InitializationException.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. namespace QuestPDF.Drawing.Exceptions
  3. {
  4. public class InitializationException : Exception
  5. {
  6. internal InitializationException(string documentType, Exception innerException) : base(CreateMessage(documentType, innerException.Message), innerException)
  7. {
  8. }
  9. private static string CreateMessage(string documentType, string innerExceptionMessage)
  10. {
  11. var (libraryName, nugetConvention) = GetLibraryName();
  12. return $"Cannot create the {documentType} document using the {libraryName} library. " +
  13. $"This exception usually means that, on your operating system where you run the application, {libraryName} requires installing additional dependencies. " +
  14. $"Such dependencies are available as additional nuget packages, for example {nugetConvention}.Linux.NoDependencies. " +
  15. $"Some operating systems may require installing multiple nugets, e.g. MacOS may need both {nugetConvention}.macOS.NoDependencies and {nugetConvention}.Linux.NoDependencies." +
  16. $"Please refer to the {libraryName} documentation for more details. " +
  17. $"Also, please consult the inner exception that has been originally thrown by the dependency library.";
  18. (string GetLibraryName, string nugetConvention) GetLibraryName()
  19. {
  20. if (innerExceptionMessage.Contains("libSkiaSharp"))
  21. return ("SkiaSharp", "SkiaSharp.NativeAssets");
  22. if (innerExceptionMessage.Contains("libHarfBuzzSharp"))
  23. return ("HarfBuzzSharp", "HarfBuzzSharp.NativeAssets");
  24. // default
  25. return ("SkiaSharp-related", "*.NativeAssets");
  26. }
  27. }
  28. }
  29. }