Could not load file or assembly 'DocumentFormat.OpenXml
Asked Answered
G

9

24

I'm keep getting this error is VS2013

Could not load file or assembly 'DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies.

In my web.config

    <?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
    <connectionStrings>
        <add name="hjkom_med_web_udvConnectionString" connectionString="Data Source=M95;Initial Catalog=hjkom-med_web;Persist Security Info=True;User ID=HJkom-MED_web;Password=bvkeB7hh" providerName="System.Data.SqlClient"/>
    </connectionStrings>
    <system.web>
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/>
                <add assembly="WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                **<add assembly="DocumentFormat.OpenXml, Version=2.0.5022.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>**

</assemblies></compilation>
    </system.web>
</configuration>

I have tried to insert windowsbase and a lot of other things.

I have search and search for a solution, do any body know how to fix it?

Gorlovka answered 14/8, 2014 at 11:48 Comment(7)
Well do you have that version of the assembly available?Fugazy
I'm not quite sure what you mean? it is a file I can add? Perhaps it would help to explain that it is a great system that is and run on an IIS server today, where I'm making a larger amount of corrections which must then be online when I'm done. The error comes when I want to run it in VS2013.Gorlovka
It's an assembly - it doesn't just appear out of the ether. You'll need to download or install it appropriately. I'd just use the nuget package, to be honest...Fugazy
Up for Jon, check if you have the version you are trying to include available in the GAC where it should be put when you installed the SDK. If you keep having problems, try using dependency walker and see if you are missing something else. You can also try setting Copy Local = true on the reference to the .dll and see if that resolves your problem. BTW: I think that a reference to System.Xml is also needed.Lent
Jon- I have tried using the NuGet console and it says: PM> Install-Package DocumentFormat.OpenXml Install-Package : The current environment doesn't have a solution open. At line:1 char:16 + Install-Package <<<< DocumentFormat.OpenXml + CategoryInfo : InvalidOperation: (:) [Install-Package], InvalidOperationException + FullyQualifiedErrorId : NuGetNoActiveSolution,NuGet.PowerShell.Commands.InstallPackageCommand Is it because this is a VS2013 website or do i do something wrong?Gorlovka
Thanks :-) I now got Documentformat.OpenXML added. but now I have fixed that error but now i god 262 errors, it is like after i added DocumentFormat.OpenXml it "forgot" every other referenceGorlovka
I am does not know on which stage you are getting this error but if after publishing then the solution could be: Open solution explorer -> References/Bin (where this library included) -> right click on the file -> copy local -> true. this operation will copy your file to local directory and publish it with all other libraries.Hock
M
21

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

Meander answered 15/6, 2015 at 16:40 Comment(2)
this download is no longer availableLaura
Just to clarify if someone needs it (I didn't get it right away): ClosedXML depends on DocumentFormat.OpenXml, but ClosedXML has maximum version of DocumentFormat.OpenXml that it supports, while newer unsupported versions of DocumentFormat.OpenXml are available. So just downgrade DocumentFormat.OpenXml if you've installed the latest version. To find out exact version you need check ClosedXML description, section "Dependencies".Plastered
B
6

At the time of writing this answer, there are 3 versions of Open XML SDK:

You most probably have referenced in your project DLL version 2.5 which was installed on your machine.
To get required v2.0 assembly, I suggest you to use NuGet I provided above.

Brasilein answered 11/1, 2016 at 20:40 Comment(0)
T
2

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).

Trawler answered 23/8, 2020 at 10:59 Comment(0)
V
2

Just for adding up a working solution, in my case I was working in my computer and a server, the reference wasn't there, then I added a file that used the reference to the DLL, but when I uploaded to the server the new version, I just copied the files because I can't do a "normal VS deploy", as usual, I didn't update web.config... but... these lines were missing at the end:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="DocumentFormat.OpenXml" publicKeyToken="8fb06cb64d019a17" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.12.3.0" newVersion="2.12.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Drawing.Common" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.2" newVersion="4.0.0.2" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Maybe you don't need the "Drawing reference" but the OpenXml part did the trick, good luck!

Verticillaster answered 17/3, 2021 at 7:48 Comment(0)
B
1

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..

Bedel answered 17/11, 2014 at 7:41 Comment(0)
D
1

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);
    }
Deedradeeds answered 17/1, 2019 at 10:49 Comment(0)
E
0

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

Etherize answered 27/9, 2018 at 7:9 Comment(0)
A
0

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.

Aylmer answered 30/9, 2020 at 14:13 Comment(0)
S
0

I had referenced DocumentFormat.XML dll into my .Net Core Web Api project and was deploying via xCopy. Problem was that I copied just the dll files and ignored the autogenerated json file: "projectName.deps.json" - which actually lists all the dependencies of the project. Once I included this file with xCopy it worked.

Stuartstub answered 10/5, 2024 at 4:42 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.