CLR detected invalid Program

CLR detected invalid Program

Anonymous
Not applicable
2,803 Views
10 Replies
Message 1 of 11

CLR detected invalid Program

Anonymous
Not applicable

I am creating(new to auto CAD) a .net application for Auto CAD (.net 2017 Framework 4.7, Auto CAD 2017). I have downloaded "Autodesk_ObjectARX_2019_Win_64_and_32_Bit" and i am using in the application. I have imported the following dll's "using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.Runtime;"). I get the error "System.InvalidProgramException: CLR detected an Invalid Exception". I am trying to run the example project "http://adndevblog.typepad.com/autocad/2012/05/insert-block-from-a-different-dwg-using-net-.html". 

I am basically trying to copy files from different .dwg to new .dwg where we can list all the block in the drop down from existing and on selection i can add into the new one.

0 Likes
2,804 Views
10 Replies
Replies (10)
Message 2 of 11

_gile
Consultant
Consultant

Hi,

 

If you are targeting AutoCAD 2017, you should reference the 2017 version of ObjectARX libraries.

You can have a look at >>this table<< to see compatibilites between AutoCAD, Visual studio and .NET Framework



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 11

Anonymous
Not applicable

Thank you for the table i had seen this table but was able to get the link for 2019. Can you provide me the link for 2017.

http://download.autodesk.com/esd/objectarx/2019/Autodesk_ObjectARX_2019_Win_64_and_32_Bit.sfx.exe (Same like this)

Thanks 

Saravanan.R

0 Likes
Message 4 of 11

Anonymous
Not applicable

Can any one give a link for downloading "ObjectARX SDK 2017"

0 Likes
Message 5 of 11

_gile
Consultant
Consultant
0 Likes
Message 6 of 11

Anonymous
Not applicable

Thank you. I already got the link from same place but why do we have to give all personal information? Hope its not circulated to others. 

"I agree to the use of my personal information as described in the Autodesk Privacy Statement."

 

I will try the new ARX 2017. Will this solve my issue of "System.InvalidProgramException: CLR detected an Invalid Exception"

0 Likes
Message 7 of 11

Anonymous
Not applicable

I have installed ARX2017 and referenced the DLL. I get this error "System.IO.FileNotFoundException: 'Could not load file or assembly 'accoremgd, Version=21.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.'"

I am doing a windows form and calling the method in class.

Class file:

[CommandMethod("InsertBlock")]
public void InsertBlk() // This method can have any name
{
Document doc = Application.DocumentManager.MdiActiveDocument;
using (Database OpenDb = new Database(false, true))
{
OpenDb.ReadDwgFile(@"C:\CAD-Reference\INTERNALGA.dwg", System.IO.FileShare.ReadWrite, true, "");
ObjectIdCollection ids = new ObjectIdCollection();

using (Transaction tr = OpenDb.TransactionManager.StartTransaction())
{
//For example, Get the block by name "TEST"
BlockTable bt;
bt = (BlockTable)tr.GetObject(OpenDb.BlockTableId, OpenMode.ForRead);

if (bt.Has("DM_24V_20A_021"))
{
ids.Add(bt["DM_24V_20A_021"]);
}
tr.Commit();
}

//if found, add the block
if (ids.Count != 0)
{
//get the current drawing database
Database destdb = doc.Database;
IdMapping iMap = new IdMapping();
destdb.WblockCloneObjects(ids, destdb.BlockTableId, iMap, DuplicateRecordCloning.Ignore, false);
}
}
}

Forms code:

private void btnInsert_Click(object sender, EventArgs e)
{
//PF.CreateAutoCADObject();
First_Test.PublicStaticClass.ImportExisting FPS = new PublicStaticClass.ImportExisting();

FPS.InsertBlk();
}

 

In some post I saw that the code cannot be executed from forms it has to be imported into auto CAD through NETLOAD and then give the CommandMethod. is it correct?

If I want to debug the code and check how do i do it?

0 Likes
Message 8 of 11

_gile
Consultant
Consultant

To be able to use the AutoCAD NET API, you have to build a class library project which generates a DLL that can be NETLOADed from AutoCAD.

You can start from here:

http://help.autodesk.com/view/OARX/2018/FRA/?guid=GUID-BA686431-C8BF-49F2-946E-9CEB2F7AE4FA



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 11

norman.yuan
Mentor
Mentor

Adding to what Gilles has said...

 

What you said "In some post I saw that the code cannot be executed from forms..." is not very clear: the .AutoCAD .NET API can or cannot be executed, is not because of "from form" or not; it is because of being executed within the AutoCAD process or not. So, by saying "from form", if you mean being executed in a stand-alone EXE process (be it Win Form EXE, or console exe, or a service EXE...) then, yes, you cannot use AutoCAD .NET API directly. I'd bet this is the reason you got your error when you tried to run your code, which is an EXE app.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 10 of 11

Anonymous
Not applicable

Thank you for the response.

As per the above I understood from other post that it can be run through the dll only.

I would like to have a application where there is a user form (Windows form) takes input from user like:

* fetch a specific block from a .dwg and place in new .dwg in specific location.

* I told specific location as number of items may be placed in different location.

* In short from the BOM(Bill of material) need find object and place in new .dwg in specific location.

* I would like to debug the code when executing.

 

Regards,

Saravanan.R

0 Likes
Message 11 of 11

_gile
Consultant
Consultant

You can use modal or modeless dialog boxes from your DLL to get user inputs.

To display the forms from an AutoCAD plugin, use the Application.ShowModalDialog() and Application.ShowModelessDialog() methods.

You can find examples in @norman.yuan's blog as this one.

If you can read French, I also try to write a 'tutorial' about AutoCAD user interfaces >>here<<.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes