Could not load file or assembly 'DocumentFormat.OpenXml

后端 未结 7 1523
时光说笑
时光说笑 2021-01-08 01:15

I\'m keep getting this error is VS2013

Could not load file or assembly \'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31b

相关标签:
7条回答
  • 2021-01-08 01:36

    Had the same problem recently.

    I have ClosedXML referenced in a library and when I use the library in a console application I get missing reference error.

    This is because the DocumentFormat.Excel, ExcelNumberFormat and FastMember.Signed are not copied into the output folder of my console application.

    2 solutions :

    1) install the closedXML nuget package and all its dependencies in the client (console application project in this case).

    2) To have the dll copied you have to reference them in the library. Add the following function to the library and call it from the static constructor:

        /// <summary>
        /// This code is here to embeed the following libraries : 
        /// - DocumentFormat.Excel
        /// - ExcelNumberFormat
        /// - FastMember.Signed
        /// </summary>
        private static void EmbeedNeededLibraries()
        {
            Action<Type> noop = _ => { };
            var lib1 = typeof(DocumentFormat.OpenXml.OpenXmlAttribute);
            var lib2 = typeof(ExcelNumberFormat.NumberFormat);
            var lib3 = typeof(FastMember.ObjectAccessor);
            noop(lib1);
            noop(lib2);
            noop(lib3);
        }
    
    0 讨论(0)
  • 2021-01-08 01:37

    I my case, I had different versions referenced in different projects within my solution. VS's nuget consolidate function helped me here as it not only shows different versions but also makes it easy to update the older ones (right click solution >> "manage nuget packages for solution" >> "Consolidate" tab).

    0 讨论(0)
  • 2021-01-08 01:38

    You can look this example.

    http://www.aspsnippets.com/Articles/Solution-ASPNet-GridView-Export-to-Excel-The-file-you-are-trying-to-open-is-in-a-different-format-than-specified-by-the-file-extension.aspx

    I download the example and i imported the

    • ClosedXML.dll
    • DocumentFormat.OpenXml.dll

    dlls (realted dlls is allready in project. And i used them). After that my error is gone. You can try.. I dont know why. But the importent is my project is working right now..

    0 讨论(0)
  • 2021-01-08 01:49

    Check in Packages.config files, in all your projects with in that solution.It's should be same in all projects inside a solution. for reference purpose

    0 讨论(0)
  • 2021-01-08 01:55

    I had this problem because I had a new version of the .dll installed on my computer running on localhost and my server was running an old version of the same .dll

    I just updated it and everything works well after that.

    In your case, install the DocumentFormat.OpenXml version 2.5 available in this microsoft link

    0 讨论(0)
  • 2021-01-08 01:56

    See https://docs.telerik.com/reporting/installation-deploying-adomd.net In my case, my project was referencing both Telerik.Reporting.OpenXmlRendering versions; once I removed the older one this error went away.

    0 讨论(0)
提交回复
热议问题