I met the error "This assembly is built by a runtime newer than the currently.."

I met the error "This assembly is built by a runtime newer than the currently.."

Anonymous
Not applicable
1,912 Views
4 Replies
Message 1 of 5

I met the error "This assembly is built by a runtime newer than the currently.."

Anonymous
Not applicable

Hi, Write to ask for solutions to problems.

 

I'm working on a tool that works outside of a Windows Form.

I completed the implementation by ActiveX method, but because of the speed problem, pattern was re-implemented in .NET.

 

I confirmed that it works well with AutoCAD 2018 by implementing the following in .Net.

Here is part of the code I used.

20190925235140.jpg

 (Sorry, I didn't know how to put the code in the box like everyone else, so I inserted it as an image)

 

However, problems have been reported with users of AutoCAD 2008.

The following message is said to occur.

[This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded]

 

I searched for this issue and found that I can lower the version of the .NET Framework in the project properties.

But I met other problems.

 

In Visual Studio 2019, lowering the version of the .NET Framework in the project properties to less than 4.0 causes a build error.

A warning occurs in the Microsoft.CSharp entry in the reference, and an error states that creation could not be made.

(error CS0656 Microsoft.CSHarp.RuntimeBinder.CharpArgumentInfo.Create...)

 

As a result, netloads fail in AutoCAD 2008 for dlls built with the 4.7.2 .NET Framework and After setting the version of the .NET Framework low, the build fails.

 

I would appreciate it if someone can let me know how to solve this problem.

 

Thanks.

0 Likes
Accepted solutions (2)
1,913 Views
4 Replies
Replies (4)
Message 2 of 5

norman.yuan
Mentor
Mentor
Accepted solution

To post code is very simple: click "</>" button above the post message window, which pops up a dialog window, then you paste your code and click "OK".

 

You cannot use the same compiled DLL file for both AutoCAD2013 or later version and AutoCAD version older than Acad2013. The newer version DLL must be built against 3 Acad .NET API assemblies (accoremgd/acdbmgd/acmgd.dll), while for pre-AutoCAD 2013 version, there are only 2 AutoCAD .NET assemblies (acdbmgd/acmgd.dll).

 

So, if you want the code to work in pre-Acad2013 or post-Acad2013 (inclusive), you MUST build your code in different project/solution with different AutoCAD .NET API assemblies referenced. With separated project/solution, you can now choose suitable target .NET framework for your target AutoCAD version. For Acad2008, you probably use .NET2.0 or 3.x. .NET 4.0 might also work, but you need to update acad.exe.config, for sure. (if you have no idea on what I said, you might as well forget to write code for Acad2008: it is so out-of-date version!)

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 3 of 5

Anonymous
Not applicable

Thank you norman,

 

I would also like the customer to use the latest version, but I have to support the old version.

Judging from your valuable information, I can create two kinds of dlls and netload appropriate dlls considering the user's AutoCAD verion. Is that correct?

 

So I tried and I encounter problems in the process of constructing a new project.

This causes problems in the following code -missing compiler required member 'error CS0656 Microsoft.Charp.RuntimeBinder.CSharpArgmentInfo.Creat'.

 

[CommandMethod("PATTERN_GEN")]

public void Pt_Gen()
{
    dynamic acCurDb = HostApplicationServices.WorkingDatabase;
    dynamic acSpace = acCurDb.CurrentSpacdId;    // Error
    dynamic acLyrTbl = acCurDb.LayerTableId;
    dynamic acEd = Application.DocumentManager.MdiActiveDocument.Editor;

 

I created a project and added acmgd.dll and acdbmgd.dll to the references in the AutoCAD 2008 path. Is there something I'm missing?
Or is there a compatibility issue in the code?

Please advice on netloadable dll development environment in AutoCAD 2008.

 

Thank you.

0 Likes
Message 4 of 5

_gile
Consultant
Consultant
Accepted solution

Hi,

 

For a project built for AutoCAD 2008, you should target the .NET Framework 2.0 (the Framework which is installed by this version). Such a project will not be able to use the 'dynamic' type which only appeared with the 4.0 framework.

But anyway, you should not use 'dynamic' everywhere you could use strong typing. Using the 'dynamic' type deprives you of Visual Studio's help (intellisense and compile-time / edit-time-error generation) and makes your program less efficient (late binding is slower than early binding).

That said, you can have two projects in the same solution, one for AutoCAD 2008 to 2012 versions targeting the .NET Framework 2.0 and using the AutoCAD 2008 libraries (acdbmgd and acmgd) and another for AutoCAD 2013 and later that targets the .NET Framework 4.0 and that uses the AutoCAD 2013 libraries (accoremgd, acdbmgd and acmgd).
Both projects can share most, if not all, code. Just write and test the code in the A2008 project and then share it with the other project in which you simply "Add as a link" the project A2008 .cs files.
In this way, you are less likely to use APIs that only exist in recent versions, but you are missing these features.
It goes without saying that if you want to publish your plugin, you should test it in all versions of AutoCAD that can use it (2008 to 2020).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

0 Likes
Message 5 of 5

Anonymous
Not applicable

Thanks gile,

Greate help again.

0 Likes