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

我的未来我决定 提交于 2019-11-29 01:21:16

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.

Marcel Balcarek

You may need to add the following to your AssemblyInfo.cs file so that the involved assemblies are the same.

[assembly: SecurityTransparent()]

Appreciate I'm extremely late to the party here but in VS2013 and suffering the same issue with a .NET 4.5.1 ClickOnce project, I fixed this issue by:

  1. Opening the Project Properties of the ClickOnce project in question
  2. Opening the Security tab
  3. Changing the trust settings to "This is a partial trust application"
  4. Changing the trust settings back to "This is a full trust application"

Hope this helps someone else!

Apparently, one potential workaround which at least made it possible for me to launch applications in Visual Web Developer was this:

  • Remove the targetFramework="4.0" attribute from the element which is located within the element.

  • If it is a Silverlight application Right click the ApplicationName.Web header select properties, then change the target framework to 3.5. If it is an asp.net application right click the top project header and select properties and then set the target framework to 3.5.

All this suggests to me their is a problem with my .Net 4.0 framework installation. But as I have installed and uninstalled and then installed the .Net 4.0 framework at least twice, this is the only option I can think of at this point. If someone provides me a better response/More permanent solution that works for me I'll mark that as the answer. In the meantime I will try launching the "install other frameworks" and reinstalling both the .Net 4.0 targeting pack and .Net 4.0 Runtime once more to see if it works.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!