82

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?

magicandre1981
  • 27,895
  • 5
  • 86
  • 127

5 Answers5

182

enter image description here

Right click on the Dll and unblock it.

iehrlich
  • 3,572
  • 4
  • 34
  • 43
Raj
  • 1,831
  • 2
  • 8
  • 2
  • 1
    as I mentioned in my answer, this is one possible cause, but did not apply to me. File are copied via USB drive/network and not downloaded from internet. – magicandre1981 Jul 21 '17 at 14:15
  • 4
    If you have **multiple DLLs in ZIP file, you can use unblock on this ZIP file** before it is uncompressed. Then, you do not have to unblock each dll separately. – Fenix Oct 26 '20 at 22:39
46

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.

magicandre1981
  • 27,895
  • 5
  • 86
  • 127
  • 1
    where can i find this config file in vs 10.0? – Ruslan_K Jul 26 '17 at 05:50
  • @user3373603 Have you checked "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe.config"? But I'M not sure if VS2010 already has the file. I think here it only includes the old mstest.exe, so edit "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe.config" – magicandre1981 Jul 26 '17 at 15:08
  • Does not work, but answer given by Raj works very well. – Bravo Jul 23 '18 at 10:49
  • 1
    @Bravo next time read correctly, I also posted that unblocking zip is 1 solution **facepalm** – magicandre1981 Jul 23 '18 at 14:53
14

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
Rich Moss
  • 2,195
  • 1
  • 13
  • 18
  • Thank you, other options create a security risk. Since the files downloaded for me come from OneDrive which is too generic to allow. The use of remote sources doesn't feel secure to me, due to opening up doors for bad practice. This PS script fixes all the issues. – DerDee Oct 28 '20 at 14:10
10

1) go to exe file click the properties

2) click the unblock button

then this will slove

Ishara Samintha
  • 460
  • 6
  • 8
0

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.

M H
  • 325
  • 3
  • 8