TheSwamp
Code Red => .NET => Topic started by: Matt__W on August 11, 2011, 04:25:25 PM
-
I've finally made the leap to .NET (God help me!!) and lo and behold, the sample from Autodesk doesn't work. I've done some quick Googling and a lot of the results suggested changing the .NET Framework. Well, I did that (tried 2-4) and no dice. Here's the Greek that is spit out when I try to NETLOAD my DLL.
Command: netload
Cannot load assembly. Error details: System.BadImageFormatException: Could not
load file or assembly 'file:///E:\Work\DOT
NET\Samples\0-HelloWorld\HelloWorld\bin\Release\HelloWorld.dll' or one of its
dependencies. This assembly is built by a runtime newer than the currently
loaded runtime and cannot be loaded.
File name: 'file:///E:\Work\DOT
NET\Samples\0-HelloWorld\HelloWorld\bin\Release\HelloWorld.dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase,
Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark,
Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef,
Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
at loadmgd()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure
logging.
To turn this feature off, remove the registry value
[HKLM\Software\Microsoft\Fusion!EnableLog].
-
Is the .dll on a Netwok?
-
Is the .dll on a Netwok?
Negatory!
-
Sorry reading the exception what version of Acad do you have installed or do you know what version of .NET is installed?
-
Is the .dll on a Netwok?
Interesting... I've heard of some having issues with that, and just tried it. I copied a DLL to the network (where I have write access), and did a NETLOAD. The DLL came in fine, and the CommandMethods worked... for the first few. Then It crashed my ACAD. LoL
The DLL is compiled using framework 3.5, and I've been testing with 2011 (via Debug), but the test mentioned above was done with 2009 (also .NET 3.5).
What I specifically found interesting, that I was previously unaware of, was in above mentioned DLL I have a simple .NET toggle of MBUTTONPAN SysVar CommandMethod that does the same as a LISP Defun that I use. Anyway, after testing the .NET version and it working, I reloaded my LISP, and the .NET version was not redefined as the LISP Defun as I was expecting.
Is there a way around this? I want to make my code available to others, and not mico-manage other's code function naming. I'd be pretty pissed if I wanted to use <AnyName> and could not as a result of some A-Holes NETLOAD. Avoiding this issue would be highly advantageous.
-
Sorry reading the exception what version of Acad do you have installed or do you know what version of .NET is installed?
AutoCAD 2008 & 2011
.NET 4
I'm trying to compile/load for 2011.
-
You should be compiling for .NET 3.5 (for 2011), .NET 2.0 (for 2008), and be sure that AcMgd.dll, AcDbMgd.dll are added as references, with Copy Local = False.
Separately, not sure where you copied+pasted your HelloWorld tutorial, but I know this works with the above conditions in 2011:
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Imports System
Imports System.Runtime
Imports System.Drawing
Public Class Commands
<CommandMethod("HelloWorld")> _
Public Sub HelloWorld()
Dim ed = Application.DocumentManager.MdiActiveDocument.Editor
ed.WriteMessage("vbLf & Hello World! ")
End Sub
End Class
Edit: ** Extra Imports calls as this was snipped from larger Commands.vb Class.
Edit: Clarified compile framework
-
Compile with .NET 2.0~3.5 or modify acad.exe.config
http://www.theswamp.org/index.php?topic=33495.msg388758#msg388758
-
You should be compiling for .NET 3.5, and be sure that AcMgd.dll, AcDbMgd.dll are added as references, with Copy Local = False.
Separately, not sure where you copied+pasted your HelloWorld tutorial, but I know this works with the above conditions in 2011:
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry
Imports Autodesk.AutoCAD.Runtime
Imports System
Imports System.Runtime
Imports System.Drawing
[/quote]
I was using a sample (possibly an old one). Your code works fine with .NET 3.5. I also noticed that your code (compared to the sample) has more Imports.
This is gonna be a long and bumpy road. :)
-
As Jgr posted, I too needed to modify acad.exe.config in order for my VS 2010 Express to stop at breakpoints during debug.
Pics of where to set .NET framework attached (compiling for 3.5 shown, set as needed).
-
Damnit, Mav!! What are YOU doing here??!? ;)
-
I was using a sample (possibly an old one). Your code works fine with .NET 3.5. I also noticed that your code (compared to the sample) has more Imports.
This is gonna be a long and bumpy road. :)
Yeah, I added an edit comment to my earlier post... I just snipped the 'HelloWorld' CommandMethod from a larger list of CommandMethods. The extra Imports are necessary for things like prompting for user input, points specification, application window modification, etc..
-
You can also open the acad.exe.config file and edit
@Matt for 4.0 in 2011-----supportedRuntime version="v4.0"
@RenderMan for loading from Network------loadFromRemoteSources enabled="true"
-
Welcome to the Dark Side. Like Sith training, you will be beaten unmercifully at the start. If you survive that then you will gain tremendous power in a short period of time. With frequent use you will end up bald, shrivelled, and quite, quite insane. Eventually somebody younger and with a better understanding of the .NET Force will toss you over the railing and take over.
-
I know we're in the .NET forum, but I often have AutoCAD open when developing .NET, thought some of you might be able to use this too:
(defun c:NETVER ()
(textpage)
(prompt (strcat "\nAutoCAD .NET Framework by version: \n"
"\n\t\t2012 \tNET 4.0 "
"\n\t\t2011 \tNET 3.5 "
"\n\t\t2010 \tNET 3.5 "
"\n\t\t2009 \tNET 3.0 "
"\n\t\t2008 \tNET 2.0 "))
(terpri)
(princ))
-
Welcome to the Dark Side. Like Sith training, you will be beaten unmercifully at the start. If you survive that then you will gain tremendous power in a short period of time. With frequent use you will end up bald, shrivelled, and quite, quite insane. Eventually somebody younger and with a better understanding of the .NET Force will toss you over the railing and take over.
LoL! Hopefully we who CAN one day overthrow, can also collect your six figure sallaries!
(http://www.site-fusion.co.uk/files/writeable/uploads/webfusion16441/image/darth-vader-reading-harry-potter-and-the-deathly-hallows.jpg)
-
Welcome to the Dark Side. Like Sith training, you will be beaten unmercifully at the start. If you survive that then you will gain tremendous power in a short period of time. With frequent use you will end up bald, shrivelled, and quite, quite insane. Eventually somebody younger and with a better understanding of the .NET Force will toss you over the railing and take over.
That was AWESOME! and very descriptive of my journey
-
I'm about half way through this, http://download.autodesk.com/media/adn/DevTV_VBA_Migration/english/DevTV_VBA_To_VBdotNet_Migration_English.html, and he makes a reference to creating a new project in VB6 from the modules/forms exported from AutoCAD VBA. Is VB6 necessary (since I don't have access to it) or is there another automated way? I'm probably jumping the gun since I haven't made it all the way through yet... just wanted to ask.
-
Nevermind!!! :)
-
I'm about half way through this, http://download.autodesk.com/media/adn/DevTV_VBA_Migration/english/DevTV_VBA_To_VBdotNet_Migration_English.html, and he makes a reference to creating a new project in VB6 from the modules/forms exported from AutoCAD VBA. Is VB6 necessary (since I don't have access to it) or is there another automated way? I'm probably jumping the gun since I haven't made it all the way through yet... just wanted to ask.
BTW - Glad to see that you're finding that link helpful. :wink:
-
I'm about half way through this, http://download.autodesk.com/media/adn/DevTV_VBA_Migration/english/DevTV_VBA_To_VBdotNet_Migration_English.html, and he makes a reference to creating a new project in VB6 from the modules/forms exported from AutoCAD VBA. Is VB6 necessary (since I don't have access to it) or is there another automated way? I'm probably jumping the gun since I haven't made it all the way through yet... just wanted to ask.
BTW - Glad to see that you're finding that link helpful. :wink:
Alright... so I'm finally, FINALLY getting back to looking at this and wouldn't you know it, the macro converter is part of VS2008 and not VS2010 (which I have installed). So that's problem #1. The second (possible) problem is/might be, if I modify the acad.exe.config file (wherever the hell that is located) does this mean that I would have to modify everyone's file? Because that simply isn't an option.
-
Alright... so I'm finally, FINALLY getting back to looking at this and wouldn't you know it, the macro converter is part of VS2008 and not VS2010 (which I have installed). So that's problem #1.
How many?
I still have VS2008 Pro installed or maybe I could decipher a couple and code it VB.NET
The second (possible) problem is/might be, if I modify the acad.exe.config file (wherever the hell that is located) does this mean that I would have to modify everyone's file? Because that simply isn't an option.
Depending on what you are changing it for and what versions but basic answer would be yes you need to update all of them.
A config file is located where the .exe is, so same folder as acad.exe
-
The second (possible) problem is/might be, if I modify the acad.exe.config file (wherever the hell that is located) does this mean that I would have to modify everyone's file? Because that simply isn't an option.
Depending on what you are changing it for and what versions but basic answer would be yes you need to update all of them.
A config file is located where the .exe is, so same folder as acad.exe
Jeff is correct, I simply copied acad.exe.config and renamed the copy acad.exe.config.void, which keeps my backup near the original in Explorer, and changes the file type to 'VOID File' :wink:
This is very easy to automate into a BAT, or even LSP - let me know if you need more info, code, etc..
-
I added the remote piece and it doesnt work, do I have to adjust anything else?
<configuration>
<!--
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
</startup>
-->
<!--All assemblies in AutoCAD are fully trusted so there's no point generating publisher evidence-->
<runtime>
<generatePublisherEvidence enabled="false"/>
<loadFromRemoteSources enabled="true"/>
</runtime>
</configuration>
-
Are you usiing AutoCAD 2012?
Configuration item <loadFromRemoteSources.../> is introduced by .NET 4. It only takes effect when the application (AutoCAD) uses .NET 4.
If you use Acad2011 or earlier, unless you force AutoCAD 2011/2010 to use .NET4 (i.e. with <supportRuntime version="v4.0" /> added to acad..exe.config), <loadFrom RemoteSources... /> will be useless.