jjzjj

c# - 系统.MethodAccessException : Attempt by security transparent method to access security critical method fails on all applications

coder 2023-07-13 原文

您好,在此先感谢您的帮助, 我知道这个问题或类似的问题已经发布,经常与 MVC 3 应用程序相关。但是,每当我尝试使用 .net 4.0 目标框架从 visual web developer express 2010 中启动任何应用程序时,我都会收到此错误消息。

准确的错误信息是:

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.

堆栈跟踪:

[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 - Is it possible to specify which .NET version is used to run an executable? 我尝试修复 .Net 4.0 框架安装,因为我听说这可能是个问题。 我昨晚刚刚安装了 visual web developer,以便处理我从 Microsoft Visual Studio 2010 转移过来的项目,因为我的试用版已过期,我们将不胜感激任何帮助或潜在的解决方法。

最佳答案

我今天遇到了这个问题。据我了解,问题在于 .NET 4.0 程序集现在默认为安全关键。安全透明代码不可能调用安全关键代码。

在我的案例中,解决方案与在我的应用程序中的几个程序集上定义 AllowPartiallyTrustedCallersAttribute 有关。我必须从所有程序集中删除此属性,或者将其添加到所有程序集中。

关于c# - 系统.MethodAccessException : Attempt by security transparent method to access security critical method fails on all applications,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12092435/

有关c# - 系统.MethodAccessException : Attempt by security transparent method to access security critical method fails on all applications的更多相关文章

随机推荐