.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NET-RELOAD Utility for Visual Studio - Download Here

45 REPLIES 45
Reply
Message 1 of 46
Artvegas
11046 Views, 45 Replies

NET-RELOAD Utility for Visual Studio - Download Here

NET-RELOAD Utility

 

I’m sure many of you are aware that there is no "NETUNLOAD" command for unloading a .NET assembly from AutoCAD. Apparently this would require a significant change to AutoCAD's .NET API and is not likely to change anytime soon. Refer here for further details: http://through-the-interface.typepad.com/through_the_interface/2008/09/tired-of-not-be.html

 

As an alternative, I have created an AutoCAD utility that allows you to "re-load" an assembly after making modifications to your code - the best bit being you can do this WITHOUT having to re-start AutoCAD each time.

 

I’d be really interested in hearing if you find this utility useful for AutoCAD .NET development purposes.

 

Cheers,

Art

 

 

Instructions

 

To run the utility:

 

1. download the attached NetReload.dll.

2. run AutoCAD, but do NOT start it from Visual Studio.

3. NETLOAD the NetReload.dll into AutoCAD.

4. open Visual Studio and make sure a file from the particular project you wish to re-load is active.

5. go back to AutoCAD and run the NRL command.

6. in the command-line, select the Visual Studio instance you wish to re-load into AutoCAD.

 

If you subsequently go back to Visual Studio and change your code, and then re-run the NRL command in AutoCAD again, the code changes will automatically be loaded into AutoCAD and ready to use.

 

Note that you won’t be able to debug your code in Visual Studio with this tool (i.e. place breakpoints and step through code). You’ll have to re-start AutoCAD from within Visual Studio to do this.

 

 

Notes

 

1. Supports multiple opened instances of Visual Studio.

2. Has been checked in AutoCAD 2011 and 2012 (should also work in AutoCAD 2010).

3. Has been checked with Visual Studio 2010 (should also work for previous versions).

4. The NRL command will default to the last chosen solution for the current AutoCAD session.

5. The NRL command will advise if:

    - no Visual Studio instances are currently open.

    - no solutions are open in any of the currently opened Visual Studio instances.

    - no document is active for the chosen solution.

 

 

How It Works

 

Technically the NRL command does not actually re-load the assembly for the chosen Visual Studio solution. Instead it does the following:

 

1. accesses the chosen Visual Studio instance using Automation (i.e. COM).

2. based on the active Document for the Visual Studio instance, gets the project to compile.

3. sets the project’s "AssemblyName" property to a random name.

4. compiles the project to an assembly in the following project folder: "\bin\Debug\ReNetload"

5. sets the project’s " AssemblyName" property back to its orignal name.

6. NETLOADs the assembly from "\bin\Debug\ReNetload" into AutoCAD.

 

The reason this works is because when you NETLOAD the randomly named assembly into AutoCAD, all of the previously defined commands of the same name are overriden by those defined in the last loaded assembly.

 

 

Tips

 

A quick way to get this assembly to automatically load when AutoCAD starts is to add the lisp code below to the acad2010.lsp / acad2011.lsp / acad2012.lsp file. Obviously you will need to change this depending on where you place NetReload.dll.

 

(setq S::STARTUP (append S::STARTUP (list (command "netload" "C:\\MyAutoCAD\\ NetReload.dll") (princ))))

 

 

Source Code

 

I have attached the C# source code file so you can build this yourself.

 

Note that you will need to add the following project references so that it compiles:

 

1. envdte.dll (Visual Studio Automation - i.e. COM).

2. System.Windows.Forms.dll (WaitCursor helper class).

3. acdbmgd.dll and acmgd.dll (AutoCAD).

45 REPLIES 45
Message 21 of 46
KevinMacDonald
in reply to: mzakiralam

After you download and unzip the DLL try right clicking on the DLL and pulling up the Properties dialog. On the General tab at the bottom you might see "This file came from another computer and might be blocked...". Click the "Unblock" button and try again.

 

