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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5328274/
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 15:22:34  来源:igfitidea点击:

Load assembly from network location

.netc#-4.0assemblies

提问by Sergey Kucher

I am trying to load assembly by :

我正在尝试通过以下方式加载程序集:

Assembly component = Assembly.LoadFrom(componentPath);

where componentPathis a full path of network location and get the the following error:

wherecomponentPath是网络位置的完整路径,并得到以下错误:

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.

尝试从网络位置加载程序集,这会导致程序集在 .NET Framework 的早期版本中被沙箱化。
默认情况下,此版本的 .NET Framework 不启用 CAS 策略,因此这种加载可能很危险。

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.

如果此加载不打算对程序集进行沙盒处理,请启用 loadFromRemoteSources 开关。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=155569

Can you please explan what should i do to avoid this security check ?

你能解释一下我应该怎么做才能避免这种安全检查吗?

Thank You

谢谢你

采纳答案by sgokhales

Read Best Practices for Assembly Loadingto get an idea.
Also read this msdnblog on .NET Security

阅读装配加载的最佳实践以获得一个想法。
另请阅读有关 .NET 安全性的msdn博客

回答by Furqan Safdar

I was having this same issue. The reason was that the Assembly file was blocked by Windows. I resolved it by right clicking on the Assembly file and selecting properties. In the Properties dialog, click Unblockbutton under the General tab and click Applyand then OK.

我遇到了同样的问题。原因是程序集文件被 Windows 阻止了。我通过右键单击程序集文件并选择属性来解决它。在“属性”对话框中,单击“常规”选项卡下的“取消阻止”按钮,然后单击“应用”,然后单击“确定”

Reference: http://blogs.msdn.com/b/drew/archive/2009/12/24/xunit-and-td-net-fixing-the-attempt-was-made-to-load-an-assembly-from-a-network-location-problem.aspx

参考:http: //blogs.msdn.com/b/drew/archive/2009/12/24/xunit-and-td-net-fixing-the-attempt-was-made-to-load-an-assembly-来自网络位置问题.aspx

回答by Starnuto di topo

In addition to Furqan Safdar's answer, another option would be to add this tag in the configuration file:

除了Furqan Safdar 的回答之外,另一种选择是在配置文件中添加这个标签:

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

Hope these links could help:

希望这些链接可以帮助:

http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx

http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx