Issue with ESRIRegAsm

1699
10
02-01-2010 03:27 AM
RobertClark
New Contributor III
One of our projects is failing to build when registering the assembly.  when run with the error code option we get the following:

Managed Exception: Exception has been thrown by the target of an invocation.
Operation Failed
00938700

In our xml project file we have:
  <Target Name="BeforeClean">
    <Exec WorkingDirectory="$(CommonProgramFiles)\ArcGIS\bin" Command="esriRegasm.exe &quot;$(TargetPath)&quot; /v 9.4 /p Desktop /u /s /e" Condition="Exists('$(TargetPath)')" />
  </Target>
  <Target Name="AfterBuild">
    <Exec WorkingDirectory="$(CommonProgramFiles)\ArcGIS\bin" Command="esriRegasm.exe &quot;$(TargetPath)&quot; /v 9.4 /p Desktop /s /e" />
  </Target>
0 Kudos
10 Replies
EagerIp
New Contributor II
By any chance this project targets .NET framework 4.0 (created via Visual Studio 2010 beta)?

You can also try to catch more debugging information by using the /e flag in esriRegasm.exe in the cmd prompt against the compiled dll; e.g.

"C:\program files\common files\arcgis\bin\esriregasm.exe" "failedAssembly.dll" /e /p Desktop /v 9.4
0 Kudos
RobertClark
New Contributor III
Hi - no this is created in VS 2008 and targets .NET framework 2.0.  We did the /e to get the debug information which gave us the following messages:

Managed Exception: Exception has been thrown by the target of an invocation.
Operation Failed
00938700
0 Kudos
EagerIp
New Contributor II
OK. The /e option doesn't give a lot of information. Can you try to debug if the error stems from any of the ComRegisterFunction() inside the failed assembly? You can do so by setting esriRegasm.exe as the debugging external program in Visual Studio. (And it is better if you remove or comment out the BeforeClean/AfterBuild xml from the project file before debugging.)

Under Start Action
------------------
Start external program:
C:\Program Files\Common Files\ArcGIS\bin\ESRIRegAsm.exe

Under Start Options
-------------------
Command line arguments:
"failedAssembly.dll" /p:Desktop /e

Working directory:
{directory of the failedAssembly.dll}
0 Kudos
MarcBate
Occasional Contributor II
By any chance this project targets .NET framework 4.0 (created via Visual Studio 2010 beta)?


I am getting an error "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded" when targeting 4.0.   I'm hoping that there is a workaround, esp after you've added support for VS2010 in Beta 2, so overlooking this seems weird.
0 Kudos
RobertClark
New Contributor III
sorporbear,

This is fixed now, there was some additional code in the register function that was causing the issue - not sure why it was in that method in the first place but anyways I've removed it and it works as usual - thanks for the pointers.

Thanks,
Rob
0 Kudos
EagerIp
New Contributor II
I am getting an error "This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded" when targeting 4.0.   I'm hoping that there is a workaround, esp after you've added support for VS2010 in Beta 2, so overlooking this seems weird.


This is a side effect of .NET 4.0 no longer uses CLR 2.0 as .NET 2.0/3.0/3.5 do; therefore, mixed-mode assemblies building against CLR 2.0 is unable to load .NET 4.0 assemblies by default.

You can workaround this issue by placing a esriRegasm.exe.config file in the same folder as esriRegasm.exe (e.g. under C:\program files\common files\arcgis\bin) with the following content -

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v2.0.50727" />
    <supportedRuntime version="v4.0.21006" />
  </startup>
</configuration>

Since .NET 4.0 and Visual Studio 2010 are still in beta, we are expecting issues to be resolved while we are still testing it internally.
0 Kudos
MarcBate
Occasional Contributor II
You can workaround this issue by placing a esriRegasm.exe.config file in the same folder as esriRegasm.exe (e.g. under C:\program files\common files\arcgis\bin) with the following content

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v2.0.50727" />
<supportedRuntime version="v4.0.21006" />
</startup>
</configuration>


If I took out the <supportedRuntime version="v2.0.50727" /> line, it WORKED!
Attached is the file if anyone is interested.
0 Kudos
EagerIp
New Contributor II
Sorry, the ordering of the supportedRuntime is reversed. It should list 4.0 first so if your machine has .NET 4.0 installed, it will load; otherwise, 2.0 is used. Also, you can omit the build number (especially .NET 4.0 is still not final).

The following .config file will work on a machine with .NET 2.0 through 3.5 +/- .NET 4.0.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
<supportedRuntime version="v2.0" />
</startup>
</configuration>
0 Kudos
MarcBate
Occasional Contributor II
Thanks, changing it to just 4.0 worked with the VS2010 RC.

Attached is the file to help others save a little time.
0 Kudos