当我尝试以PDF/Excel/Word或打印报告导出报告时,出现错误.错误说明:
Server Error in '/' Application.
Operation could destabilize the runtime.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Security.VerificationException: Operation could destabilize the runtime.
Run Code Online (Sandbox Code Playgroud)
来源错误:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack …Run Code Online (Sandbox Code Playgroud) 我在我的本地计算机上的一个ASP.NET 4.5 MVC应用程序中收到此错误.使用ASP.NET 4.5设置其他应用程序并使用StructureMap可以正常工作.

任何帮助/解决方案都将受到高度赞赏.导致这种情况的代码行是:
using StructureMap;
using StructureMap.Graph;
namespace Management.Web.DependencyResolution
{
public static class IoC
{
public static IContainer Initialize()
{
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.Assembly("Management.Core");
scan.Assembly("Management.DAL");
scan.Assembly("Management.BusinessServices");
scan.Assembly("Management.Infrastructure");
});
x.For<INavigationService>().Use<NavigationService>();
});
return ObjectFactory.Container;
}
}
}
Run Code Online (Sandbox Code Playgroud) 我创建了一个.NET 4.5控制台应用程序来尝试新的Ent Lib v6中的语义记录位.使用PDF中的示例代码:
var listener2 = new ObservableEventListener();
listener2.EnableEvents( EventSourceCore.Log , EventLevel.LogAlways , Keywords.All );
SinkSubscription<SqlDatabaseSink> subscription = listener2.LogToSqlDatabase( "Demo Semantic Logging Instance" , ConfigurationManager.AppSettings["mdbconn"] );
Run Code Online (Sandbox Code Playgroud)
立即运行代码会出现错误"操作可能使运行时不稳定".我看到VS2012中Exception帮助器中的堆栈跟踪
at Microsoft.Practices.EnterpriseLibrary.TransientFaultHandling.RetryPolicy`1..ctor(Int32 retryCount, TimeSpan minBackoff, TimeSpan maxBackoff, TimeSpan deltaBackoff)
at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.Sinks.SqlDatabaseSink..ctor(String instanceName, String connectionString, String tableName, TimeSpan bufferingInterval, Int32 bufferingCount, Int32 maxBufferSize, TimeSpan onCompletedTimeout)
at Microsoft.Practices.EnterpriseLibrary.SemanticLogging.SqlDatabaseLog.LogToSqlDatabase(IObservable`1 eventStream, String instanceName, String connectionString, String tableName, Nullable`1 bufferingInterval, Int32 bufferingCount, Nullable`1 onCompletedTimeout, Int32 maxBufferSize)
at svc2.Program.LogPrep() in c:\cos\Program.cs:line 66
at svc2.Program.Main(String[] args) in c:\cos\Program.cs:line 23 …Run Code Online (Sandbox Code Playgroud) 我有这个方法,它在一个动态工厂方法中包装一个构造函数:
static Func<TArg1, TResult> ToFactoryMethod<TArg1, TResult>(this ConstructorInfo ctor)
where TResult : class
{
var factoryMethod = new DynamicMethod(
name: string.Format("_{0:N}", Guid.NewGuid()),
returnType: typeof(TResult),
parameterTypes: new Type[] { typeof(TArg1) });
ILGenerator il = factoryMethod.GetILGenerator();
il.Emit(OpCodes.Ldarg_1);
il.Emit(OpCodes.Newobj, ctor);
il.Emit(OpCodes.Ret);
return (Func<TArg1, TResult>)
factoryMethod.CreateDelegate(typeof(Func<TArg1, TResult>));
}
Run Code Online (Sandbox Code Playgroud)
但是,下面的代码抛出一个VerificationException上.Invoke(…):
ConstructorInfo ctor = typeof(Uri).GetConstructor(new Type[] { typeof(string) });
Func<string, Uri> uriFactory = ctor.ToFactoryMethod<string, Uri>();
Uri uri = uriFactory.Invoke("http://www.example.com");
Run Code Online (Sandbox Code Playgroud)
如果我更换ldarg.1,则不会抛出异常; newobj <ctor>用ldnull,所以这个问题必须由这两个IL指令造成的.进一步的实验表明错误在于ldarg.1.(我用ldstr <string>上面的具体例子替换了它.)
有谁看到这些IL指令有什么问题?
c# reflection reflection.emit dynamicmethod verificationexception