COM Interop and AutoCAD 2025

COM Interop and AutoCAD 2025

s3b79
Participant Participant
2,693 Views
12 Replies
Message 1 of 13

COM Interop and AutoCAD 2025

s3b79
Participant
Participant

Hello,

 

I've just started a new job and my first task is to migrate an AutoCAD application written in .Net Framework / VB.NET to Autocad 2025 and therefore .Net 8.

 

This application is quite old and a large portion of the code still uses COM interop classes rather than managed classes. A line like

 

Dim blocTemps As New AcadBlockReference

 

works in .Net Framework but no longer works in .Net 8 : BC30517 Overload resolution failed because no 'New' is accessible.

 

Has anyone ever encountered this problem and could give me some advice on how to solve it?

 

Thanks in advance

0 Likes
Accepted solutions (1)
2,694 Views
12 Replies
Replies (12)
Message 2 of 13

_gile
Consultant
Consultant

Did you reference the AutoCAD 2025 libraries for AcDbMgd, AcCoremgd, AcMgd, Autodesk.AutoCAD.Interop, Autodesk.AutoCAD.Interop.Common, ... (version 25.0.58.0.0)?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 3 of 13

s3b79
Participant
Participant

Yes, I am using the NuGet packages AutoCAd.NET (25.0.1)
and AutoCAD.NET.Interop (2025.25.0.58).

 

Visual Studio does recognize AutoCAD types.

0 Likes
Message 4 of 13

_gile
Consultant
Consultant

You should provide more informations. For example, did you start a new project from scratch or upgrade an existing .NET Framework project with the .NET Upgrade Assistant? In the second case, you could read this topic.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 13

s3b79
Participant
Participant

I did use the .NET Upgrade Assistant extension to update my projects.

 

But your comment was interesting. I tried to make a new project in .Net 4.7 and .Net 8.


I used this time NuGet packages to reference the classic AutoCAD libraries and local references for the interop libraries (because AutoCAD.NET.Interop is not an official package).

 

s3b79_0-1725454356871.png

 

I read your doc but it didn't give me any clues, but thanks for that.

 

 

0 Likes
Message 6 of 13

_gile
Consultant
Consultant
Accepted solution

Sorry, I'm not familiar with VB specifics and I try to avoid using COM interop in .NET plugins, but the code you posted doesn't make sense to me (i.e. creating an AcadBlockReference with New). As far as I know, you can only create a new AcadBlock reference with the InsertBlock method.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 7 of 13

s3b79
Participant
Participant

I'm a C# guy too and I don't really like VB. but it's historical in the project where VBA code was migrated to VB.NET with interop.

 

I also wondered if it made sense to do a New. Maybe the New is useless because the reference is overwritten later and just declaring a variable of type AcadBlockReference without the new would be sufficient.

 

My project is big and I have many errors of this type to correct but I can try...

 

Thanks for your help.

0 Likes
Message 8 of 13

_gile
Consultant
Consultant

I had to do this kind of migration a dozen years ago and I'm glad that today projects are entirely converted to C# without any reference to COM interop.

All the best.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 9 of 13

ActivistInvestor
Mentor
Mentor

I would never write code that has a dependence on COM Interop. 

 

I have code that uses the COM API (e.g., AcadDocument), but does so via late-binding using System.Dynamic.

0 Likes
Message 10 of 13

Ed__Jobe
Mentor
Mentor

Do you start development by referencing COM.Interop, just to get Intelisense and then switch to late binding when you're done?

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 11 of 13

ActivistInvestor
Mentor
Mentor

@Ed__Jobe wrote:

Do you start development by referencing COM.Interop, just to get Intelisense and then switch to late binding when you're done?


No, I go from memory, and I don't really do use COM very much to begin with, so not having Intellisense isn't really an issue.

Message 12 of 13

Ed__Jobe
Mentor
Mentor

@ActivistInvestor wrote:

@Ed__Jobe wrote:

Do you start development by referencing COM.Interop, just to get Intelisense and then switch to late binding when you're done?


No, I go from memory, and I don't really do use COM very much to begin with, so not having Intellisense isn't really an issue.


Thx. My memory isn't as good. So I have a shortcut to the help file. 🙂 However, if @s3b79 isn't familiar with the COM api and needs Intellisense, they should know that they have the option to set a reference to AutoCAD.COM.Interop and remove it before they compile for Release.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 13 of 13

s3b79
Participant
Participant

As I said above, I have just taken over the maintenance of a project. This project uses interop classes (in addition to managed classes...). And it's not a choice, it's a fact.

 

I'm a developer and my knowledge of Autocad and its APi is very limited. @_gile's answer about the fact that the code I posted didn't make sense was very pertinent. I simply deleted the New and the code compiled.

 

I can't say that the migration to .Net 8 is complete, but this particular point seems to have been resolved.

 

Thanks to all.

 

0 Likes