MigraDoc and .NET Core 2.0
Asked Answered
S

2

6

I have made a class library for PDF-generation. It is implemented using PDFshart-MigraDoc (the core package*). The class library itself is made with .NET Standard as its target framework.

I can use the class library in classic C# projects (like WinForms), but if I try to use it with .NET Core 2.0, I get the following error:

Could not load file or assembly 'System.Drawing.Common, Version=0.0.0.0, Culture=neutral, PublicKeyToken=xxxx'. The system cannot find the file specified.

I guess the reason for this, could be that MigraDoc is using 'System.Drawing' in its implementation, which is (as far as I know) not supported by the .NET Core framework.

However, that doesn't really solve my problem, which is that I need the class library to work for all .NET frameworks. I have tried to include the NuGet package CoreCompat.System.Drawing, based on advise from this post. But this has been without effect, probably because MigraDoc is still trying to use the "original" System.Drawing library.

Is there any way, in which I can get my class library to work for .NET Core? Or am I out of luck...?

Note: The MigraDoc Core Package has nothing to do with the .NET Core Framework. The clash of names is merely a coincidence.

Sea answered 4/7, 2018 at 10:15 Comment(2)
Do you target Windows only or other platforms also?Anastatius
Currently the only target is Windows, yes. It was originally made for a WinForms project, but not a colleague of mine, also wants to use it in a .NET Core 2.0 project.Forehand
D
8

I found a port for PDFSharp & MigraDoc here on github which usesSystem.Drawing.Common and works with .Net Core.

I had the same and got it fully working.

Note: You may need to add System.Drawing.Common Nuget Package in your .Net Core project.

Decrepitate answered 8/3, 2019 at 14:22 Comment(0)
A
1

Update:
Beginning with PDFsharp 6.0.0, PDFsharp supports .NET 6.0 and the Core build no longer relies on System.Drawing.
Beginning with PDFsharp 6.1.0, PDFsharp Core also supports .Netstandard 2.0.

Original answer:
The MigraDoc/PDFsharp Core packages were created long before .NET Core was even announced. "Core" has a different meaning for those MigraDoc packages and they do use System.Drawing.

It's not a bug that the Core package uses System.Drawing.

There are third-party ports of PDFsharp for .NET Core like this one:
https://github.com/groege/PdfSharpCore
Maybe one of these ports is an option for you.

Maybe there are portable replacements for System.Drawing.

Anastatius answered 4/7, 2018 at 11:50 Comment(1)
Thanks for your answer. I should have noted, that I am aware, that the MigraDoc Core is completely unrelated to .NET Core. I was looking for an alternative, which does not require a complete rewrite of my class library. I will try out some of the MigraDoc ports you mentioned. Replacing System.Drawing doesn't seem like its possible.Forehand

© 2022 - 2024 — McMap. All rights reserved.