Search code examples
azureazure-storagemstestnetwork-sharefileshare

MSTest fails to load dll from network share


I am running MSTest (on a Microsoft Azure VM) to test a DLL which is in a network file share (linked to Azure File Storage).

I get this error -

Could not load file or assembly 'file:///P:\test\bin\mydll.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)


Solution

  • Solution 1:

    xcopy the folder containing the dll and its dependencies from the network share to a local disk and run it from there.

    Solution 2:

    This solution is preferable because it saves the copy step.

    Find the folder that contains MSTest.exe. In my case here:

    C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE

    Open MSTest.exe.config (it should already exist) and add the following line under<runtime> :

    <loadFromRemoteSources enabled="true"/>
    

    in context:

    <configuration>
       <runtime>
          <loadFromRemoteSources enabled="true"/>
       ...
    

    From: MSDN: <loadFromRemoteSources> element.

    Confusingly, it says:

    In the .NET Framework 4.5, assemblies on local network shares are run as full trust by default; you do not have to enable the <loadFromRemoteSources> element.

    I am targeting .NET 4.5, but I got the error until I enabled loadFromRemoteSources.