.NET 程序集在网络驱动器上部分信任地运行,但所有其他程序集完全信任地运行
在网络驱动器上运行时,我们的 C++ 解决方案(调用 .NET 4.0 程序集)遇到了一个奇怪的问题。该解决方案通过 NetTcpBinding 托管多个 WCF 服务,其中之一具有非默认绑定配置。非默认 NetTcpBinding 本身在部分信任下是不可能的(请参阅堆栈溢出问题WCF NetTcpBinding何时需要客户端完全信任?),但该解决方案在完全受信任的网络驱动器下运行。这确实可以在多台不同的计算机(Windows Vista 和 Windows 7)上运行,但在一台(Windows Vista)上失败并抛出异常,
为“system.serviceModel/bindings”创建配置节处理程序时发生错误:该程序集不允许部分受信任的调用方。 (K:\Somepath\Testing.exe.Config 第 6 行)
如果解决方案确实在该计算机上的部分信任下运行,但它确实在完全信任下运行,则此异常完全正常。即使我检查代码是否完全信任,它也是如此。
我们用它运行的其中一台计算机仔细检查了互联网选项 - 没有差异。
所有 DLL 文件和 EXE 文件都是强命名的。
更新: 网络驱动器在特定计算机 (caspol.exe
) 上处于完全信任状态。
我们应该寻找什么?
如果您需要更多信息,请告诉我。
更新2: 我们仍然遇到这个问题,现在甚至在一台计算机上(Windows 7)。所以它似乎与操作系统无关。
We have a strange issue with our C++ solution (which calls .NET 4.0 assemblies) when running on a network drive. The solution hosts several WCF services with NetTcpBinding, one of them with a non-default binding configuration. A non-default NetTcpBinding is per se not possible under partial trust (see Stack Overflow question When does WCF NetTcpBinding need full trust on the client?), but the solution runs under a fully trusted network drive. This does work on several different computers (Windows Vista and Windows 7) but fails on one (Windows Vista) with throwing an exception,
An error occurred creating the configuration section handler for "system.serviceModel/bindings": That assembly does not allow partially trusted callers. (K:\Somepath\Testing.exe.Config line 6)
This exception would be totaly OK, if the solution would indeed run under partial trust on that computer, but it does run under full trust. Even if I check for full trust in code it is true.
We double checked the Internet options with one of the computers it works on - no differences.
All DLL files and the EXE file are strong named.
Update:
The network drive is under full trust on the particular computer (caspol.exe
).
What should we look for?
If you need additional information, please let me know.
Update 2:
We still have that issue and now even on one computer more (Windows 7). So it seems to be OS independent.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
它称为代码访问安全 (CAS),它强制所有不受信任的网络驱动器被视为不受信任网络代码。
本地代码完全信任,网络代码部分信任,互联网代码不信任。这是仅限 .NET 的安全模型。您可以选择通过授予网络驱动器完全权限(搜索
caspol.exe
完全信任网络驱动器)来将网络驱动器指定为“受信任”驱动器,或者将 EXE 文件复制到本地驱动器。使用 CASPOL 完全信任网络共享应该可以帮助您。
或者在命令行上:
It's called code access security (CAS), and it forces all untrusted network drives to be treated as untrusted network code.
Local code has full trust, network code has partial trust and Internet code has no trust. It's a .NET only security model. Your options are to either designate the network drive as a 'trusted' drive by giving it full rights (search for
caspol.exe
full trust network drive) or to copy the EXE file to a local drive.Using CASPOL to Fully Trust a Network Share should help you out.
Or on the command line:
我们在这里没有找到解决方案,而是找到了解决方法:不要使用 app.config 进行绑定设置。在代码中设置它们对我们在相同的环境中是有效的。
这个问题顺便说一下,似乎正在处理类似的问题。华泰
We didn't find a solution here but a workaround: Don't use the app.config for the binding settings. Setting them in code works for us in the same environment.
This question by the way seems to handle a similar issue. HTH
右键单击app.config ->属性->解锁
Right click on app.config -> Properties -> Unbock