March 2015

Sun Mon Tue Wed Thu Fri Sat
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31        


« An interview with John Walker - Part 3 | Main | Mirroring AutoCAD entities using .NET »

September 29, 2008

Tired of not being able to NETUNLOAD from AutoCAD? "Edit and Continue" to the rescue!

A question came in on a previous post:

Hello, I write applications for Autocad Map and Civil3d platforms, mostly with ObjectARX. I would like to do more with .NET but so far the main reason preventing this is not having the NETUNLOAD command.. With arx I can just arxunload and arxload the application for modifications in a second. But with .NET I have to restart the heavy environment and do all kinds of lengthy initializations before being able to try even small changes in code, this can take a minute or more.. Maybe it is possible to create an utility, for development purposes, to unload a .net assembly from Autocad ?

NETUNLOAD has been requested many times by developers, but unfortunately would require a significant change for the .NET API - one it's unclear there'd be significant benefit in making. The root of the situation is that .NET assemblies cannot be unloaded from an AppDomain.

To implement a NETUNLOAD command, we would have to host each assembly in a separate AppDomain and then destroy the AppDomain to unload it. It's altogether possible to implement your own bootstrapper assembly that does just this: I'm going to give that a try, to see how it works, but in the meantime I thought I'd point out (or remind you of) a capability that to greatly reduces the need to continually unload modules from AutoCAD: Visual Studio's Edit and Continue.

Edit and Continue has been around since VB6, although you may not have looked at it in recent versions of Visual Studio. I personally didn't start finding it usable again until Visual Studio 2005 (and its Express Editions). If you'd previously turned your back on it, I suggest taking another look.

To enable Edit and Continue, start by editing the Debugging options (accessed via Tools -> Options in the Visual Studio editor):

Debugging Options - Edit and Continue

If you attempt to edit the code before the module has been loaded, you'll get this error:

Edit and Continue - assembly not loaded

And if you try to edit the code before a breakpoint has hit, you'll get this altogether more obscure error:

Edit and Continue - breakpoint not hit

This message wasn't very helpful - at least not to me. My code wasn't running, as such (although I agree that someone's code was :-) and the setting mentioned was set correctly. Anyway - breaking into your code allows you to then edit the code, which should be obvious by a message on the application status-bar that tells you when the "continue" piece is successful:

Edit and Continue - code changes applied

I'd be curious to hear about others opinions of Edit and Continue: does it meet your debugging needs, or do you still see NETUNLOAD as important functionality? (There are clearly still areas - unrelated to debugging - where it might be useful to unload .NET assemblies. To be clear, I'd be happy to receive input on those areas, also.)


TrackBack URL for this entry:

Listed below are links to weblogs that reference Tired of not being able to NETUNLOAD from AutoCAD? "Edit and Continue" to the rescue!:

blog comments powered by Disqus


10 Random Posts