Exceptions while programmatically launching AutoCad2019 on Windows 10 (2024)

.NET

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Showonly | Search instead for

Did you mean:

Exceptions while programmatically launching AutoCad2019 on Windows 10

16 REPLIES 16

Back to AutoCAD Customization Category

Back to Topic Listing

Reply

Topic Options

  • Subscribe to RSS Feed
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Printer Friendly Page
  • Back to Topic Listing
  • Previous
  • Next

Message 1 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (1)

Anonymous

1983 Views, 16 Replies

‎09-07-201802:24 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎09-07-201802:24 AM

Exceptions while programmatically launching AutoCad2019 on Windows 10

When I try to launch the AutoCAD 2019 through console program in Windows 10 through the following codes,

AutoCAD 2019 is failed to start up and reports with the following exceptions.

(.NetFramework : 4.7)

I tried to useacax23enu.tlb andAutodesk.AutoCAD.Interop.dll,

but still, throw the same exception.

Can anyone help me to solve this problem?

Many Thanks.

Code:

try
{ Type acType = Type.GetTypeFromProgID("AutoCAD.Application.23"); acApp = (AcadApplication)Activator.CreateInstance(acType, true);}catch (Exception ex){
// Exception Handling}

Exception Message:

Retrieving the COM class factory for component with CLSID {4AC6DFE1-607B-45B2-B289-D7FBCD44169C} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

Tags (2)

  • Tags:
  • AutoCAD 2019
  • Windows 10

Report

0Likes

Reply

  • Back to Topic Listing
  • Previous
  • Next

16 REPLIES 16

Message 2 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (2)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (3)FRFR1426

in reply to:Anonymous

‎09-07-201804:53 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎09-07-201804:53 AM

The AcadApplication GUID is the right one for AutoCAD 2019.

There is an interesting article on this error here:https://blogs.msdn.microsoft.com/adioltean/2005/06/24/when-cocreateinstance-returns-0x80080005-co_e_...

I think you have a problem in your AutoCAD installation. A repair or a reinstall can help.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Report

0Likes

Reply

Message 3 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (4)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (5)FRFR1426

in reply to:Anonymous

‎09-07-201805:00 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎09-07-201805:00 AM

Also, read this post:https://forums.autodesk.com/t5/net/error-while-programmatically-launching-autocad/td-p/5555190

Maybe it's linked to the user account running your console program.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Report

0Likes

Reply

Message 4 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (6)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (7)Jens.Bruhn

in reply to:FRFR1426

‎01-31-201904:41 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎01-31-201904:41 AM

I have exactly the same problem when I switched my application from Acad2018 to Acad2019.
The problem occurs on Win10 and Win7 systems so I think it's independent from the OS.
Are there any other ideas so solve the issue?

Kind regards,

Jens

Report

0Likes

Reply

Message 5 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (8)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (9)FRFR1426

in reply to:Jens.Bruhn

‎02-01-201912:15 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-01-201912:15 AM

If your program run as administrator, try to run it with a standard account.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Report

0Likes

Reply

Message 6 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (10)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (11)Jens.Bruhn

in reply to:FRFR1426

‎02-01-201904:36 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-01-201904:36 AM

the problem is independent from user rights, the problem occurs as administrator and with standard user rights.

Regards,

Jens

Report

0Likes

Reply

Message 7 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (12)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (13)FRFR1426

in reply to:Jens.Bruhn

‎02-01-201909:07 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-01-201909:07 AM

If you can, try on another computer to check if it is due to a bad configuration on your local machine.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Report

0Likes

Reply

Message 8 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (14)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (15)norman.yuan

in reply to:Jens.Bruhn

‎02-02-201906:11 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-02-201906:11 AM

Just did a quick verification with one of my computers: Windows 10 Pro, Vanilla AutoCAD 2019. Following simple console app starts AutoCAD successfully:

using System;using Autodesk.AutoCAD.Interop;namespace AutomateAcad2019{ class Program { static void Main(string[] args) { Console.WriteLine("Press R to run AutoCAD, any other key to exit:"); var an = Console.ReadLine(); if (an.ToUpper().StartsWith("R")) { RunAutoCAD(); Console.WriteLine("Press any key to exit:"); Console.ReadLine(); } } private static void RunAutoCAD() { AcadApplication acApp = null; try { Type acType = Type.GetTypeFromProgID("AutoCAD.Application.23"); acApp = (AcadApplication)Activator.CreateInstance(acType, true); acApp.Visible = true; Console.WriteLine("AutoCAD started!"); } catch (Exception ex) { Console.WriteLine("Error" + ex.Message); } } }}

Since the console app is a desktop app, it runs with my login user account, which is local admin. I'd assume if I use a standard user account that was able to run AutoCAD with this computer, the console would also work OK.

So, the problem would not be with the code, rather, the condition under which the EXE app and/or AutoCAD is to run, which, you (and the OP) did not describe at all.

Report

0Likes

Reply

Message 9 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (18)Jens.Bruhn

in reply to:norman.yuan

‎02-06-201902:28 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-06-201902:28 AM

Hi Norman,

thank you for the sample code.

With this console app everything works fine.
When I use the same code inside my own application (Autodesk Vault JobProcessor - custom job) I figured out that the line
(AcadApplication)Activator.CreateInstance(acType, true);

starts a non visible DWG TrueView process (dwgviewr.exe) !??

Maybe something is wrong with my Acad2019 Installation, but it's strange, that exactly the same issue occurs on a completely different system.

Kind regards,

Jens

Report

0Likes

Reply

Message 10 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (19)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (20)FRFR1426

in reply to:Jens.Bruhn

‎02-06-201905:07 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-06-201905:07 AM

Ah OK. This is why the context is important. A custom job for the Vault job processor is executing in a MTA thread (instead of a standard STA thread). This can explain why your call toCreateInstance() is failing.

You can try to replace yourCreateInstance() with a Process.Start() followed by a loop callingMarshal.GetActiveObject(). When AutoCAD will be started,Marshal.GetActiveObject() will return successfully.

In order to use Process.Start(), you need to have the path of acad.exe. You can find it in the registry.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Report

0Likes

Reply

Message 11 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (21)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (22)Jens.Bruhn

in reply to:FRFR1426

‎02-06-201911:33 PM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-06-201911:33 PM

With Process.Start() the AutoCAD start works - thank you!
So I have to change the communication with Acad to open a dwg and do some things.

I can't use acApp.Documents.Open and SendCommand(...) any more, I think I have to load a script with Process.Start().

Some work to rebuild the program and I'm still wondering what has changed from Rel. 2018 (Acad+Vault) to Rel.2019.

Kind regards and thanx for your help,

Jens

Report

0Likes

Reply

Message 12 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (23)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (24)FRFR1426

in reply to:Jens.Bruhn

‎02-07-201901:06 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-07-201901:06 AM

You can, just get the COM server with Marshall.GetActiveObject() (code not tested):

Process process = Process.Start(acadExePath);if (process == null) throw new ApplicationException("AutoCAD can not start.");if (!process.WaitForInputIdle(60 * 1000)) throw new ApplicationException("The AutoCAD process has not finished its initialization in the specified timeout.");AcadApplication acadApp = null;for (int i = 0; i < 60; ++i){
const uint MK_E_UNAVAILABLE = 0x800401e3; try { acadApp = Marshal.GetActiveObject("AutoCAD.Application"); break; } catch (COMException ex) when ((uint) ex.ErrorCode == MK_E_UNAVAILABLE) { Thread.Sleep(1000); }}// You can use acadApp here

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Report

0Likes

Reply

Message 13 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (25)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (26)Jens.Bruhn

in reply to:FRFR1426

‎02-07-201904:23 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-07-201904:23 AM

Unforunately the line

acadApp = Marshal.GetActiveObject("AutoCAD.Application");

results in an type conversion error?

Report

0Likes

Reply

Message 14 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (27)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (28)FRFR1426

in reply to:Jens.Bruhn

‎02-07-201904:46 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-07-201904:46 AM

Use "AutoCAD.Application.23" as ProgID to be sure that you're getting the 2019 version.

Maxence DELANNOY
Manager
Add-ins development for Autodesk software products
http://wiip.fr

Report

0Likes

Reply

Message 15 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (29)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (30)Jens.Bruhn

in reply to:FRFR1426

‎02-07-201907:44 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-07-201907:44 AM

hmm, it's another problem.
The line

acadApp = Marshal.GetActiveObject("AutoCAD.Application.23");

doesn't get compiled because of a type mismatch.

Report

0Likes

Reply

Message 16 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (31)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (32)norman.yuan

in reply to:Jens.Bruhn

‎02-07-201911:58 AM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-07-201911:58 AM

C# is strong-typed language. In your code, acadApp is declared as type of "AcadApplication", while Marshal.GetActiveObject() return's type of "object". So, you need to cast the returned object:

// This may raise exception, if the object returned is not AcadApplication

acadApp=(AcadApplication)Marshal.GetActiveObject(...);

or you can

acadApp=Marshal.GetActiveObject(....) as AcadApplication;

if (acadApp!=null)

{

// your are ok to continue...

}

else

{

// Cannot get AcadApplication object...

}

Report

0Likes

Reply

Message 17 of 17

Exceptions while programmatically launching AutoCad2019 on Windows 10 (34)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (35)Jens.Bruhn

in reply to:norman.yuan

‎02-07-201911:53 PM

  • Mark as New
  • Bookmark
  • Subscribe
  • Mute
  • Subscribe to RSS Feed
  • Permalink
  • Print
  • Report

‎02-07-201911:53 PM

OK, thanks for your help.

When I cast the returned object the application gets compiled.

But the result is still the same:
When I run the code from a console app everything works fine.

When I run the code from my Vault job processor extension I can't communicate with AutoCAD

-> Marshal.GetActiveObject(progID) as AutoCAD.AcadApplication; returns nullExceptions while programmatically launching AutoCad2019 on Windows 10 (36)

Report

0Likes

Reply

Exceptions while programmatically launching AutoCad2019 on Windows 10 (37)

Exceptions while programmatically launching AutoCad2019 on Windows 10 (38)

Reply

Topic Options

  • Subscribe to RSS Feed
  • Mark Topic as New
  • Mark Topic as Read
  • Float this Topic for Current User
  • Bookmark
  • Subscribe
  • Printer Friendly Page
  • Back to Topic Listing
  • Previous
  • Next
Exceptions while programmatically launching AutoCad2019 on Windows 10 (2024)
Top Articles
Latest Posts
Article information

Author: Terence Hammes MD

Last Updated:

Views: 5763

Rating: 4.9 / 5 (69 voted)

Reviews: 92% of readers found this page helpful

Author information

Name: Terence Hammes MD

Birthday: 1992-04-11

Address: Suite 408 9446 Mercy Mews, West Roxie, CT 04904

Phone: +50312511349175

Job: Product Consulting Liaison

Hobby: Jogging, Motor sports, Nordic skating, Jigsaw puzzles, Bird watching, Nordic skating, Sculpting

Introduction: My name is Terence Hammes MD, I am a inexpensive, energetic, jolly, faithful, cheerful, proud, rich person who loves writing and wants to share my knowledge and understanding with you.