Author Topic: My first shot at .NET (shot down)  (Read 8387 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."

BlackBox

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

LoL! Hopefully we who CAN one day overthrow, can also collect your six figure sallaries!

"How we think determines what we do, and what we do determines what we get."

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: My first shot at .NET (shot down)
« Reply #16 on: August 13, 2011, 08:32:29 AM »
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
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

Matt__W

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

Matt__W

  • Seagull
  • Posts: 12955
  • I like my water diluted.
Re: My first shot at .NET (shot down)
« Reply #18 on: August 15, 2011, 10:28:37 AM »
Nevermind!!!  :)
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 #19 on: August 17, 2011, 05:14:09 PM »
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:
"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 #20 on: September 20, 2011, 08:57:46 AM »
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.
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 #21 on: September 20, 2011, 09:48:17 AM »
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
 

BlackBox

  • King Gator
  • Posts: 3770
Re: My first shot at .NET (shot down)
« Reply #22 on: September 20, 2011, 10:26:28 AM »
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..
"How we think determines what we do, and what we do determines what we get."

David Hall

  • Automatic Duh Generator
  • King Gator
  • Posts: 4075
Re: My first shot at .NET (shot down)
« Reply #23 on: October 04, 2011, 03:36:17 PM »
I added the remote piece and it doesnt work, do I have to adjust anything else?
Code: [Select]
<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>
Everyone has a photographic memory, Some just don't have film.
They say money can't buy happiness, but it can buy Bacon and that's a close second.
Sometimes the question is more important than the answer. (Thanks Kerry for reminding me)

n.yuan

  • Bull Frog
  • Posts: 348
Re: My first shot at .NET (shot down)
« Reply #24 on: October 05, 2011, 11:05:26 AM »
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.