我们收到以下程序集加载错误。程序集从本地路径“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()
答案 0 :(得分:82)
如果已从Web复制应用程序,则Windows会将其标记为Web应用程序,即使它位于本地计算机上也是如此。您可以通过更改文件属性来更改该指定,也可以使用该元素授予程序集完全信任。作为替代方法,您可以使用UnsafeLoadFrom方法加载操作系统已标记为已从Web加载的本地程序集。
尝试打开文件属性,然后点击“取消阻止”:
答案 1 :(得分:11)
我可以使用以下链接解决此问题,并将设置添加到我的配置中。
https://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx
<configuration>
<runtime>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
答案 2 :(得分:2)
我不得不使用方法
Assembly.UnsafeLoadFrom()
而不是Assembly.LoadFrom,它解决了我的问题...... 在这个链接找到它:
https://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx
答案 3 :(得分:1)
除了上面给出的答案,我还解决了这个问题。
尝试取消阻止导致文件仍然存在 似乎被阻止了。
因此,我创建了一个新文件夹,复制了受影响的文件并按文件执行了解锁文件。 令人惊讶的是,与在原始文件位置执行相同操作相比,标记已被删除。 因此,最后一步是将现在未阻止的文件复制回原始位置。完成!