.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
11042 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 2 of 46
aksaks
in reply to: Artvegas

Of course. Are you kidding? This is going to a great help for me. I cannot wait to try it out on Monday. I am just starting out to rewrite my acad VBA applications to .NET and I have come to the conclusion that I will need to develop as much of the applications as I can independent of AutoCAD before adding in the AutoCAD aspects that will require netloading to continue development. I have considered doing manually what NRL does but as a VS greenhorn I am already overwhelmed performing even the simplest task. I hope you will share this and future applications with us.

 

Thank you!

 

aks

Message 3 of 46
aksaks
in reply to: Artvegas

I built the project with no errors reported but Microsoft stepped in at Netload time telling me I did not have permissions to do so. I am using VS 2010 express. I can build and netload vb creations. Can you help with this? Thanks. 

Message 4 of 46
Artvegas
in reply to: aksaks

Hi aks,

 

Thanks for highlighting your issue. Unfortunately it appears that Visual Studio Automation (i.e. COM) is not supported for express editions. I assume this is the problem you are experiencing.

 

I do have another technique for automating this process using the pre-build event command line setting in Visual Studio. I'll send you a private message on here in a short while.

 

Cheers,
Art

Message 5 of 46

I would not recommend this method for debugging:
1. If the application is subscribed with the events of AutoCAD - will be conflict.
2. If your application uses shared resources (file, database) - will be conflict.
3. If the application uses the palette - will be conflict.
Only in the simplest cases, you can use this algorithm.
IMHO.

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 6 of 46
fieldguy
in reply to: Artvegas

I cannot "build" my app after it has been netloaded in acad.  VS 2008 gives me this message:

 

Error 1 Unable to copy file "obj\Release\ViewPorts.dll" to "bin\Debug\ViewPorts.dll". The process cannot access the file 'bin\Debug\ViewPorts.dll' because it is being used by another process. ViewPorts

 

1. Start acad

2. Load app

3. Make changes to code

4. Build generates error

Message 7 of 46

Hi Alexander,

 

Yes these should definately be kept in mind. This utility will not necessarily suit some of the situations you listed, and I wouldn't say it's the way to go when debugging large fully fledged applications.

 

But if you're just looking to experiment with different parts of the API it is very cumbersome to:

1. Close the drawing you are working on.

2. Close AutoCAD.

3. Change your code in Visual Studio.

4. Build your dll in Visual Studio.

5. Re-start AutoCAD.

6. Re-open the drawing you are working on.

7. NETLOAD your revised dll.

 

Especially for every change you make to your code - no matter how small. With my utility you can skip steps 1, 2, 4, 5, 6 and 7 above. All you have to do is change your code in Visual Studio and then run my NRL command in AutoCAD.

 

I like to think this is for the pragmatist. It's saved me loads of time.

 

Thank you for your feedback.

 

Art

Message 8 of 46
Artvegas
in reply to: fieldguy

Hi fieldguy,

 

Yes that is the error you will receive in Visual Studio when you try to build (F6) to a dll that has already been loaded into AutoCAD (i.e. using NETLOAD). Makes sense to me.

 

It's important to understand with this utility that you don't actually do anything from Visual Studio (other than change your code).

 

In order to use the utility, please try the following:

1. Download the attached zip file from my original post and extract the NetReload.dll file.

2. Open your solution in Visual Studio and make sure that at least one of your project's code files are current.

3. In AutoCAD, load the NetReload.dll (i.e. using NETLOAD).

4. Run the NRL command in AutoCAD. This command will do all of the work for you. You will be prompted from within AutoCAD to select a running instance of Visual Studio. The command will then automatically build the solution and load it into AutoCAD. You won't have to switch back to Visual Studio.

 

Please don't hesitate to let me know how this goes for you, or if you have any further questions on this.

 

Cheers,

Art

Message 9 of 46
fieldguy
in reply to: Artvegas

I understand now.  Thank you very much - this is an awesome tool!  Nice code - that opens some new doors.  Thanks for sharing.

 

The user has to make sure to build from VS at the end of the development process to make sure the dll with the desired name matches the "tempassemblyname" dll. 

Message 10 of 46
Artvegas
in reply to: fieldguy

Hi fieldguy,

 

Yes that's right. The utility creates randomly named dll files in the "bin\Debug\NetReload\" folder. Once you're finished you should build (F6) your solution in Visual Studio to update the dll in the "bin\Debug\" folder.

 

Glad you like it Smiley Happy

 

Art

Message 11 of 46
aksaks
in reply to: Artvegas

My initial problem is caused by the assembly being loaded off our local network. I am able to netload it when it resides on my local drive. Now the problem is , "No running Viusla Studio instances were found." I am hoping this can be fixed with a tweak to the code somewhere. Do you think this is possible?

 

