AutoCAD 2010/2011/2012

AutoCAD 2010/2011/2012

Reply
Active Contributor
26 Posts
0 Kudos
Registered: ‎12-12-2011
Post 1 of 5
Accepted Solution

Error : typeInitializationException

365 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*
9,832 Posts
1,218 Kudos
Registered: ‎06-29-2007
Post 2 of 5

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
26 Posts
0 Kudos
Registered: ‎12-12-2011
Post 3 of 5

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*
9,832 Posts
1,218 Kudos
Registered: ‎06-29-2007
Post 4 of 5

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
26 Posts
0 Kudos
Registered: ‎12-12-2011
Post 5 of 5

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 interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!