Kevin

Inventor 2013
Tags (1)
Message 22 of 46
mzakiralam
in reply to: KevinMacDonald

Unfortunately, I did not get any option as you mentioned.

Message 23 of 46
serafin.albiero
in reply to: Artvegas

Here´s the VB.Net class. I hope it helps you! 

Serafin A. Albiero Jr.
Message 24 of 46
KevinMacDonald
in reply to: mzakiralam

I do recall having the same problem, but it's been awhile and I don't remember the precise fix. Something that would fix it for sure is downloading the code and building the DLL yourself. Note that the error being thrown is a sandbox error, i.e. .NET thinks it might be a rogue DLL of some sort. So, you have to convince the .NET run time that is not the case. Building it yourself would definitely accomplish that. Kevin
Inventor 2013
Message 25 of 46

Hi serafin.albiero ,
 
Thanks a lot for your effort. Today I have tried and successfully build the dll which is currently working fine.
 
Thanks once again.
 
Zakir
 
Message 26 of 46

Good to know buddy!!  Thanks...

Serafin A. Albiero Jr.
Message 27 of 46

After I Netload NetReload.dll or a later version NetReload2013 (by serafin) I cannot issue the NRL command.

Is this because I am using VSE2012. How do I make a VS project active?   

Message 28 of 46

You should read this whole thread. Try re-building the utility yourself so that you don't get any .NET code security errors. 

 

It's been awhile, but I think I eventually found that restarting Autocad each time while testing my code wound up being easier than using NRL.

Inventor 2013
Message 29 of 46

Thanks Kevin. 

 

I tried to re-build using VSE2012 and managed to get as far as issuing the NRL command. However, it reports back that "no running Visual Studio instances were found." Is this because I am not using VS? Any ideas.

 

Message 30 of 46
fieldguy
in reply to: david.ngLU45T

The instructions are pretty clear in the 1st post.  This is how I use it (currently Civil 3D 2015).

 

Assume that you have rebuilt the net reload utility - this is recommended as it is well written code and good to learn from.  The required references and locations may have to be changed.  I copy my version of the reload utility dll to the current application ..\bin\debug folder.  This makes it easier to load both dlls in autocad.

Assume that you have Visual Studio open, and you've got your application built and ready to test.

 

Start autocad using the normal method - in my case a desktop icon.

Issue the netload command and load both -

eg.  C:\Users\user\Documents\Visual Studio 2015\Projects\App1\App1\bin\Debug\App1.dll

eg.  C:\Users\user\Documents\Visual Studio 2015\Projects\App1\App1\bin\Debug\NETRELOAD.dll

 

Run your app, and make changes as required in Visual Studio.  I always create messages and show boxes but some use the acad text window.  Since you cannot use breakpoints, you need some way for your app to communicate results with you.

Use NRL in autocad to "build and reload" the modified visual studio contents.

 

In other words, you are using Visual Studio to make the changes, and the reload utility (NRL) to manage building and loading the new dll.  It does this by using a random file name generator.  You can see this happen in the appropriate ..\bin\debug folder.

 

This is a slick utility - I use it every day.  Thanks again Art! 

Message 31 of 46

That could very well be the problem. The NRL code is specifically looking for running objects that start with "!VisualStudio.DTE". It's possible that you might be able to figure out what VSE uses and change the NRL code.
Inventor 2013
Message 32 of 46
david.ngLU45T
in reply to: fieldguy

Thanks Fieldguy,

 

I tried to follow your instructions. This is what I got.

 

I loaded myapp.dll and netreload.dll

 

When I proceeded to re-build my dll in VSE, I got the following error.

"... The process cannot access the file 'bin\Debug\myapp.dll' because it is being used by another process.

 

In AutoCAD. When I tried to run nrl, I got

"No running Visual Studio instances were found" 

 

 

I think it is my combination of VSE2012 and AutoCAD2016 that is somehow not allowing me to use Netreload.

There was some brief mention about VSE and CASPOL in earlier posts.

 

