Could not load file or assembly Operation is not supported. (Exception from HRESULT: 0x80131515)

.NetVisual Studio-2012Scheduled TasksCoded Ui-Tests

.Net Problem Overview


When I run CodedUI Test from a small Console tool via vstest.console.exe from a scheduled task I sometimes see this error message on different PCs:

> error : Could not load file or assembly 'file:///C:\foobar.dll' or > one of its dependencies. Operation is not supported. (Exception from > HRESULT: 0x80131515)

Why/what is this not supported?

.Net Solutions


Solution 1 - .Net

![enter image description here][1]

Right click on the Dll and unblock it. [1]: https://i.stack.imgur.com/V4Lco.png

Solution 2 - .Net

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.

Searching more for the error code 0x80131515 I found this answer in the MSDN forum.

So I edited the file

> 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.

Maybe this helps other users who also run into this strange issue.

Solution 3 - .Net

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.

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:

Get-ChildItem *.* -Recurse | Unblock-File

Solution 4 - .Net

  1. go to exe file click the properties

  2. click the unblock button

then this will slove

Solution 5 - .Net

For me, I needed to set the start up object in the Application settings.

Right click on the project name in the Solution Explorer. Click Properties. Go to the Application tab, Select the correct method from the Startup object dropdown.

Mine was not set, causing intermittent compile errors.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmagicandre1981View Question on Stackoverflow
Solution 1 - .NetRajView Answer on Stackoverflow
Solution 2 - .Netmagicandre1981View Answer on Stackoverflow
Solution 3 - .NetRich MossView Answer on Stackoverflow
Solution 4 - .NetIshara SaminthaView Answer on Stackoverflow
Solution 5 - .NetM HView Answer on Stackoverflow