DocX icon indicating copy to clipboard operation
DocX copied to clipboard

Could not load file or assembly Xceed.Words.NETStandard

Open shandysawyer opened this issue 3 years ago • 5 comments

I am converting a .NET 4.8 Framework library over to a .NET Standard 2.0 class library, which uses Xceed.Words.NET. I have a paid license. I am trying to unit test this new class library with a .NET 5 project in the same solution. The test project contains a project reference to the library. Everything complies correctly. However I am getting the following error when running a unit test:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Xceed.Words.NETStandard, Version=2.3.22263.20500,
Culture=neutral, PublicKeyToken=ba83ff368b7563c6'. The system cannot find the file specified.'

Any recommendations on fixing this issue?

shandysawyer avatar Aug 18 '22 16:08 shandysawyer

Hello, Please send a request to [email protected] if you have a valid license in order to get fast support. Maybe a sample could help better understand the issue. You are mixing .NET5 and .NETStandard ? Thanks

XceedBoucherS avatar Aug 18 '22 17:08 XceedBoucherS

Hi, I have been communicating with support [## 5025 ##].

I am trying to use Xceed.Words.NET in a .NET Standard 2.0 Library to use it inside a .NET Framework 4.8 Application. I followed the steps on your website here, however, I am now getting the following error now:

-->FileNotFoundException: 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.
   at Xceed.Document.NET.Document.PrepareDocument(Document& document, DocumentTypes documentType)
   at Xceed.Words.NET.DocX.Create(Stream stream, DocumentTypes documentType)
   at TestLibrary.Library.ReplaceText() in C:\Users\734278\Downloads\ReplaceText5025\TestLibrary\Library.cs:line 16
   at App.Program.Main(String[] args) in C:\Users\734278\Downloads\ReplaceText5025\App\Program.cs:line 12

Current project file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Drawing.Common" Version="6.0.0" />
    <PackageReference Include="System.IO.Packaging" Version="6.0.0" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="Xceed.Document.NETStandard">
      <HintPath>..\..\..\..\..\Program Files (x86)\Xceed\Xceed Words for .NET v2.3\Bin\NETStandard\Xceed.Document.NETStandard.dll</HintPath>
    </Reference>
    <Reference Include="Xceed.PDF.NETStandard">
      <HintPath>..\..\..\..\..\Program Files (x86)\Xceed\Xceed Words for .NET v2.3\Bin\NETStandard\Xceed.PDF.NETStandard.dll</HintPath>
    </Reference>
    <Reference Include="Xceed.Words.NETStandard">
      <HintPath>..\..\..\..\..\Program Files (x86)\Xceed\Xceed Words for .NET v2.3\Bin\NETStandard\Xceed.Words.NETStandard.dll</HintPath>
    </Reference>
  </ItemGroup>

</Project>

I tried changing System.IO.Packaging to v4.0.0 available in NuGet, but it still gives me the same error.

shandysawyer avatar Aug 24 '22 15:08 shandysawyer

Okay I think I have come to the root cause. The problem I am experiencing is that when using Xceed.Words.NETStandard inside a .NET Standard 2.0 class library, it is not referencing the additionally needed dlls inside that library (System.Drawing.Common and System.IO.Packaging). It only seems to work when those dlls are added to a project that is using my class library.

Does this behavior seem backwards? Shouldn't I be able to add the supporting dlls for Xceed.Words.NETStandard inside the class library and not inside the the project calling the library?

shandysawyer avatar Aug 25 '22 16:08 shandysawyer

I am converting a .NET 4.8 Framework library over to a .NET Standard 2.0 class library, which uses Xceed.Words.NET. I have a paid license. I am trying to unit test this new class library with a .NET 5 project in the same solution. The test project contains a project reference to the library. Everything complies correctly. However I am getting the following error when running a unit test:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Xceed.Words.NETStandard, Version=2.3.22263.20500,
Culture=neutral, PublicKeyToken=ba83ff368b7563c6'. The system cannot find the file specified.'

Any recommendations on fixing this issue?

@shandysawyer could you please tell me what was the solution of your problem? You said that you had been communicating with support?

I have 'Could not load file or assembly 'Xceed.Words.NET, Version=2.4.22471.15220, Culture=neutral, PublicKeyToken=ba83ff368b7563c6'.' exception with .net 5 and .NET Standard 2.0 class library

System.Drawing.Common and System.IO.Packaging were already installed in my case...

VakhrameevAnton avatar Nov 08 '22 23:11 VakhrameevAnton

To clarify, I was using VS 2019. I ended up using this SO answer with Option 2 which was to update the .NET48 NuGet mode to "PackageReference". Switching the mode somehow got thing to wire up things correctly on the backend when referencing the .NET Standard 2.0 library.

Additionally, I would recommend wrapping these .NETStandard dlls in your own internally hosted NuGet packages (one dll per package) and add them to your project via NuGet instead of adding them as dll references in your project. It circumvents other potential problems you can run into.

shandysawyer avatar Nov 09 '22 18:11 shandysawyer