.net 不允许从网络位置加载程序集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28339116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:37:46  来源:igfitidea点击:

Not allowed to load assembly from network location

.netvisual-studiovisual-studio-2012.net-4.5.net-assembly

提问by Stijn

I've recently set up a new Windows Server 2012 R2environment and installed Visual Studio 2012.

我最近设置了一个新的Windows Server 2012 R2环境并安装了Visual Studio 2012

Now I'm having a problem with multiple .NET 4.5project's I migrated from my old server, a Windows Server 2008 machine. This never occurred on the old server.

现在我遇到了从旧服务器(Windows Server 2008 机器)迁移的多个.NET 4.5项目的问题。这在旧服务器上从未发生过。

When trying to load an assembly from a network location, I run into the following issue:

尝试从网络位置加载程序集时,我遇到了以下问题:

An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default, so this load may be dangerous. If this load is not intended to sandbox the assembly, please enable the loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569for more information.

尝试从网络位置加载程序集,这会导致程序集在 .NET Framework 的早期版本中被沙箱化。默认情况下,此版本的 .NET Framework 不启用 CAS 策略,因此这种加载可能很危险。如果此加载不打算对程序集进行沙箱处理,请启用 loadFromRemoteSources 开关。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=155569

I've lookedatsomeotherquestions, but none of them provide a working solution.

看着一些其他的问题,但他们没有提供一个可行的解决方案。

This is what I've tried so far:

这是我迄今为止尝试过的:

  • Added the loadFromRemoteSourcesswitch to devenv.config, XDesProc.exe.appx.configand XDesProc.exe.config.
  • Checked whether the assembly was blocked, which it wasn't.
  • Tried using the CasPolutility, even though this only applies to pre .NET 4.0 projects.
  • loadFromRemoteSources开关添加到devenv.configXDesProc.exe.appx.configXDesProc.exe.config
  • 检查程序集是否被阻止,事实并非如此。
  • 尝试使用CasPol实用程序,即使这仅适用于 .NET 4.0 之前的项目。

All without success.

都没有成功。

Is there another solution to solve this problem?

有没有其他解决方案来解决这个问题?

回答by Stijn

Adding the loadFromRemoteSourcesswitchto machine.configsolved the problem.

loadFromRemoteSourcesswitch添加到machine.config解决了这个问题。

MSDN

MSDN

The loadFromRemoteSourceselement specifies whether assemblies from remote sources should be granted full trust.

loadFromRemoteSources元素指定是否应授予来自远程源的程序集完全信任。

Example

例子

<configuration>
    <runtime>
       <loadFromRemoteSources enabled="true"/>
   </runtime>
</configuration>

You can find machine.confighere:

您可以在这里找到machine.config

32-bit

32 位

%windir%\Microsoft.NET\Framework\[version]\config\machine.config

64-bit

64 位

%windir%\Microsoft.NET\Framework64\[version]\config\machine.config