Thanks, aks

Message 12 of 46

As an alternative - simply rename the dll-file and create a new one with the same name

Відповідь корисна? Клікніть на "ВПОДОБАЙКУ" цім повідомленням! | Do you find the posts helpful? "LIKE" these posts!
Находите сообщения полезными? Поставьте "НРАВИТСЯ" этим сообщениям!
На ваше запитання відповіли? Натисніть кнопку "ПРИЙНЯТИ РІШЕННЯ" | Have your question been answered successfully? Click "ACCEPT SOLUTION" button.
На ваш вопрос успешно ответили? Нажмите кнопку "УТВЕРДИТЬ РЕШЕНИЕ"


Alexander Rivilis / Александр Ривилис / Олександр Рівіліс
Programmer & Teacher & Helper / Программист - Учитель - Помощник / Програміст - вчитель - помічник
Facebook | Twitter | LinkedIn
Expert Elite Member

Message 13 of 46
fieldguy
in reply to: aksaks

I think you need to search here for CASPOL.  You can run dlls locally or setup CASPOL to allow access to user defined network dlls.

Message 14 of 46
Artvegas
in reply to: aksaks

Hi aks,

 

Did you get my response to your last post?

 

I don't believe this will work for VS express editions. However I might have another way of doing this with express.

 

I sent you a private message. To access your messages just click on the mail symbol at the top of the webpage (as shown in the pic below):

 

aaa.jpg

 

Hope to hear back from you soon.

 

Art

Message 15 of 46
Artvegas
in reply to: Artvegas

Hi Alexander,

 

I did try that - unfortunately renaming dll files doesn't work. The commands don't get overriden.

 

It appears that the dll files need to have different Intermediate Language (IL) signatures. Then the commands are overriden in AutoCAD with subsequent NETLOADs.

 

If you change a project's AssemblyName property before you compile the dll files, then it works. I'm not exactly sure of the reason. I'm guessing when I say it might have something to do with the way AutoCAD loads .NET assemblies into its AppDomain.

 

Art

Message 16 of 46
aksaks
in reply to: fieldguy

Thanks for reminding me about CASPOL. I did not have rights to do that the last time I looked into this. I'll give it another shot. Thanks 

Message 17 of 46
KevinMacDonald
in reply to: Artvegas

I am a fairly seasoned .NET developer and have been battling to set up a reasonable environment in which to work with Autocad 2013 / Visual Studio 2012. It has been quite a pain between not being able to debug, nor being able to "netreload" an assembly. This little utility is clever as hell, useful as all getout, and the first bit of light in my otherwise dismal experience with this. Nice work-around. Thank you Artvegas! 

 

FYI I had to set up a project and recompile it to get NetReload.dll to work in Autocad 2013. Also, the EnvDTE assembly can be referenced from Assemblies --> Extensions. Had to search for that a bit.

 

Kevin

Inventor 2013
Message 18 of 46
serafin.albiero
in reply to: Artvegas

First... Thank you very much!!!!

 

For those using the new Microsoft Visual Studio 2012 Express for Windows Desktop edition, here's the compatible version I compiled.

 

NetReload2013 command to run!

Serafin A. Albiero Jr.
Message 19 of 46
mzakiralam
in reply to: Artvegas

Hi ,

 

I have tried to load your dll file direct with netload command. It shows me below error:

 

Command: netload
Cannot load assembly. Error details: System.IO.FileLoadException: Could not
load file or assembly 'file:///C:\Users\alamzaki\Desktop\VB_PPT\NetReload.dll'
or one of its dependencies. Operation is not supported. (Exception from
HRESULT: 0x80131515)
File name: 'file:///C:\Users\alamzaki\Desktop\VB_PPT\NetReload.dll' --->
System.NotSupportedException: An attempt was made to load an assembly from a
network location which would have caused the assembly to be sandboxed in
previous versions of the .NET Framework. This release of the .NET Framework
does not enable CAS policy by default, so this load may be dangerous. If this
load is not intended to sandbox the assembly, please enable the
loadFromRemoteSources switch. See http://go.microsoft.com/fwlink/?LinkId=155569
for more information.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean
forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String
codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint,
StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean
forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName
assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean
forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile,
Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm
hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks,
StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
   at loadmgd()

 

Can you have a look at this? It seems to me that this utility would be great if I can use it. I use only VB so I did not build your C# code into dll. Do you have VB command for this utility?

Message 20 of 46
mzakiralam
in reply to: mzakiralam

Sorry , I forgot to add my ACAD version. I am using ACAD2011 to load your dll

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