Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
389 views
in Technique[技术] by (71.8m points)

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

Hello and thanks in advance for the help, I know that this question or similar questions have been posted, frequently with specific regards to MVC 3 applications. However, I am getting this error message whenever I try and launch any application from within visual web developer express 2010 using a .net 4.0 target framework.

The exact error message is:

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.

Stack trace:

[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

I am completely at a loss here. If I create just any basic application from scratch and try and launch it, even with nothing added, I get this error screen. I have tried removing the target framework="4.0" attribute from the

<compilation debug="true" targetFramework="4.0" />

tag and running it with no results. I have tried removing that attribute and adding

<startup useLegacyV2RuntimeActivationPolicy="true">
  <supportedRuntime version="v2.0.50727"/>
  <supportedRuntime version="v4.0.30319"/>
 </startup>

as suggested in this thread: BadImageFormatException - Is it possible to specify which .NET version is used to run an executable? I tried repairing the .Net 4.0 framework installation because I heard that may be an issue. I just installed visual web developer last night in order to work on a project that I moved over from Microsoft Visual Studio 2010 because my trial version expired, any help or potential workarounds would be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I experienced this issue today. As far as I understand it, the problem is that .NET 4.0 assemblies now default to security critical. It's not possible for security transparent code to call into security critical code.

The solution in my case was related to having AllowPartiallyTrustedCallersAttribute defined on only a few of the assemblies in my application. I had to either remove this attribute from all assemblies, or add it to all of them.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...