Testing and debugging your Enterprise Architect C# Add-In

In my previous post Tutorial: Create your first C# Enterprise Architect add-in in 10 minutes I explained how to create a simple add-in for Enterprise Architect.

(Smoke) testing your add-in

Once created you will of course want to test it to see whether it works.

The logical thing to do is fire up Enterprise Architect and try it out. And then, as it goes with software development, you discover a bug, or a missing feature.

Next thing you do is correct the problem, build the project… and get an error, because the add-in dll is being used by Enterprise Architect and it can’t be overwritten by Visual Studio.

So you close EA, build the project, open EA, find another issue,… rinse and repeat

After a while this whole process becomes a major annoyance that is really crippling your productivity.

Debugging your add-in

Debugging an add-in for Enterprise Architect is only possible when you have a full (payed) version of Visual Studio.

To debug your add-in (using a full version of VS) you set the appropriate breakpoints, start EA, and in Visual Studio choose Debug|Attach to process. Then choose ea.exe and start the functionality of your add-in. Visual Studio will then stop the execution of your add-in code at the breakpoints you defined, and you can debug away.

But again, if you change anything to the code, and want to re-build you’ll need to shut down EA first.

When you have a (free) Express version of Visual Studio you’re completely out of luck, since Microsoft decided not to include the “Attach to process” feature in the Express versions. (see Wikipedia for more details about he limitations of the Express versions)

The solution

To avoid this problem I wrote a small add-in test application that mimics the menu behavior of EA and allows you to test, debug and build your add-in without having to shut down and restart EA.

This add-in tester will only allow you to test and debug the menu driven functionality of your add-in. To test and debug the event driven functionality (things like EA_OnPostNewElement you will still have to resort to the annoying way of working)

Here’s what you need to do to use the test application

  • Download the source code from the Sparx Systems Community Site
  • Add the EAAddinTester project to your Visual Studio
  • Set the EAAddinTester project as Startup Project
  • Add a reference to your add-in project to the EAAddinTester project
  • Change the first line of code of the EAAddinTesterProgram.cs so it points to your add-in class
    // replace this next line with the addin you want to test
    internal static MyAddin.MyAddinClass addin = new MyAddin.MyAddinClass();
    
  • Disable your add-in in Enterprise Architect via Add-Ins|Manage Add-Ins…
  • There is an excellent tool available to enable/disable add-ins while starting up EA: Enterprise Architect Launcher
  • Shut down and restart EA
  • Hit F5 to start-up the EA Add-in Tester

Now choose the location of your menu and you should see the menu’s you’ve defined for your add-in.

Selecting a menu option will execute the appropriate functionality of your add-in just like EA would.

Using this tool will of course also solve the debug issue for Visual C# Express users.

http://en.wikipedia.org/wiki/Microsoft_Visual_Studio_Express#Visual_C.23_Express

20 thoughts on “Testing and debugging your Enterprise Architect C# Add-In

  1. Hi Geert,

    great contribution.

    One remark / clue:
    MS VS C# Express 2008 is able to debug a dll like an EA addin in the context of EA. It works fine. It may take some minutes to get it working.

    If you would like I send you a small project where you can see it by yourself (in fact your little example). C# 2008 express is still available to download and register. It also works parallel to the 2010 release.

    Kind regards,

    Helmut

    1. Hi Helmut,

      Thanks for the tip. Does that mean that the “attach to running process” functionality only has been removed as from the 2010 version?
      Anyhow, I’ve gotten pretty used to sharpdevelop now, and I even prefer it above the full version of VS.

  2. Hi Geert,
    Thank you for your article.
    I haven’t had any problems with VS2005, but now with VS2010 Professional I can’t debug my addin. When I run the project in debug mode with the attached ea.exe a message window appears with this text:

    Sparx System – http://www.sparxsystems.com
    A debugger has been found running in your system.
    Please, unload it from memory and restart your program.

    Do you know what could be happening?

    Thank you,

    Frederic

    1. Hi Frederic,

      I think you either need to attach ea.exe and then execute the functionality from within EA, or you run your test application from within VS.

      Geert

  3. Hi Geert,
    first of all thanks for your huge support of this article and the one before,

    i’m trying to debug MyAddin (have 2010 ultimate with the option to attach to proccess),
    i’m starting the EA and then trying to attach but it seems it cannot load the symbols of my DLL, do you know why its happening? is there any definition i’ve forgot?

    i’m pretty sure that my DLL is the one EA loads cause i can’t delete it while the EA is open 🙂

    thanks for your support!
    Haim.

  4. hey geertbelle. I think this software is very very interesting for engineers. But it is difficult to understand it how to develop it and how to use is by other programmings. Example. how to develop it using C#, java .etc. so if you are interested plz make us to gate an access based on video forms. if possible send it through brhane.MIT@gmail.com.

  5. Hi,

    I have a problem when i’m using your test application. I can debug but i can’t get current resource for example “currentRepository.GetTreeSelectedItem(out selectetObject);” it’s always null. Is this because my currentRepository is incializing in EA_Connect method which is maybe event_driven?
    And if it so, i have a problem to test my add in with VisualStudio 2010 I attached my dll to a proccess but when i start to debug EA is shuting down.

    Thanks,
    Aleksandar

    1. Well, now we have Visual Studio 2013 Community Edition, which allows us to Attach to Process to our hearts desire and for free…

      Many thanks for your multi-faceted intro to plugin development and for your tempaltes an d tools. This is all very helpful!

      Cheers,
      Hermann

  6. I think it’s important to note that one should be running both applications (VS & EA) as an Adminstrator. One will need admin privileges to register the addin dll and the VS will need to have EA running as the same user in order for ‘Marshal.GetActiveObject(“EA.App”)’ to be able to access to that object. That was a painful lesson on a Saturday night… 😉 BTW I really appreciate all the great work Geert has provided the EA community. I don’t know where I would be without it. Thank you sir….

Leave a Reply