【问题标题】:.net local assembly load failed with CAS policy.net 本地程序集加载因 CAS 策略而失败
【发布时间】:2013-03-06 03:58:33
【问题描述】:

我们收到以下程序集加载错误。程序集从本地路径“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()

【问题讨论】:

    标签: c# .net


    【解决方案1】:

    来自link in the error message

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

    尝试打开文件属性并点击“取消阻止”:

    【讨论】:

    • 对我来说,这只是一个从我们自己的内部 Proget 实例“下载”的 nuget 包,这一定是造成这种情况的原因:) 解除阻止工作
    • 对于许多文件,我使用 powershell 脚本: dir -Path YOUR_PATH -Recurse |取消阻止文件
    • 非常感谢!这解决了我的问题)
    【解决方案2】:

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

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

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

    【讨论】:

    • 这对我有用,而他们更赞成的答案却没有。
    • 这有点愚蠢,通过将它放在配置中,它只是绕过了微软试图实现的Security......哈哈
    • 就我而言,我制作了一个可以运行很长时间的应用程序,但最近在我的机器上它停止了工作。我找不到代码,它已经有几年了,现在才停止工作。像魅力一样让它重新运行
    【解决方案3】:

    我不得不使用方法

    Assembly.UnsafeLoadFrom()
    

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

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

    【讨论】:

      【解决方案4】:

      除了上面给出的答案之外,我的问题的解决方案。

      尝试解除阻塞总是导致文件仍然存在 好像被屏蔽了。

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

      【讨论】:

        猜你喜欢
        • 2021-09-17
        • 1970-01-01
        • 2017-10-31
        • 2022-12-22
        • 2010-11-04
        • 1970-01-01
        • 2010-12-31
        • 1970-01-01
        • 2013-01-29
        相关资源
        最近更新 更多