Thursday, November 1, 2012

Problems with .net4 regasm.exe on shared disk

I've been struggling trying to use the .NET4 version of regasm on a C#4 DLL. The error was:

    RegAsm : error RA0000 : Count not load file or assembly '...' or one of its dependencies. Operation is not supported.

It turns out this is a security thing, due to not trusting my network drive (where the DLL is kept).

The fix was to go to c:\windows\Microsoft.NET\Framework\v4.0.30319\ and open regasm.exe.config in a text editor. Mine now looks like this (the lines I added are shown in red):


<configuration>
    <startup uselegacyv2runtimeactivationpolicy="true">
        <requiredruntime imageversion="v4.0.30319" safemode="true" version="v4.0.30319">
        <supportedruntime sku="client" version="v4.0">
    </supportedruntime></requiredruntime></startup>
<runtime>
    <loadfromremotesources enabled="true"> </loadfromremotesources></runtime>

</configuration>


I didn't have to do this with the .NET2 version of regasm.

By the way, if you get an error complaining about "CoCreateInstance failed with error 0x80040154", that (in my case) was due to having previously registered this DLL as a .NET2 assembly with .NET2 version of regasm. Recompiling the DLL for any of .NET3 or .NET3.5 was fine, but targetting .NET4 gave that error. Hence the need to register it again using v4  of regasm.

3 comments:

Ben Dover said...

I had this problem.

The fix was to open the dll file properties and on the Details tab, click the Unblock button.

Apparently the file was not trusted because it came from another computer.

Ben Dover said...

I had this same problem and it turned out the server thought my file was untrustworthy because it came from another computer.

The resolution was to open the dll file properties and click the Unblock button.

Also, compiling using the /codebase switch helped as my dll was com exposed.

Ben Dover said...

on my previous comment, replace "compiling using the /codebase switch" to...

"regasm using the /codebase switch"

D'Oh