簡體   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