Debugging using Express Editions

Most of our desktop products support a "plug-in" model of development: you create a DLL (which may or may not be renamed with a number of extensions, such as DBX or ARX) which gets loaded into the calling executable's memory space. This allows the process to share memory with the loaded modules, improving performance over the more archaic IPC (inter-process communication)-based architectures.

[Here begins retracted information...]

While Visual C++ Express Edition supports debugging DLL projects using an external executable, Visual C# Express and Visual VB.NET Express Editions do not. When developing with our products it is extremely common to launch an external executable (for instance AutoCAD's executable, acad.exe), which in turn loads your class module/DLL into its memory space, allowing you to step through the code, watching the contents of variables and all the good stuff that comes with a professional debugging tool.

This essentially means these two tools (Visual C#/VB.NET Express Editions) are crippled when it comes to doing serious development work with a plug-in architecture such as AutoCAD's. Visual C++ Express Edition, on the other hand, apparently allows you to debug DLL projects fully.

[End of retracted information.]

OK - I'm adding some information to this post... the paragraphs above belonged to my initial post, and aren't strictly true. Thanks to Ray Mendoza for raising this issue.

While Visual Basic 2005 (and presumably Visual C#) Express Edition does not make it easy for you to set up and use an external application to debug a class library, it is possible to do. Here's the initial message you get, when you simply try to debug a class library with no addition project set-up performed:

Vb_express_debugging_2

While at first you think "OK, great - let me just add in acad.exe and have it as the startup object", when you come to modify the project settings, there's no easy way to do it. You may be able to add in a separate EXE project to debug, but we don't have or need that for a pre-built EXE such as AutoCAD.

So what can we do? Well, it turns out that all you need to enable debugging in Visual Basic Express Edition is a separate file in the project folder, called "MyProjectName.vbproj.user". This contains the user-specific project settings for the MyProjectName project. In my test I used the default project name for a Class Library, and so the file was called "ClassLibrary1.vbproj.user" and in the same folder as "ClassLibrary1.vbproj". Here are the contents of that file:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files\AutoCAD 2007\acad.exe</StartProgram>
  </PropertyGroup>
</Project>

After creating this file (please make sure the executable path is correct for your system, of course), you will need to reopen the project for it to be detected and read. But once it's found, you can debug your class library project with an external executable, just by hitting F5. Once AutoCAD is loaded, NETLOAD your DLL and away you go.

This file does get created automatically using the Autodesk Managed AppWizard (part of the ObjectARX Wizard - see the previous post for more information).

Now - if someone out there knows an easier way to set this up directly in VB Express, please do let me know, by email or by adding a comment to this post. This is the first time I've used VB Express myself, so there may well be something obvious that I've missed.

  1. I use VB .Net Express to create cutom functions in AutoCAD...I have had no problem getting VB Express to debug...I have to tell it to startup AutoCAD and I also have to netload the dll that I am creating...I get the "do not use managed code..." error a few times, but everything runs well after that...

  2. Paul Richardson Avatar
    Paul Richardson

    Thanks for the update..Thought it was just me.:)

  3. Thanks very much did the trick also had to set the working directory to same location as exe to avoid a subsequent error.

  4. Hello, all. Those who attended my classes last year at AU (AU 2006) received a DVD that included a Template for creating VB.NET applications using VB.NET Express. I have since created templates that can be used for creating Jigs (both Draw and Entity Jigs) using VB.NET Express Edition. Look me up this year if you would like these templates.

    By the way, nearly all of my classes use VB.NET Express edition - even the Hands-On Introduction to VB.NET Labs.

    Take care and I hope to see you at AU 2007.

    Jerry Winters

  5. Thanks, Jerry.

    Looking forward to seeing you in Vegas!

    Kean

  6. Now that VS 2008 is out, does the first line of the above file need to change?

  7. It's possible - I won't have time to research whether the information provided is still relevant in the 2008 Express Editions for some time.

    If someone researches this and finds out what changes are needed (if any), please post the information as a comment.

    Kean

  8. I tried this same thing with the C# Express Edition 2008 and it worked just fine without any alterations.

  9. Is anyone getting a LoaderLock Error when they start debugging?

  10. I am using VB.net Express 2008
    Below The LoaderLock Error, I am getting this error:
    I'm not how to fix it???
    Any ideas?
    Thanks
    Mark

    DLL 'C:\Program Files\Autodesk Land Desktop 2006\FdoConfigUi.dll' is attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

  11. Kean Walmsley Avatar

    Hi Mark,

    Sorry - I don't use Land Desktop, so don't see this error.

    Is this something you can disable in Debug -> Exceptions... ?

    Regards,

    Kean

  12. Seems to work just fine in Express 2008. The vbproj.user file already existed in my project with the exact same first line so I just replaced it. Pointed it at the AutoCAD 2008 executable and finally I can netload & debug.

    Thanks

  13. Hi, Mark
    i am using VS Express(VC,VCS,VB) , i have a problem that i can not build object arx in VC because have link to ATL or MFC, can i do without ATL/MFC?

  14. for LoaderLock Error you can unactive "Loader Lock" by:
    Hit CTRL+Alt+E (mnu debug/exceptions)
    In managing debbug...
    uncheck loaderlock

  15. Hi!

    I tried this with Visual C# 2008 Express, and it works, too. You've just got to name the extra file "MyProjectName.csproj.user".
    Thanks a lot to the author - you saved me a lot of hassle =)

  16. Oscar Quintero Avatar
    Oscar Quintero

    I'm using Visual Basic 2008 Express Edition.
    I tried and it was really helpful.
    Thanks.

  17. Ferry Kranenburg Avatar
    Ferry Kranenburg

    Hi!

    If you also would like to automaticly netload your dll in Autocad from Visual Basic 2008 .NET then do the following:

    - create a text file in notepad
    - type in : netload ..\bin\Debug\[myclass].dll
    - save the file in you vb project directory as "script.scr"
    - in the VB.net IDE go to you project properties => debug => and type in the 'command line arguments' /b "[path to VB.net project]\script.scr"
    - if you debug your project then the DLL in the debug directory will be netloaded.

  18. I am using visual studio C# 2008 express but do not see the .csproj.user file only the .csproj file. Am I missing a step?

  19. aok -

    If I recall correctly, the point is that you need to create the .csproj.user file yourself.

    Regards,

    Kean

  20. Magnus Jørgensen Avatar
    Magnus Jørgensen

    Hi everybody

    I'm using VSE 2008 and can't get this to work.
    When doing the NETLOAD part i get this error in VSE:

    A first chance exception of type 'System.TypeInitializationException' occurred in ACADProject.dll

    Does anyone know what to do about this?

    Thanks
    Magnus

  21. Magnus Jørgensen Avatar
    Magnus Jørgensen

    By the way....

    Netloading the project works just fine when i start AutoCAD normally..

  22. Hi Magnus,

    Hopefully you've found a way around this: people have (I'm led to believe) managed to make this work with the 2008 Express editions, but I haven't tested it myself.

    Regards,

    Kean

  23. Hello!

    I'm a bit late with this, but we just started to test using C# with autocad. We currently use Autocad 2007, but we will update to 2010 or 2011 when we have tested and programmed enough code.

    Thanks to this article we managed to get the debugging up and running in Visual Studio 2005 Express. (how did you find this out? We'd never found this ourselves!)

    Now, is it normal that autocad is started and closed everytime? Isn't it possible to have autocad open the whole time? This would make our debugging much faster and easier.

    Or is this only possible in the professional edition, or maybe in a more recent version (2008, that will be needed for Acad 2010/2011)?

    Thanks!

  24. Kean Walmsley Avatar
    Kean Walmsley

    Hello Jeroen,

    We noticed that Class Library projects created using full Visual Studio had debugging enabled in Express versions: the rest was just a matter of comparing the respective files. No real magic. 🙂

    You should be able to use edit & continue in Express editions, I believe.

    Regards,

    Kean

  25. This also works with Visual C# express...

  26. Hello!

    I tried this trick with VS 2010 express edition C#; I was able to start my external application (which loads my dll then), but I can´t hit any breakpoints I set (which makes debugging quite useless...:( ). Has anybody done that successfully with VS 2010 Express for C#. I´d appreciate any help on this...

    Best regards...

  27. Kean Walmsley Avatar

    Hello Maria,

    The information in this post should be of help.

    Regards,

    Kean

  28. Hi Kean,
    I have the same problem as Maria had(or still has?).
    As I'm using VS 2010 Express C# I it is not possible to me to change the options from solution 1 and 3.
    Changing 'acad.exe.config' (solution 2) require write privilege on that file which I don't have... Are there other ways to get it running correctly?
    Thanks

  29. Hi Miro,

    Without write access to acad.exe.config you may be out of luck.

    There may be some information in this post about Revit that may help you (I haven't looked at it in detail, myself).

    Regards,

    Kean

  30. Thank you very much for this helpful tick

    it's working for me with Delphi Application.

    Regards

  31. This is a great trick thank you! I am using C# express 2010 and the right name for the file is MyProjectName.csproj.user
    No change of the schema file to do it is still 2003

  32. hey man, thank you very much for this hint! I appreciate that!regards from germany!! johannes

  33. Great Help/Info - Worked under VB.Net Express 2010 Win7-64 PC, 32bit app. Debugged DLL created as an Event Handler in an SDK. File 'ClassLibrary1.vbproj.user' gets generated when creating a new project, so it just needed to be edited with the entry 'PropertyGroup Condition=...'. Needed to re-build each time after editing code. Could not edit during debug.

  34. Hi Kean,

    Many thanks for this article! It was just what i needed to start debugging my add-in for Sparx Enterprise Architect. Hope you don't mind i posted this on its resources forum.

    best regards,

    Paulus

  35. Hi Kean,

    I used this trick against Visual Studio 2013 express on a c# project.

    I just gave the file extension .csproj.user and all ran fine. Even If we do not see the "start external program" in the debug section of the project's options, Autocad starts when debugging is launched. Magic!
    Thank you a lot!

  36. I tried this trick as well in Visual Studio 2013 (plus another one I've seen before) to debug in Revit 2013 but something is odd. After I get into Revit and open a project, all the buttons are grayed out. I was able to debug previously in VS2012 but then I upgraded. Has MS caught on? Any ideas? Thanks in advance.

  37. I'd be surprised if this was due to some deliberate action, to be honest. You might try posting to the Revit developer discussion group, to see if anyone there has some ideas.

    Kean

  38. does this apply to VSE2013. I could not find the "ClassLibrary1.vbproj.user" file. How do I set this up in VSE2013 ?

    1. Looking at Rémy's comment, it seems so. I haven't tried it myself, though.

      Kean

  39. Thanks so much for sharing this useful information.
    I'm developing a VB6 addin as a COM dll in C# 2010 Express.
    I followed your advice ( the file should be *.csproj.user with C# ) and
    now I am able to debug it !!!

  40. Works well with AcCoreConsole.exe too.

  41. Thomas Irmscher Avatar
    Thomas Irmscher

    i need to start my hostprogram with some parameters. there is no way to start it by just running the exe-file.
    what is the correct way to modify the ...csproj.user to use an exe with additional parameters.

    I've tried:
    <propertygroup>
    <startaction>Program</startaction>
    <startprogram>C:\Program Files\Tecnomatix\eMPower\Tune.exe /c NewAssembler /l offline</startprogram>
    </propertygroup>

    If i try this, but VS C# Express tells me, that this is not an EXE-File.
    (of course it's not)

    1. Kean Walmsley Avatar

      Try placing the arguments inside a <startarguments> element.

      Kean

      1. Thomas Irmscher Avatar
        Thomas Irmscher

        i used:
        <startprogram>C:\Program Files\Tecnomatix\eMPower\Tune.exe</startprogram>
        <startarguments>/c NewAssembler /l offline</startarguments>

        and it works. Thanks

  42. I stumbled across this post somehow. But for the benefit of those who are reading this post 10 years later - this post is now obsolete. Microsoft are basically getting the big companies to pay for Visual studio, and are not targetting small time users - which would be most of you. you can download Visual Studio Community edition which has most things a dev starting with Autocad needs. There you can easily debug in visual studio.

Leave a Reply

Your email address will not be published. Required fields are marked *