.net 无法加载文件或程序集 不支持操作。(来自 HRESULT 的异常:0x80131515)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34400546/
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
Could not load file or assembly Operation is not supported. (Exception from HRESULT: 0x80131515)
提问by magicandre1981
When I run CodedUI Test from a small Console tool via vstest.console.exefrom a scheduled task I sometimes see this error message on different PCs:
当我通过vstest.console.exe计划任务从小型控制台工具运行 CodedUI 测试时,有时会在不同的 PC 上看到此错误消息:
error : Could not load file or assembly 'file:///C:\foobar.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
错误:无法加载文件或程序集“file:///C:\foobar.dll”或其依赖项之一。不支持操作。(来自 HRESULT 的异常:0x80131515)
Why/what is this not supported?
为什么/这是不支持的?
采纳答案by magicandre1981
During my research I found that this may happen when you downloaded a test in a ZIP from the internet and the advice was to unblock the ZIP. But I copied the files over the network from my developer system to the test PCs and the files were not blocked.
在我的研究中,我发现当您从 Internet 下载 ZIP 格式的测试并且建议解除对 ZIP 的阻止时,可能会发生这种情况。但是我通过网络将文件从我的开发人员系统复制到测试 PC 并且文件没有被阻止。
Searching more for the error code 0x80131515I found this answer in the MSDN forum.
搜索更多错误代码,0x80131515我在 MSDN 论坛中找到了这个答案。
So I edited the file
所以我编辑了文件
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe.config
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe.config
and added the entry <loadFromRemoteSources enabled="true" />under the runtime tag and voilá, the tests run fine without any issues from a scheduled task.
并<loadFromRemoteSources enabled="true" />在运行时标签下添加了条目,瞧,测试运行良好,没有任何计划任务的问题。
Maybe this helps other users who also run into this strange issue.
也许这有助于其他也遇到这个奇怪问题的用户。
回答by Raj


Right click on the Dll and unblock it.
右键单击 Dll 并取消阻止它。
回答by Rich Moss
As previously stated, a Zip file is blocked when downloaded from an untrusted site. If you are confident the site is reliable you can prevent this behavior by adding it to your trusted sites list in Internet Explorer -> Tools Menu -> Internet Options -> Security Tab -> Trusted Sites. Future downloads will not be marked as blocked.
如前所述,从不受信任的站点下载 Zip 文件时会被阻止。如果您确信该站点是可靠的,则可以通过将其添加到Internet Explorer -> 工具菜单 -> Internet 选项 -> 安全选项卡 -> 受信任站点中的受信任站点列表来防止这种行为。以后的下载不会被标记为已阻止。
For blocked files that have already been extracted, run this at a Powershell prompt to unblock all the files in the current folder and subfolders:
对于已被提取的被阻止文件,在 Powershell 提示符下运行此命令以取消阻止当前文件夹和子文件夹中的所有文件:
Get-ChildItem *.* -Recurse | Unblock-File
回答by Ishara Samintha
1) go to exe file click the properties
1)进入exe文件点击属性
2) click the unblock button
2)点击解锁按钮
then this will slove
那么这会变慢
回答by Zolfaghari
This problem occurs when sgen.exe is not able to get write access to your output assembly to generate serialization assembly.
当 sgen.exe 无法获得对输出程序集的写入访问权限以生成序列化程序集时,会出现此问题。
Reason may be file is read only or it is on UNC path.
原因可能是文件是只读的,或者它在 UNC 路径上。
To resolve this issue you have following options.
要解决此问题,您有以下选择。
- Copy your solution to you system local drive then build your solution.
- Use caspol.exe to grant full trust to the UNC path.
- Disable Generate serialization assembly option from your project properties build tab.
- 将您的解决方案复制到系统本地驱动器,然后构建您的解决方案。
- 使用 caspol.exe 授予对 UNC 路径的完全信任。
- 从您的项目属性构建选项卡禁用生成序列化程序集选项。
For more info please visit http://bimbim.in/post/2010/09/06/SGEN-error-Could-not-load-file-or-assembly.aspx
有关更多信息,请访问http://bimbim.in/post/2010/09/06/SGEN-error-Could-not-load-file-or-assembly.aspx
answer replyed from: bimbim.in
回复来自:bimbim.in

