June 04, 2011

Regasm error RA0000 : Could not load file or assembly

.NET 4.0 has some additional security (!) which prevents executing some commands on a file which is hosted on the network drive. For example you might get the following error while compiling project which uses regasm command in its post build event.

C:\Program Files\Microsoft Visual Studio 10.0\VC>regasm E:\TestAsm.dll

Microsoft (R) .NET Framework Assembly Registration Utility 4.0.30319.1
Copyright (C) Microsoft Corporation 1998-2004. All rights reserved.

RegAsm : error RA0000 : Could not load file or assembly 'file:///E:\TestAsm.dll' or
one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)

To avoid this issue either keep all your code at host drive or add the loadFromRemoteSources element in file “regasm.exe.config” at location “C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319”

After adding the loadFromRemoteSources element “regasm.exe.config” looks as below:

<?xml version ="1.0"?> 
<configuration>
<runtime>
<loadFromRemoteSources="true"/>
</runtime>

<startup useLegacyV2RuntimeActivationPolicy="true">
<requiredRuntime safemode="true" imageVersion="v4.0.30319" version="v4.0.30319"/>
<supportedRuntime version="v4.0" sku="client" />
</startup>
</configuration>



Please see the following link for more information.



http://msdn.microsoft.com/en-us/library/dd409252(VS.100).aspx



From above link -



MSBuild



If you are running MSBuild, rather than Visual Studio, the element needs to be added to msbuild.exe.config.  I found 10 copies of this file on my build machine - 6 in Windows\Microsoft.Net\Framework... and 4 in Windows\winsxs....  Due to permission issues, I was not able to change the copies in winsxs..., but that didn't matter.  I changed all 6 in the Framework hierarchy and that solved the problem.



>> I found only one config file where we have to make change.