autocad 2025 plugin: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0

autocad 2025 plugin: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0

oneMSN
Advocate Advocate
1,275 Views
14 Replies
Message 1 of 15

autocad 2025 plugin: Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0

oneMSN
Advocate
Advocate

I am trying to add dependency injection framework to my autocad 2025 plugin.

 

to demonstrate the issue I have created a small .NET 8.0 Test App class library.

 

I first made the test app and set the initialize method to write a message to the editor "Hello World"  The plugin loaded AOK and displays the message.

 

I add a nuget package Microsoft.Extensions.DependencyInjection ( I have tried others but I get the same error no mater which framework I choose)

 

I adjusted my test app to Initialise the dependency frame work:

private void SetupIOC()
{
   ServiceCollection serviceCollection = new ServiceCollection();
   Debug.WriteLine($"ServiceCollection created erviceCollection.ToString()}");
}

 

But now when loading the plugin throws an exception:
"Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.":"Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"

 

Next I tried referenceing the dll's directly so that they would be copied to the output directory:

 

oneMSN_0-1741441783308.png

See there they are!

 now the error message changes slightly:

 

{"Could not load file or assembly 'Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. Could not find or load a specific file. (0x80131621)":"Microsoft.Extensions.DependencyInjection.Abstractions, Version=9.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60"}

 

So in the first instance it could not find the file to load.  in the next is says it could not find or load.

 

I have never encountered this in the ,NET Framework plugin world.  But this issue with the .NET Core stuff is really annoying as I cannot find a solution except maybe build my own version of an IOC implementation.

In the test app I only have Startup.cs and here it is in it's entirety if anyone has had a similar issue please let me know how you solved it as at the moment I am completely stuck!

 

using System.Diagnostics;
using Autodesk.AutoCAD.Runtime;
using Microsoft.Extensions.DependencyInjection;

namespace ACADTest
{
    public class Startup : IExtensionApplication
    {
        public void Initialize()
        {
            // Tell the user were loaded.
            try
            {
                SetupIOC();
            }
            catch (System.Exception ex)
            {
                Debug.WriteLine($"Error setting up IOC: {ex.Message}"); 
            }
            Autodesk.AutoCAD.ApplicationServices.Core.Application.DocumentManager.MdiActiveDocument.Editor.WriteMessage("Hello World");
        }

        public void Terminate()
        {
            // **TODO** Terminate still to figure out.
            // Might need to dispose of the container or something.
        }

        private void SetupIOC()
        {
            // **TODO** Setup IOC still to figure out.
            // Might need to register services here.

            ServiceCollection serviceCollection = new ServiceCollection();
            Debug.WriteLine($"ServiceCollection created {serviceCollection.ToString()}");
        }

    }
}
0 Likes
Accepted solutions (2)
1,276 Views
14 Replies
Replies (14)
Message 2 of 15

ActivistInvestor
Mentor
Mentor

This is a longshot: Open your csproj file, and look for this:

 

<Nullable>enable</Nullable>

 

If you find it, remove it.

0 Likes
Message 3 of 15

oneMSN
Advocate
Advocate

Hi AI!  I have Nullable set to disabled it irks me.

 

I have attached the vs project to this post hopefully some trusting individual will try running it and let me know if it works for them or otherwise.

 

I have never encountered this behaviour before, I have another plugin which uses nuget packages and it works fine.  I feel I am missing something simple but not sure what that is yet.

 

0 Likes
Message 4 of 15

oneMSN
Advocate
Advocate
Accepted solution

I finally found the issue.
The latest and greatest is not always the best!  When I installed

Microsoft.Extensions.DependencyInjection

Nuget gave me the latest version v9.0  I found another plugin I have which works and discovered the version of the dll was v8.0, So I went back to NUGET and downgraded to v8.0 of this library and the issue went away.  This was quite frustrating, beware! 

Message 5 of 15

brand
Contributor
Contributor

