.NET 4.0 third-party library causing “That Assembly does not allow partially trusted callers”

浪子不回头ぞ 提交于 2019-12-12 03:11:08

问题


I have a console application that references third party libraries whose source code I don't have:

1) Common.Logging.NLog, 2) Common.Logging, 3) NLog

After switching the Security option to "This is a partial trust application" (deployed in a network share drive), VS gave 4 warnings:

Warning 1   Reference 'Common.Logging.NLog' does not allow partially trusted callers.
Warning 2   Reference 'Common.Logging' does not allow partially trusted callers.
Warning 3   Reference 'NLog' does not allow partially trusted callers.
Warning 4   Use of app.config binding redirects requires full trust.

I tried the solution in C# - .NET 4.0 - That Assembly does not allow partially trusted callers by 1) Create a key using SN.EXE 2) Sign all my assemblies with this key.

After that the compiler complained that the third party libraries don't have a strong name.

Would anyone suggest a solution? I don't have direct control on the client machine, so I'd prefer a solution that doesn't require client machine configuration (for example, CASPOL.EXE).

UPDATE_1

I added <NetFx40_LegacySecurityPolicy enabled="true" /> to app.config. It went passed the first SecurityException, but died at a later point for the same error.

Thanks.


回答1:


After some trial and error, I found a way to get the sample app working.

  1. Download the code.
  2. Set the Target Framework of each project to .NET 4.
  3. Sign each project with the same key. (I didn't experiment signing them with different keys)
  4. Compile everything.
  5. Add to App.config

       <runtime>             
         <NetFx40_LegacySecurityPolicy enabled="true" />
       </runtime> 
    



回答2:


You may be in luck -- all three assemblies are open source and live on github, so you can compile them yourself and sign with your choice of strong-name key. Links to the project source repository pages are:

  • common-logging
  • NLog


来源:https://stackoverflow.com/questions/9743267/net-4-0-third-party-library-causing-that-assembly-does-not-allow-partially-tru

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