- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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:
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()}");
}
}
}
Solved! Go to Solution.