Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Thu Mar 31, 2022 6:34 pm

Please help.
We are trying to use Spire in a .NET-Core 5.0 application.
We got it to load, and use Word-to-HTML fine.
But in trying to do Word-to-PDF, we are encountering an error:

Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

The error occurs when we try to save to stream as such:

Spire.Doc.Document doc;
doc.SaveToStream(~~stream~~, global::Spire.Doc.FileFormat.PDF); <== Error occurs here.

Can anyone help us solve this issue?

John.Brumbelow
 
Posts: 2
Joined: Thu Mar 31, 2022 6:28 pm

Thu Mar 31, 2022 6:54 pm

I think I found the solution.

I went to my .NET Core-5.0 project file (csproj) and applied changes I learned from this link:

https // stackoverflow.com/questions/68505622/how-do-i-add-system-windows-forms-to-my-net-5-0-project

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

<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework> <== I changed minde from just "net5.0" to "net5.0-windows".
<UseWindowsForms>true</UseWindowsForms> <== I added this setting.
</PropertyGroup>

Then my error went away, and I got my Word-to-PDF to work.
I hope that is the correct thing to do!

John.Brumbelow
 
Posts: 2
Joined: Thu Mar 31, 2022 6:28 pm

Fri Apr 01, 2022 10:37 am

Hi,

Yes, the way you used to solve your problem is correct. As you seen in the stackoverflow, this issue is related to the compatibility of App TargetFramework. If I directly create a Winform App with NET5.0, the TargetFramework in csproj is net5.0-windows rather than net5.0. If you have other question, please feel free to write back.

Sincerely,
Kylie
E-iceblue support team
User avatar

kylie.tian
 
Posts: 412
Joined: Mon Mar 07, 2022 2:30 am

Return to Spire.PDF

cron