AVPolyakov / PdfSharpSandbox

Sandbox for PdfSharp
2 stars 2 forks source link

MissingManifestResourceException with MigraDoc.Improved v1.32.6372 #2

Open MovGP0 opened 5 years ago

MovGP0 commented 5 years ago

When rendering an image to an PDF, I get the following exception:

(INTERNAL ERROR while formatting error message: System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.  Make sure "MigraDoc.Rendering.Resources.Messages.resources" was correctly embedded or linked into assembly "MigraDoc.Rendering" at compile time, or that all the satellite assemblies required are loadable and fully signed.
   at System.Resources.ManifestBasedResourceGroveler.HandleResourceStreamMissing\(String fileName\)
   at System.Resources.ManifestBasedResourceGroveler.GrovelForResourceSet\(CultureInfo culture, Dictionary`2 localResourceSets, Boolean tryParents, Boolean createIfNotExists, StackCrawlMark& stackMark\)
   at System.Resources.ResourceManager.InternalGetResourceSet\(CultureInfo requestedCulture, Boolean createIfNotExists, Boolean tryParents, StackCrawlMark& stackMark\)
   at System.Resources.ResourceManager.InternalGetResourceSet\(CultureInfo culture, Boolean createIfNotExists, Boolean tryParents\)
   at System.Resources.ResourceManager.GetString\(String name, CultureInfo culture\)
   at MigraDoc.Rendering.Resources.Messages.FormatMessage\(IDs id, Object[] args\))
MovGP0 commented 5 years ago

Project was compiled as .NET Core 2.2

AVPolyakov commented 5 years ago
  1. Most likely the path to image is incorrect.
  2. Problem with error message “Image not found” from embedded resource file. I will try to fix this problem.
MovGP0 commented 5 years ago

The image is embedded as BASE64 and still not working. Code is as follows:

// cell is of type MigraDoc.DocumentObjectModel.Tables.Cell
// imageBytes is of type byte[]

if (imageBytes == null || imageBytes.Length == 0) return;

var imageBase64 = "base64:" + Convert.ToBase64String(imageBytes);
cell.AddImage(imageBase64);
AVPolyakov commented 5 years ago

BASE64 images are supported starting with version MigraDoc v1.50.

For many reasons, we refused to use MigraDoc. Now we use SharpLayout. SharpLayout supports images from any stream:

cell.Add(new Image().Content(GetStream));

Stream GetStream()
{
    return //Any Stream. For example, File.OpenRead, Assembly.GetManifestResourceStream, MemoryStream.
}
MovGP0 commented 5 years ago

my workaround was to use the source of PDFSharpCore, did some code fixes on the release build, and used ImageSharp to load the file instead of the base64 encoded string.

Not a clean solution, because I now have rendering issues with tables and fonts. But at least the images are working.