Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Visual Studio Won't Load AutoCAD for Debugging

jmcfarland1996
Contributor

Visual Studio Won't Load AutoCAD for Debugging

jmcfarland1996
Contributor
Contributor

Hi,

I am trying to debug a C# AutoCAD plug-in I made. I am using Visual Studio 2019 and AutoCAD 2020. I am using the "Start External Program" feature and upon pressing play, Visual Studio should open AutoCAD. It attempts to do this, but I get this message:

 

Loaderlock Exception.JPG

 

 

 

 

 

 

 

 

 

 

 

 

 

If I open AutoCAD manually and then netload my dll, no problem. But if Visual Studio tries to open AutoCAD, it won't do it. I need to open it this way because I am debugging my application. I am using the Managed .NET API with C#. How do I avoid running my managed code in DllMain? I am new to programming and can't figure this one out. Any help would be much appreciated!

0 Likes
Reply
Accepted solutions (1)
3,445 Views
15 Replies
Replies (15)

_gile
Consultant
Consultant

Hi,

Try the shortcut Ctrl+Alt+E to open the Exception Settings window > expand the Managed Debugging Assistant node > uncheck LoaderLock.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

jmcfarland1996
Contributor
Contributor

I tried this already. Visual Studio attempts to open AutoCAD, then just abruptly stops. Pretty much the same as before but without the warning.

0 Likes

ntclmain
Advocate
Advocate

@jmcfarland1996 
Could you capture your Project properties\ application and Project properties\ debug?
I have 2 assumptions:
1. Maybe something wrong with your project's Target framework, be sure to set project Target framework to .Net framework 4.7 (not 4.7.1 nor 4.7.2)

2. Maybe something wrong with your Debug\ Start external program, it should be (if autocad installed to default folder):

"C:\Program Files\Autodesk\AutoCAD 2020\acad.exe"

0 Likes

Keith.Brown
Advisor
Advisor

Make sure you in debug mode and not release mode.

0 Likes

jmcfarland1996
Contributor
Contributor

I was using .NET Framework 4.8, but I just changed it to 4.7 and it didn't help. Using a later version of .NET Framework than is necessary for a version of AutoCAD shouldn't hurt right? I remember I had successfully linked Visual Studio to AutoCAD on a previous project, and I just tried using that one and now it isn't working either! I don't know what happened...Loaderlock Exception2.JPG

Loaderlock Exception3.JPG

 

 

0 Likes

jmcfarland1996
Contributor
Contributor
I am in debug mode.
0 Likes

ntclmain
Advocate
Advocate

@jmcfarland1996 

From my poor experiences, I'm afraid that you've started with wrong project type.
For VS 2019, I started from the type "WPF app (.Net framework)",  and Project properties\ application\ Application type (Output type) should be: "WPF class library" not "Class library"

*
Here is my project properties, it works with CV3D 2022. The project can show user form over CV3D,

ntclmain_1-1644049082782.png

ntclmain_2-1644049108964.png

 

0 Likes

_gile
Consultant
Consultant

By any chance, is the Copy Locale property of the AutoCAD library references set to False?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

jmcfarland1996
Contributor
Contributor

Yes all three are set to false. I tried the "Start Without Debugging" button and it loaded AutoCAD just fine. It is only when I try to open it for debugging that it throws the exception.

Another possible clue: The breakpoints are disabled with this message:

The breakpoint will not currently be hit. No Symbols have been loaded for this document.

0 Likes

jmcfarland1996
Contributor
Contributor

I appreciate the help, but I have seen videos of people debugging with class library templates and I know it is possible. I have not yet attempted a WPF app in AutoCAD. I don't think this is the source of the problem. I tried checking the "Enable native code debugging" box in the debug menu. It then tries to load AutoCAD but endlessly tries to load symbols. Sometimes it gives me this error:

Loaderlock Exception4.JPG

0 Likes

_gile
Consultant
Consultant

Isn't your plugin alreay installed?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes

ntclmain
Advocate
Advocate

Update 7/2: After creating a test C# project with "Autocad 2022 Dotnet Wizard", I find out that the C# project type created by the wizard is non-WPF.  

(This is different from the VB project type created by the wizard (WPF))
With C# project created by the Wizard, I can start Autocad 2022 from VS debug after turn off Loader Lock.

I also attach the solution with C# project created by the wizard.

*

*

*

I've checked the sample solution at:

C:\Program Files\Autodesk\AutoCAD 2022\C3D\Sample\Civil 3D API\DotNet

If the Output type is "Class Library" then Debug\ Start external program is unchecked.

ntclmain_4-1644138753890.png

ntclmain_5-1644138799222.png

In this case I can still debug by:

1. In the same solution of your existing project, add another WPF project, declare Application & Debug tab, declare references as your existing project (I'm not sure if it is necessary), set the WPF as your startup project.

2. From VS 2019, start debug (F5) to open Acad.exe, in that Acad.exe instance, netload the existing non-WPF project .dll file which is located in \bin\Debug folder.

*
By the way, the previous WPF project I showed you was a mimic of another created by Autocad 2018 VB plug-in for VB.net in VS 2015.  Don't understand why it must be WPF, but it is working.

 

0 Likes

jmcfarland1996
Contributor
Contributor

Sorry if this is a dumb question, but what do you mean by installed? I am still pretty new to this so let me just run through what I am doing. I am using the class library template, writing some code, then building to make a dll file. I then open AutoCAD and netload that dll. I have been doing this for a while with no problems. But now my applications are getting more complicated and I want to debug my code. I thought the way to do this was to press the start button, and add AutoCAD to the "start external program" option. This is how I would debug a console app.

 

Am I missing something? What process do you go through to debug class libraries used in AutoCAD?

0 Likes

ntclmain
Advocate
Advocate

Go to this page

https://www.autodesk.com/developer-network/platform-technologies/autocad
Scroll to the end of the page, you will see the Dotnet Wizard (a plug-in / template for MS Visual studio)
For VS 2019, it is the 2021 and 2022 DotNet Wizard

ntclmain_0-1644222810842.png

ntclmain_1-1644222945637.png

 

 

jmcfarland1996
Contributor
Contributor
Accepted solution

Hey guys, update here. Thank you for all your help, I really appreciate it. I tried everything but nothing worked. Eventually I decided to start fresh with a new version of AutoCAD and Visual Studio. (I had been meaning to make the change anyway and as a member of the ADN this came at no extra cost to me.) After installing AutoCAD 2022, everything worked just fine! I think there may have been an issue with the particular version of AutoCAD I was using. It was an old student version of AutoCAD 2020 which was entitled "Civil 3D As AutoCAD". My best guess is that there was something wrong with the configuration file associated with that version. But who knows.

 

I am still using the class library template, but now that or any other template seems to be working fine. I use the template which is made for the type of project that I will be working on. I have not yet used the .NET wizard. I just set up my files manually and it only takes me a few seconds. But once again, thank you for your advice and the thought you put into this!

0 Likes

Type a product name