您好,在此先感谢您的帮助。 我知道这个问题或类似的问题已经发布了很多次,特别是针对MVC 3应用程序。然而,每当我尝试在Visual Web Developer Express 2010中使用.NET 4.0目标框架启动任何应用程序时,都会出现以下错误信息:
确切的错误提示如下:
尝试使用安全透明方法“System.Runtime.Diagnostics.DiagnosticTrace..ctor(System.String, System.Guid)”访问安全关键方法“System.Runtime.Diagnostics.EtwDiagnosticTrace..ctor(System.String, System.Guid)”失败。
程序集“System.ServiceModel.Internals、版本=4.0.0.0、Culture=neutral、PublicKeyToken=31bf3856ad364e35”标记有 AllowPartiallyTrustedCallersAttribute,且使用级别为2的安全透明模型。级别2的透明度默认会导致AllowPartiallyTrustedCallers程序集中的所有方法均变成安全透明的,这可能是异常的原因。
堆栈跟踪:
[MethodAccessException: Attempt by security transparent method 'System.Runtime.Diagnostics.DiagnosticTrace..ctor(System.String, System.Guid)' to access security critical method 'System.Runtime.Diagnostics.EtwDiagnosticTrace..ctor(System.String, System.Guid)' failed.
Assembly 'System.ServiceModel.Internals, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model. Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security transparent by default, which may be the cause of this exception.]
System.Runtime.Diagnostics.DiagnosticTrace..ctor(String traceSourceName, Guid etwProviderId) +24
System.ServiceModel.Activation.FxTrace.InitializeTracing() +90
System.ServiceModel.Activation.FxTrace.get_Trace() +84
System.ServiceModel.ServiceHostingEnvironment.EnsureInitialized() +59
System.ServiceModel.ServiceHostingEnvironment.OnEnsureInitialized(Object state) +4
System.ServiceModel.AspNetPartialTrustHelpers.PartialTrustInvoke(ContextCallback callback, Object state) +52
System.ServiceModel.ServiceHostingEnvironment.SafeEnsureInitialized() +65
System.ServiceModel.Activation.HttpModule.ProcessRequest(Object sender, EventArgs e) +58
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +143
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
我完全不知所措。如果我从头开始创建任何基本应用程序并尝试启动它,即使没有添加任何内容,我也会得到这个错误屏幕。我尝试删除 target framework="4.0" 属性,但仍然出现此错误。
<compilation debug="true" targetFramework="4.0" />
我尝试使用标签,但没有得到任何结果。我已经尝试删除该属性并添加
。<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0.50727"/>
<supportedRuntime version="v4.0.30319"/>
</startup>
正如在这个帖子中建议的那样:BadImageFormatException - 是否可以指定使用哪个 .NET 版本来运行可执行文件? 我尝试修复了 .Net 4.0 框架的安装,因为我听说可能会出现问题。 昨晚我刚刚安装了 Visual Web Developer,以便于处理我从 Microsoft Visual Studio 2010 移植过来的项目,因为我的试用版已经过期了。如果有帮助或潜在解决方法,将不胜感激。