繁体   English   中英

.net本地程序集加载因CAS策略而失败

[英].net local assembly load failed with CAS policy

我们收到以下程序集加载错误。 程序集从本地路径“ C:\\ Program Files \\ ASWorx Products \\ ASWorx \\ Bin \\”加载。 旧版本的二进制文件不存在问题。 当我们通过电子邮件发送了新的二进制文件时,就会出现此问题。 构建设置不会更改。 我们如何解决这个问题? 该问题出现在Win7 32位计算机中

File name: 'file:///C:\Program Files\ASWorx Products\ASWorx\Bin\ASConnexDI.dll' ---> System.NotSupportedException: 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=155569 for more information.

   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)

   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)

   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)

   at System.Reflection.Assembly.LoadFrom(String assemblyFile, Evidence securityEvidence)

   at System.Activator.CreateInstanceFromInternal(String assemblyFile, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo)

   at NeST.ICE.IOSystem.DIManager.InitializeDI()

错误消息中链接

如果已经从Web复制了应用程序,则Windows将其标记为Web应用程序,即使它位于本地计算机上也是如此。 您可以通过更改文件属性来更改该名称,也可以使用元素来授予程序集完全信任。 或者,可以使用UnsafeLoadFrom方法加载操作系统已标记为已从Web加载的本地程序集。

尝试打开文件属性,然后单击“取消阻止”:

属性窗口

我可以使用下面的链接并将设置添加到我的配置中来解决此问题。

https://msdn.microsoft.com/zh-CN/library/dd409252(VS.100).aspx

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

我不得不使用该方法

Assembly.UnsafeLoadFrom()

而不是Assembly.LoadFrom,它解决了我的问题...在以下链接中找到了它:

https://msdn.microsoft.com/zh-CN/library/dd409252(VS.100).aspx

除了以上给出的答案,这里是我针对该问题的解决方案。

尝试执行解除阻止操作始终会导致文件似乎仍然被阻止。

因此,我创建了一个新文件夹,将其复制到受影响的文件上,然后逐个文件执行解锁文件。 令人惊讶的是,与在原始文件位置中执行相同的操作相比,该标志被删除了。 因此,最后一步是将现在已解除阻止的文件复制回原始位置。 做完了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM