C# - .NET 4.0 - That Assembly does not allow partially trusted callers

我的梦境 提交于 2019-12-06 13:32:23

问题


When running from a network share, my application throws the following exception:

That assembly does not allow partially trusted callers.

My application references two DLL files:

  • BitFactory.Logging.dll
  • FileHelpers.dll

I'm not sure which one it is having problems with.

  • AllowPartiallyTrustedCallersAttribute: Read up on it, but I do not have the source for either of the DLL files, so I'm not able to add the attribute to those DLL files.

  • CASPOL.EXE: added my network share using a few variations, such as caspol -machine -addgroup 1. -url \\netserver\netshare\* LocalIntranet nothing seems to affect.

I've used CASPOL hack before, with .NET 3.5, however, it seems to not work with .net 4.0 now. Can anyone suggeest on how I can bypass this "Partially Trusted Caller" check?

Thanks.


回答1:


.NET 4.0 has changed the default rules for security policy. You'll need to create or modify the App.config file for this application.

Code access security (as configured by CASPOL) is now ignored by default in .NET 4.0. If you want to enable it you need to add the following to your app.config file:

<configuration>
   <runtime>
      <!-- enables legacy CAS policy for this process -->
      <NetFx40_LegacySecurityPolicy enabled="true" />
   </runtime>
</configuration>

You can configure .NET 4.0 to treat code from the network using LoadFrom as fully trusted with the following configuration item:

<configuration>
   <runtime>
      <!-- Treat assemblies from network locations as fully trusted. -->
      <!-- Caution: Do not point this loaded gun at your foot. -->
      <loadFromRemoteSources enabled="true" />
   </runtime>
</configuration>


来源:https://stackoverflow.com/questions/4260782/c-sharp-net-4-0-that-assembly-does-not-allow-partially-trusted-callers

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