2

I am trying to process a word document. For that, I installed the DocumentFormat.OpenXml NuGet package. It installed following dependencies:

  • DocumentFormat.OpenXml
  • System.IO.Packaging (4.5.0)
  • System.Runtime.Serialization

Here is the Screen shot

As soon as it hit the code where I am processing the word document. It throws this error "Could not load file or assembly 'System.IO.Packaging, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified."

I have tried the following things so far:

  • Try to manually add a reference of System.IO.Packaging to CSPROJ file but that didn't work and I got the same error.
  <ItemGroup>
    <PackageReference Include="DocumentFormat.OpenXml" Version="2.9.1" />
    <PackageReference Include="System.IO.Packaging" Version="4.5.0" />
    <PackageReference Include="System.Data.Common" Version="4.3.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.6.1" />
  </ItemGroup>
  • I tried to add "WindowsBase" nuget package but it displayed a conflict:
The type 'Package' exists in both 'System.IO.Packaging, Version=4.0.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' 

The error is complaining about version 4.0.3.0 but nuget added version 4.5.0 of System.IO.Packaging DLL. How can I fix that?

magicandre1981
  • 27,895
  • 5
  • 86
  • 127
Imran Khan
  • 117
  • 2
  • 11
  • 1
    Use binding redirect to redirect old references to use the new assembly https://learn.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/bindingredirect-element – Mihail Shishkov Jul 03 '19 at 17:52
  • Also currently there is a bug in WinForms projects. If you reference a net standard dll from the winforms project the dll won't get copied in the bin folder on build. – Mihail Shishkov Jul 03 '19 at 17:54
  • 1
    install the System.IO.Packaging in prerelease version 4.6.0-preview6.19303.8 before trying to install DocumentFormat.OpenXml – magicandre1981 Jul 04 '19 at 15:01
  • @magicandre1981... Getting the same error : Could not load file or assembly 'System.IO.Packaging, Version=4.0.4.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. – Imran Khan Jul 08 '19 at 15:04
  • activate [AutoGenerateBindingRedirects](https://learn.microsoft.com/en-US/dotnet/framework/configure-apps/how-to-enable-and-disable-automatic-binding-redirection) – magicandre1981 Jul 08 '19 at 15:10
  • Github issue: https://github.com/xceedsoftware/DocX/issues/226 – taylorswiftfan Nov 27 '20 at 19:05

1 Answers1

3

Try removing the reference to System.IO.Packaging (4.5.0) and then try adding the "WindowsBase" nuget package

or

Try

Update-Package –reinstall System.IO.Packaging

Shad
  • 1,185
  • 1
  • 12
  • 27
  • 1
    I don't know how to remove "System.IO.Packaging" reference. As it is installed as part of the OpenXml dependency. – Imran Khan Jul 08 '19 at 14:48