.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

COM Interop and AutoCAD 2025

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
s3b79
664 Views, 12 Replies

COM Interop and AutoCAD 2025

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

Tags (1)
12 REPLIES 12
Message 2 of 13
_gile
in reply to: s3b79

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

Message 3 of 13
s3b79
in reply to: s3b79

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.

Message 4 of 13
_gile
in reply to: s3b79

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

Message 5 of 13
s3b79
in reply to: _gile

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.

 

 

Message 6 of 13
_gile
in reply to: s3b79

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

Message 7 of 13
s3b79
in reply to: s3b79

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.

Message 8 of 13
_gile
in reply to: s3b79

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

Message 9 of 13
ActivistInvestor
in reply to: s3b79

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.

Message 10 of 13
ed57gmc
in reply to: ActivistInvestor

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

Message 11 of 13
ActivistInvestor
in reply to: ed57gmc


@ed57gmc 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
ed57gmc
in reply to: ActivistInvestor


@ActivistInvestor wrote:

@ed57gmc 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

Message 13 of 13
s3b79
in reply to: ed57gmc

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.

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

AutoCAD Inside the Factory


Autodesk Design & Make Report