AutoCAD 2010/2011/2012

AutoCAD 2010/2011/2012

Reply
Active Contributor
M_Mogharabi
Posts: 26
Registered: ‎12-12-2011
Message 1 of 5 (350 Views)
Accepted Solution

Error : typeInitializationException

350 Views, 4 Replies
01-06-2012 09:05 PM

Hi all,
 
I've found a code to open a dwg file in autocad with objectARX commands.this code works successfully when i wrote it in a Class Library project, but the problem is happened when i want to place this code in my windows application.It gives me this error message :

 

The type initializer for '< Module >' threw an exception.
 
Inner Exception : The C++ module failed to load during process initialization.

 

My code is :

 

String MyDWGFilePath = @"\\Server\SharedFolder\Projects\File1.dwg";
DocumentCollection dm = Application.DocumentManager;
Document doc = null;
 
if(File.Exists(MyDWGFilePath))
{
   doc = dm.Open(MyDWGFilePath, false);
   Application.DocumentManager.MdiActiveDocument = doc;
}

 Note: I've add acdbmgd.dll and acmgd.dll from autocad installed folder and also AutoCAD and AXDBLib from COM references.

 

please tell me what is my mistake???

Hi,

 

>> Do you mean ObjectARX just works in DLLs but not in exe applications?

ObjectARX works only within AutoCAD, plus ObjectARX is written in C++ so it's unmanged and it's not a DLL, it's a special kind of DLL with the extension ARX

If you do your coding with C# or VB.NET (or any dotNET based language) then you are using the managed API from AutoCAD and also this (DLL then) runs only inside of AutoCAD (either loaded with command _NETLOAD or some settings in the registry to get loaded autmatically).

 

If you control AutoCAD from an external EXE you can only use the COM/ActiveX way and that works in the same way as you control Excel, Word or any other COM-based API.

 

You can start it with

CreateObject("AutoCAD.Application")    'or also using the version-number if you have to start a specific release

or you can use the Processes to start another EXE like:

Processes.Start("ACAD.EXE")   'of course you will use the path to the exe here

and then GetObject(,"AutoCAD.Application")    'to get access to the AutoCAD ActiveX server

 

A lot of search samples could be found using Google with >>>CreateObject("AutoCAD.Application")<<<


HTH, - alfred -

 

*Expert Elite*
Alfred.NESWADBA
Posts: 9,415
Registered: ‎06-29-2007
Message 2 of 5 (347 Views)

Re: Error : typeInitializationException

01-06-2012 11:49 PM in reply to: M_Mogharabi

Hi,

 

>> when i want to place this code in my windows application

Do you mean that you develop an external EXE (and not an internal DLL)? If so you have no access to the managed API (it's near to ObjectARX, but it's not ARX). The only option then is to work with COM.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Contributor
M_Mogharabi
Posts: 26
Registered: ‎12-12-2011
Message 3 of 5 (346 Views)

Re: Error : typeInitializationException

01-07-2012 12:40 AM in reply to: Alfred.NESWADBA

Hi alfred,

 

Do you mean ObjectARX just works in DLLs but not in exe applications?

So how can i open a dwg file from a windows application?

please describe for me how can i use COM instead of ARX?

 

i'm too confused.please help me...

*Expert Elite*
Alfred.NESWADBA
Posts: 9,415
Registered: ‎06-29-2007
Message 4 of 5 (343 Views)

Re: Error : typeInitializationException

01-07-2012 12:57 AM in reply to: M_Mogharabi

Hi,

 

>> Do you mean ObjectARX just works in DLLs but not in exe applications?

ObjectARX works only within AutoCAD, plus ObjectARX is written in C++ so it's unmanged and it's not a DLL, it's a special kind of DLL with the extension ARX

If you do your coding with C# or VB.NET (or any dotNET based language) then you are using the managed API from AutoCAD and also this (DLL then) runs only inside of AutoCAD (either loaded with command _NETLOAD or some settings in the registry to get loaded autmatically).

 

If you control AutoCAD from an external EXE you can only use the COM/ActiveX way and that works in the same way as you control Excel, Word or any other COM-based API.

 

You can start it with

CreateObject("AutoCAD.Application")    'or also using the version-number if you have to start a specific release

or you can use the Processes to start another EXE like:

Processes.Start("ACAD.EXE")   'of course you will use the path to the exe here

and then GetObject(,"AutoCAD.Application")    'to get access to the AutoCAD ActiveX server

 

A lot of search samples could be found using Google with >>>CreateObject("AutoCAD.Application")<<<


HTH, - alfred -

 

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Active Contributor
M_Mogharabi
Posts: 26
Registered: ‎12-12-2011
Message 5 of 5 (329 Views)

Re: Error : typeInitializationException

01-08-2012 09:09 PM in reply to: Alfred.NESWADBA

ahaa, now i can understand it clearly.

 

Thanks alot .........

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!