Any ideas

 

Message 33 of 46
fieldguy
in reply to: david.ngLU45T

>>When I proceeded to re-build my dll in VSE, I got the following error.<<

 

Don't use Visual Studio to re-build after you have netloaded "myapp.dll".  You will get the error "..being used by another process". Autocad has it.  The NRL utility handles the re-build and re-load of the modified visual studio project.

 

I am not sure about VSE.  I know for sure that this works with Visual Studio Community 2015 - I recommend that you upgrade. 

You don't have to worry about CASPOL if you work from a local hard disk.  There are other ways to handle loading of dlls from other sources but I am out of date on that.

If visual studio is running and your project is open, I don't know why Autocad is not seeing the "running instances".

 

Good luck!   

 

Remember - don't use build in visual studio until Autocad is closed.

Message 34 of 46
david.ngLU45T
in reply to: fieldguy

Thanks fieldguy,

 

I downloaded VSC2015 and rebuilt myapp.dll and Netreload.dll.

They work beautifully! Now I can rebuild myapp.dll using NRL within AutoCAD.

 

In summary, Visual Studio Express should be avoided when using the original Netreload utility.

 

Message 35 of 46
lukasborges
in reply to: Artvegas

I did not find any replacement for this utility, so I decided to roll with it.
It was posted in 2011, and in 2018 I still got it to work with Visual Studio 2017 and AutoCAD 2019!
The .dll did not work, so I compiled the source code in VS2017. In order to compile I had to go under the Solution Explorer, right-clicked References, and Add References. Searched for EnvDTE, and System.Windows.Forms; added these to the project. VS2017 had some of these references removed for faster boot.

 

Then I compiled the Netreload .dll, loaded it in AutoCAD with NETLOAD, typed NRL to select your open instance of visual studio and loaded my .dll in development. Remember that if you attempt to reload a .dll with repeated CommandMethod names, you will get an eDuplicateKey error, and the "reload" won't work.

 

Although I'm grateful for this workaround, I think AutoCAD should have native support for this feature.

Message 36 of 46
microtecnologo
in reply to: Artvegas

Hi Artvegas,  This is Fernando (microtecnologo) from Mexico, it is nice to know about your net-reload work, but i have 2 dificultities:

1.- I could not NetLoad your dll, Autocad 2012 report this message: "Cannot load assembly. Error details: System.IO.FileLoadException: Could not load file or assembly 'file:///C:\Metriko_64\NetReload.dll' or one of its
dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
File name: 'file:///C:\Metriko_64\NetReload.dll' ---> ..." I guess previously I need to register the class and, I do not know how to.

2.- Is it necessary to have active the VS ide? Is it possible to Reload a csproj or *.sln file. My necesity is a little bit different: I have a dll to lock selection of Entities which works pretty nice just on the first drawing BUT, at the moment

I open another drawing the application loss its funcionality.

  I will apretiate your help. 

  Greetings from Mexico.

 

Message 37 of 46
thang605
in reply to: lukasborges

Hi,

work with Visual Studio 2017 and AutoCAD 2019!

I compiled the source code but I get error.

New Bitmap Image.jpg

Could you please send me your Netreload .dll?

 

Best Wishes

Message 38 of 46
thang605
in reply to: thang605

I found the error from my code.

I send netreload.dll (use for visual 2017 and autocad 2019) for someone need 🙂

I can't send file to forum. So just a link:

http://www.mediafire.com/file/w75369e6d5t1uq5/NetReload.dll/file

Tags (1)
Message 39 of 46
simon
in reply to: Artvegas

Just found this and it is exactly what I was looking for. Thanks for making it available. It really does make life easier when developing for Autocad. 🙂

Message 40 of 46
javedw
in reply to: thang605

This tool is awesome.  OMG! - This is saving me so much of time.  Thank You to everyone that worked on putting this together and upgrading it for the newer versions of AutoCAD.

 

This is Genius!

 

Javed

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost