Unable to load DocumentFormat.OpenXml.dll into AutoCAD 2025

Unable to load DocumentFormat.OpenXml.dll into AutoCAD 2025

shricharana_bharadwaj
Enthusiast Enthusiast
1,206 Views
8 Replies
Message 1 of 9

Unable to load DocumentFormat.OpenXml.dll into AutoCAD 2025

shricharana_bharadwaj
Enthusiast
Enthusiast

Hi, 

 

I'm using openxml to read and write excel files in an AutoCAD plugin. 

I recently switched from AutoCAD 2024 to AutoCAD 2025 and I'm migrating the project to .NET8.

The project itself has no issues. It successfully compiles.

But I'm unable to load the DocumentFormat.OpenXml.dll into AutoCAD 2025. I'm getting the below error. 

Command: NETLOAD
Cannot load assembly. Error details: System.IO.FileLoadException: Could not load file or assembly 'DocumentFormat.OpenXml, Version=3.1.0.0, Culture=neutral, PublicKeyToken=8fb06cb64d019a17'.
   at System.Runtime.Loader.AssemblyLoadContext.<LoadFromPath>g____PInvoke|5_0(IntPtr __ptrNativeAssemblyBinder_native, UInt16* __ilPath_native, UInt16* __niPath_native, ObjectHandleOnStack __retAssembly_native)
   at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at Autodesk.AutoCAD.Runtime.ExtensionLoader.Load(String fileName)
   at Autodesk.AutoCAD.ApplicationServices.ExtensionLoader.Load(String fileName)
   at loadmgd()

 

I can load the "DocumentFormat.OpenXml.Framework.dll" into 2025 but not the first one.

 

I can load both the  dlls into AutoCAD 2024 without issues. 

 

Am I missing something ? Could any one please help? 

 

Thanks in advance.

0 Likes
1,207 Views
8 Replies
Replies (8)
Message 2 of 9

norman.yuan
Mentor
Mentor

Later versions of AutoCAD comes with a version of DocumentFormat.OpenXml.dll. So, you should tell how you set reference to it: you use the one coming with AutoCAD, or use NuGet package (thus the latest version)?

 

The one coming with AutoCAD does not have DocumentFormat.OpenXml.Framework.dll, which is a required dependency if you use the latest version of DocumentFormat.OpenXml.dll from NuGet package.

 

Since we are doing Acad2025/.NET 8.0, we should always use NuGet package for the latest version of it and make sure all the dependency DLLs in the NuGet package are deployment with the AutoCAD plugin DLL. So, you need to look into your plugin DLL folder where you NETLOAD it from: do all the DLLs coming with the NuGet package be there?

 

Make sure you have properly edited the Plugin's *.projcs file, as shown below:

normanyuan_0-1727712490508.png

 

I did a quick test with following code, which refers an enum type in DocumentFormat.OpenXml.dll. It works OK, meaning the DocumentFormat.OpenXml.dll is loaded into AutoCAD 2025 correctly.:

 

        [CommandMethod("OpenXmlTest")]
        public static void RunMyCommand()
        {
            var dwg = CadApp.DocumentManager.MdiActiveDocument;
            var ed = dwg.Editor;

            var obj = DocumentFormat.OpenXml.PresentationDocumentType.Presentation;

            ed.WriteMessage($"\nOpenXml.PresentationDocumentType: {obj}");
        }

 

 

Edit:

I added reference from NuGet package, which is in its version 3.10, as opposed to version 2.16, the one comes with AutoCAD2024/2025.

 

HTH.

 

Norman Yuan

Drive CAD With Code

EESignature

Message 3 of 9

shricharana_bharadwaj
Enthusiast
Enthusiast

Hi,

Thank you for the reply.

 

I do have the CopyLocalLockFileAssemblies set to true is .csproj.

I'm using the latest NuGet packet. The versions are 3.1.0 for both the DocumentFormat.OpenXml.dll and DocumentFormat.OpenXml.Framework.dll. 

 

I tried loading the 2.16.0 version that comes with AutoCAD 2025, it loads without issue. But when I try to load the 3.1.0 version file it gives the above mentioned error and does not load the dll.

 

I have these two dlls in the plugin folder.

shricharana_bharadwaj_0-1727760946994.png

 

Is this an AutoCAD bug? Would re-installing AutoCAD work? 

