Could not load file or assembly 'DocumentFormat.OpenXml

后端 未结 7 1522
时光说笑
时光说笑 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:

        /// 
        /// This code is here to embeed the following libraries : 
        /// - DocumentFormat.Excel
        /// - ExcelNumberFormat
        /// - FastMember.Signed
        /// 
        private static void EmbeedNeededLibraries()
        {
            Action noop = _ => { };
            var lib1 = typeof(DocumentFormat.OpenXml.OpenXmlAttribute);
            var lib2 = typeof(ExcelNumberFormat.NumberFormat);
            var lib3 = typeof(FastMember.ObjectAccessor);
            noop(lib1);
            noop(lib2);
            noop(lib3);
        }
    

提交回复
热议问题