Author Topic: My first shot at .NET (shot down)  (Read 8388 times)

0 Members and 1 Guest are viewing this topic.

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
My first shot at .NET (shot down)
« 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.

Quote from: AutoCAD Command Line
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].
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Jeff H

  • Needs a day job
  • Posts: 6150
Re: My first shot at .NET (shot down)
« Reply #1 on: August 11, 2011, 04:26:19 PM »
Is the .dll on a Netwok?

« Last Edit: August 11, 2011, 04:33:02 PM by Jeff H »

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: My first shot at .NET (shot down)
« Reply #2 on: August 11, 2011, 04:32:01 PM »
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

Jeff H

  • Needs a day job
  • Posts: 6150
Re: My first shot at .NET (shot down)
« Reply #3 on: August 11, 2011, 04:33:08 PM »
Sorry reading the exception what version of Acad do you have installed or do you know what version of .NET is installed?

BlackBox

  • King Gator
  • Posts: 3770
Re: My first shot at .NET (shot down)
« Reply #4 on: August 11, 2011, 04:37:27 PM »
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.
"How we think determines what we do, and what we do determines what we get."

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: My first shot at .NET (shot down)
« Reply #5 on: August 11, 2011, 04:37:58 PM »
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.
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

BlackBox

  • King Gator
  • Posts: 3770
Re: My first shot at .NET (shot down)
« Reply #6 on: August 11, 2011, 04:41:10 PM »
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:

Code: [Select]
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
« Last Edit: August 11, 2011, 04:55:21 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

jgr

  • Guest
Re: My first shot at .NET (shot down)
« Reply #7 on: August 11, 2011, 04:43:47 PM »
Compile with .NET 2.0~3.5 or modify acad.exe.config
http://www.theswamp.org/index.php?topic=33495.msg388758#msg388758

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: My first shot at .NET (shot down)
« Reply #8 on: August 11, 2011, 04:47:46 PM »
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:

Code: [Select]
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.  :)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

BlackBox

  • King Gator
  • Posts: 3770
Re: My first shot at .NET (shot down)
« Reply #9 on: August 11, 2011, 04:48:09 PM »
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).
« Last Edit: August 11, 2011, 04:56:07 PM by RenderMan »
"How we think determines what we do, and what we do determines what we get."

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: My first shot at .NET (shot down)
« Reply #10 on: August 11, 2011, 04:48:50 PM »
Damnit, Mav!!  What are YOU doing here??!?  ;)
Autodesk Expert Elite
Revit Subject Matter Expert (SME)
Owner/FAA sUAS Pilot @ http://skyviz.io

BlackBox

  • King Gator
  • Posts: 3770
Re: My first shot at .NET (shot down)
« Reply #11 on: August 11, 2011, 04:51:05 PM »
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..
"How we think determines what we do, and what we do determines what we get."

Jeff H

  • Needs a day job
  • Posts: 6150
Re: My first shot at .NET (shot down)
« Reply #12 on: August 11, 2011, 05:02:42 PM »
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"

 
 

dgorsman

  • Water Moccasin
  • Posts: 2437
Re: My first shot at .NET (shot down)
« Reply #13 on: August 11, 2011, 05:09:06 PM »
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.
If you are going to fly by the seat of your pants, expect friction burns.

try {GreatPower;}
   catch (notResponsible)
      {NextTime(PlanAhead);}
   finally
      {MasterBasics;}

BlackBox

  • King Gator
  • Posts: 3770
Re: My first shot at .NET (shot down)
« Reply #14 on: August 11, 2011, 05:09:31 PM »
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:

Code: [Select]
(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))
"How we think determines what we do, and what we do determines what we get."