I'm fighting this same issue [could not find/load Microsoft.Extensions.DependencyInjection.Abstractions] with EntityFrameworkCore, which I still haven't solved.

 

For IoC specifically, though, have you tried SimpleInjector? I was able to get that to work in an Autocad 2025 plugin.

0 Likes
Message 6 of 15

kerry_w_brown
Advisor
Advisor

@oneMSN wrote:

I finally found the issue.
The latest and greatest is not always the best!  When I installed

Microsoft.Extensions.DependencyInjection

Nuget gave me the latest version v9.0  I found another plugin I have which works and discovered the version of the dll was v8.0, So I went back to NUGET and downgraded to v8.0 of this library and the issue went away.  This was quite frustrating, beware! 


@oneMSN 

I upvoted the Topic and your post because the solution of using the correct nuget version is one that is sort of hidden away in the configutation and not obvious from the code.

Thanks for posting back.

 

Regards,

 


// Called Kerry or kdub in my other life.

Everything will work just as you expect it to, unless your expectations are incorrect. ~ kdub
Sometimes the question is more important than the answer. ~ kdub

NZST UTC+12 : class keyThumper<T> : Lazy<T>;      another  Swamper
0 Likes
Message 7 of 15

cedric_marchand
Explorer
Explorer

Hi,

 

As my first contribution here, I'm upvoting this Topic and your post.

It works also for Autocad 2026, I didn't try a version above 8.0 though, but 9.X prevents your plugin to load.

Regards

Message 8 of 15

brand
Contributor
Contributor

Any chance you could post a simple project with this working? I still can't get EF to work.

0 Likes
Message 9 of 15

mystarxk-cn
Explorer
Explorer

When use CsvHelper nuget package,it also like this problem, and i hace try some lower revision, but not work.

0 Likes
Message 10 of 15

brand
Contributor
Contributor

I was able to get CsvHelper to work. I've posted a sample solution here: https://github.com/leadensky/Autocad_CsvHelperTest. A couple of settings were needed in the .csproj file:

 

brand_0-1755270431157.png

 

After NETLOAD-ing the DLL, run CSVHELPERTEST command. Output from TestDoc.csv shown below:

 

brand_1-1755270553186.png

 

0 Likes
Message 11 of 15

oneMSN
Advocate
Advocate

I cant get EF to work either. Not in 2025 or 2026.  I don't know when EF got so bloated, but there are about a 'gazzlion' transitive packages referenced and who knows which of them causes the plugin to not load properly.  I know it gets into memory  but the Initialize method is never called.  I guess we should try another ORM, is NHibernate still a thing?  I have not done DB in while!

0 Likes
Message 12 of 15

brand
Contributor
Contributor

Let's go Madhukar Moogala at Autodesk Platform Services! I submitted a ticket to APS and he found that EF 8.0.19 works in 2025/2026. I've confirmed this with 2025. Here's the pertinent stuff in the .csproj file:

 

brand_0-1756219316253.png

I added the package references via NuGet Manager. Note the version numbers, as EF 9.x won't work at this time.

0 Likes
Message 13 of 15

oneMSN
Advocate
Advocate

This is my csproj file:  Plugin will still not load!

 

oneMSN_0-1756226694892.png

 

If I remove 'DbContext' from the code base:

public class TestContext : DbContext { }

It will load.  As soon as I reference DbContext the Plugin will not load, an no errors are present in visual studio.  Any thoughts?

 

I've attached the whole test project if anyone is brave enough to test it.

0 Likes
Message 14 of 15

_gile
Consultant
Consultant
Accepted solution

Hi,

Are the package DLLs copied to the output directory?



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 15 of 15

oneMSN
Advocate
Advocate

Dang, the Dlls were not being copied,  I added '<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> and now I have a working EF plugin. Thanks @_gile 

oneMSN_0-1756308090477.png

 




0 Likes