I am trying to write a VB.Net program and I cant seem to reference AcSmComponents18Lib with the project set to Framework 3.5. The project template started out set to 4.0 but I set it to 3.5 before I referenced AcSmComponents18Lib in.
Even when I made a project template that started out set to Framework 3.5 I could not get AcSmComponents18Lib referenced in, It said it could not find the file even though I could find it through the COM tab just fine.
See attached for error message
Is there something I'm doing wrong or is there something wrong with AcSmComponents18Lib in 2010?
(BTW im using VBE 2010, Win 7 and 64-bit)
I have had the dreaded BadImageFormatException a couple of times now. If you do a web search you will find a lot of different explanations for it (none of which have ever solved the problem for me), most of them are about trying to reference a 32 bit assembly into a 64 bit assembly. It sounds as though that might be what's going on?
the other part of your error message says that acsmcomponents was built by a runtime newer than the currently loaded runtime... Have you tried targeting .NET 4.0?
It works fine when I target 4.0 but when I try to debug/run it in MEP it throws all kinds of errors about it being the wrong framework so I'm assuming, perhaps wrongly, that AutoCAD can only use 3.5?
Is there a 64-bit version of AcSmComponents18Lib? I only see one listed in the COM tab and only one when I browse C:\Program Files\Common Files\Autodesk Shared
Please correct me if I am wrong on this, I'm still new to .Net and have a lot to learn.
I Googled "BadImageFormatException" and an MSDN article said this...
A DLL or executable is loaded as a 64-bit assembly, but it contains 32-bit features or resources. For example, it relies on COM interop or calls methods in a 32-bit dynamic link library.
To address this exception, set the project's Platform target property to x86 (instead of x64 or AnyCPU) and recompile.
A number of other Google hits mentioned the "Platform Target" also but I can not find where to set this in VBExpress 2010, any idea where this is?
NM, found it.
Its a menu thats not shown by default
To target x86 in the express editions:
Tools --> Options --> Projects and Solutions-->General Check "Show advanced build configurations"
If "Configuration Manager" doesn't show on the Buid menu, add it and click it.
Active Solution Platform --> New --> Type or select the new platform x86
Geez! I keep replying to myself.
I think I found a solution and possibly the problem. I went back to VBExpress 2008 and, lo and behold, no problem building the project to Framework 3.5 with AcSmComponents18.
So the problem might be more to do with VBE2010 than anything else.