1

I want to build the project to create a tool with ArcObjects in Visual Studio. I get this error:

The command "esriRegasm.exe "...Project1.dll" /p:Desktop /s" exited with code -1.

I use C#, Visual Studio 2015, ArcObjects 10.5, ArcMap 10.5.

I looked at past questions with the same error (External tool (esriRegasm.exe) fails during build. Where in my VS project is it executed?).

I tried to solve the problem like this:

  • tried to open the solution as an "adminimtrator" not just a user;
  • run the esriRegAsm.exe command from the command line. I tried in two ways. The first, as in the error in Visual Studio (picture 1) and the second, as per the instructions on the help.arcgis website. (picture 2);
  • tried to open the .csproj file, go to the end of the file, find the line esriRegAsm.exe, delete it and rebuild the project.

None of this worked. How to build a project?

Nolu
  • 11
  • 2
  • I quite often stumble over that error and never really nailed it down. Usually I just delete the `BeforeClean`- and `AfterBuild`-targets within the csproj-file, where the call usually is defined. However I suggest to go to `gis.stackexchange` with questions related to ArcGIS. – MakePeaceGreatAgain Sep 22 '20 at 14:04
  • Anway what happens when you righclick your assembly and select register? – MakePeaceGreatAgain Sep 22 '20 at 14:08
  • The error reporting is too lame to tell you what went wrong. You need to know the InnerException but it won't tell you. Debug it with Project > Properties > Debug tab, select "Start external program" and type the command. Next use Debug > Windows > Exception Settings and tick CLR Exceptions. Press F5 and the debugger should stop at the statement in your code that caused the exception. Typically it is the initialization of a static variable that keels over. – Hans Passant Sep 22 '20 at 14:25
  • @HansPassant In the "Start external program" field, I have the path to ArcMap.exe. Do I need to change it? I selected all "CLR Exceptions". – Nolu Sep 22 '20 at 17:33
  • @HimBromBeere I didn't understand where I need to press the right button and find "registration". I am a beginner, thanks for your understanding. – Nolu Sep 22 '20 at 17:42
  • Did you review [this](https://community.esri.com/thread/108044)? – Kadir Şahbaz Sep 22 '20 at 18:18
  • you can rightclick your compiled assembly - assuming you have the ArcObjects SDK installed - and select register/unreigster from there, which eventually does also call esriregasm. – MakePeaceGreatAgain Sep 23 '20 at 05:37
  • Furthermore you can disable the `/s`-flag from your call within the build-task. Maybe you get more meaningful error then - probably not. – MakePeaceGreatAgain Sep 23 '20 at 05:43

1 Answers1

1

The esriregasm-tool is used to register your own commands, tools or extension for using in ArcGIS. It is usually defined as msbuild-task at the end of your csproj-file as follows:

<Target Name="BeforeClean" Condition=" '$(NO_ESRI_REGASM)' == '' ">
  <Exec WorkingDirectory="$(CommonProgramFiles)\ArcGIS\bin" Command="esriRegasm.exe &quot;$(TargetPath)&quot; /p:Desktop /u /s" Condition="Exists('$(TargetPath)')" />
</Target>
<Target Name="AfterBuild" Condition=" '$(NO_ESRI_REGASM)' == '' ">
  <Exec WorkingDirectory="$(CommonProgramFiles)\ArcGIS\bin" Command="esriRegasm.exe &quot;$(TargetPath)&quot; /p:Desktop /s" />
</Target>

As I get this eror on nearly every rebuild of my solution, I developed a couple of strategies to handle it.

First you can just build the project again. As this won´t invoke the forementioned targets - only on "Clean" or "Rebuild", but not on "Build" - the registration is not executed. However your assembly is created. You can still register it after being compiled, either by rightclicking on the dll-file and selecting Register, or by calling the following within the commandline:

%CommonProgramFiles%\ArcGIS\bin\esriregasm /p:Desktop /u
%CommonProgramFiles%\ArcGIS\bin\esriregasm /p:Desktop

Be aware that I omitted the /s-flag in order to get more meaningul errors. You can also append the /e-switch for more verbose errors - which is not really much from my experience.

Now look into folder where the ECFG-files are located. This is usually %CommnonProgramFiles%\ArcGIS\Desktop<version>\Configuration\CATID. Make sure there is a file with the name of your assembly and the extension ecgf (it may also have some GUID at the beginning, e.g. {6d102248-13e2-40a0-8011-378543f63901}_MyAssembly.ecfg). This is just some zip-archieve, you can also unzip it and find an xml-file containing the GUIDs of your commands and tools. If registering the assembly didn´t work with the step mentioned before, you can just delete that ecfg-file and re-build (!!) your assembly. Then verify the file was created in that folder.

If that still does not work, just delete your compiled assembly alltogether with an eventually existing ecfg-file and re-build again.

MakePeaceGreatAgain
  • 35,491
  • 6
  • 60
  • 111
  • When I try to register the assembly using the command line I get the error `Could not load file or assembly "file: /// ... / Project1 / bin / Debug" or one of their dependencies. Access denied.` But I am using the command line as "administrator". I tried to enter Windows using the `net user administrator / active: yes` command. Still denied access. The location of "... ArcGIS \ Desktop10.5 \ bin \ Configuration \ CATID" no file with my build. There is only _esri.catid.ecfg_ . – Nolu Sep 23 '20 at 09:41
  • I deleted the _esri.catid.ecfg_ file and the assembly file and rebuild the project again, then the error `Cannot register assembly" ... \ Project1 \ bin \ Debug \ Project1.dll "appears. Exception has been thrown by the target of an invocation.` – Nolu Sep 23 '20 at 10:08
  • woe, that´s more descriptive than I ever got from the tool. Anyway the ecfg-files are not contained in ArcGIS´s program-folder, but in `%CommonProgramFiles%/ArcGIS`, which is `C:/Program Files (x86)/CommonFiles/ArcGIS` for me. – MakePeaceGreatAgain Sep 23 '20 at 10:08
  • The _CATID_ folder is located only in the `C: \ Program Files (x86) \ ArcGIS \ Desktop10.5 \ bin \ Configuration` location. I don't have the location "C: / Program Files (x86) / CommonFiles \ ArcGIS \ Desktop 10.5 \ Configuration \ CATID". The folder `C: / Program Files (x86) / CommonFiles \ ArcGIS \ Desktop 10.5` contains the _bin_, _Help_, _Support_, _ThirdParty_ subfolders and that's it. – Nolu Sep 23 '20 at 10:48