PDFsharp & MigraDoc Foundation
http://forum.pdfsharp.de/

Refactor GlobalFontSettings to an instance class
http://forum.pdfsharp.de/viewtopic.php?f=4&t=4440
Page 1 of 1

Author:  Arolla [ Sun May 07, 2023 8:35 am ]
Post subject:  Refactor GlobalFontSettings to an instance class

When using MigraDoc in a background job server (I use Hangfire), we have situations where setting the GlobalFontSettings.FontResolver property can occur several times leading to an exception. Even when using a mutex the setting code can still run. If the GlobalFontSettings is implemented as an instance class which is passed to the document renderer the problem will disappear.
In .NET Core and up it would in any case be better to refactor the code to be able to use the DI container via a IServiceProvider instance.

Author:  TH-Soft [ Mon May 08, 2023 8:37 am ]
Post subject:  Re: Refactor GlobalFontSettings to an instance class

Arolla wrote:
When using MigraDoc in a background job server (I use Hangfire), we have situations where setting the GlobalFontSettings.FontResolver property can occur several times leading to an exception.
There is no exception when you set the same FontResolver multiple times. Make sure the FontResolver is a singleton and a mutex is used to create that singleton. Been there, done that.

As of now, it is by design that there is a single, global font resolver.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/