0 Likes
Message 4 of 9

norman.yuan
Mentor
Mentor

As I replied previously, the simple code I tested runs OK.  Just to prove both DocumentFormat.OpenXml.dll and DocumentFormat.OpenXml.Framework.dll are loaded with my simple plugin, I did minor update to let the code refer 2 enum tyles, one from DocumentFormat.OpenXml.dll and the other from DocumentFormat.OpenXml.Framework.dll and the code run as expected:

 

using DocumentFormat.OpenXml;

[assembly: CommandClass(typeof(DocumentOpenXmlTest.MyCommands))]
[assembly: ExtensionApplication(typeof(DocumentOpenXmlTest.MyCommands))]

namespace DocumentOpenXmlTest
{
    public class MyCommands : IExtensionApplication
    {
        [CommandMethod("OpenXmlTest")]
        public static void RunMyCommand()
        {
            var dwg = CadApp.DocumentManager.MdiActiveDocument;
            var ed = dwg.Editor;

            // enum type "PresentationDocumentType" from DocumentFormat.OpenXml.dll
            var obj = DocumentFormat.OpenXml.PresentationDocumentType.Presentation;
            // enum type "FileFormatVersions" from DocumentFormat.OpenXml.Framework.dll
            var fileVersion = FileFormatVersions.Office2016;

            ed.WriteMessage($"\nOpenXml.PresentationDocumentType: {obj}");
            ed.WriteMessage($"\nOpenXml.FileFormatVersion: {fileVersion}");
        }

        public void Initialize()
        {
            var dwg = CadApp.DocumentManager.MdiActiveDocument;
            if (dwg!=null)
            {
                dwg.Editor.WriteMessage("\nOpenXml Test project loaded.");
            }
        }

        public void Terminate()
        {
        
        }
    }
}

I'll take the simple test plugin to one of my other computer for a test (maybe later today) and post back.

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 5 of 9

shricharana_bharadwaj
Enthusiast
Enthusiast

Hi, 

 

I'm not saying it's not loading for you. Forgive me if my reply came across that way.

I believe you. 

 

But the DocumentFormat.OpenXml.dll is not loading in my AutoCAD 2025. I don't know why. All I'm trying to do is get it to load somehow.

 

Here is what I have so far, 

DocumentFormat.OpenXml.dll (version 3.1.0) is not loading for me and in one of my colleague's laptop running AutoCAD 2025.

DocumentFormat.OpenXml.Framework.dll (version 3.1.0) is loading without issue in AutoCAD 2025.

DocumentFormat.OpenXml.dll (Version 2.16) that comes with AutoCAD is loading without issue in AutoCAD 2025.

DocumentFormat.OpenXml.dll (version 3.1.0) is loading without issue in AutoCAD 2024.

 

It's only with version 3.1.0 I'm having an issue with and I'm not sure why!

I'm not sure if it's a corrupt installation or a setting in AutoCAD that's causing this issue. 

 

Anything I can try to get it loaded would be helpful!

 

Thanks in advance.

0 Likes
Message 6 of 9

norman.yuan
Mentor
Mentor

FYI:

I have test my simple DocumentFormat.OpenXml project in my other computers with AutoCAD 2025 and AutoCAD Civil3d 2025, and it worked as expected. That is, there is no issue of loading lasted version of DocumentFormat.OpenXml.dll and DocumentFormat.OpenXml.Frametwork.dll from NuGet (v3.1.0).

 

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes
Message 7 of 9

shricharana_bharadwaj
Enthusiast
Enthusiast

Thank you for checking it on your end.

But, I'm still not able to load the dll into AutoCAD 2025. At this point I have no idea what I can try to fix this. 

0 Likes
Message 8 of 9

shricharana_bharadwaj
Enthusiast
Enthusiast

So, 

I tried loading the dll on a new laptop and freshly installed AutoCAD 2025. The dll still refuses to load. 

Below is the acad.exe details

shricharana_bharadwaj_0-1728484292675.png

 

0 Likes
Message 9 of 9

norman.yuan
Mentor
Mentor

The 2 computers I tried my code with Document.Format.OpenXml successfully both have Acad2025.1 update installed when the code was tried:

 

normanyuan_0-1728487879435.png

 

Norman Yuan

Drive CAD With Code

EESignature

0 Likes