question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor Wasm Clientside , does not read fonts

See original GitHub issue

Do you want to request a feature or report a bug?

  • Bug
  • Feature
  • Question

Did you test against the latest CI build?

  • Yes
  • No

Version of ClosedXML

0.97

What is the current behavior?

When using the Library on clientside blazor . The Default Graphics Engine Cannot Find any fonts . The Constructor of the Engine uses LoadFont Method , which in turn gets the SystemFontCollection.Collection from SixLabors But six labors checks for fonts only in Windows/Linux/MAC platforms and returns an empty array when in browser

What is the expected behavior or new feature?

Maybe , be able to load one or more fonts manually to the Default Graphics Engine ? Is there any other way except implementing a new IXLGrapgicsEngine?

Is this a regression from the previous version?

This problem was not present in 0.96.1 Preview There where two engines and the default one was not using SixLabors Library

Reproducibility

Running the Library in a Blazor application in the Client .

throws exception Unhandled exception rendering component: Unable to find font Calibri or fallback font Microsoft Sans Serif. Install missing fonts or specify a different fallback font through ‘LoadOptions.DefaultGraphicEngine = new DefaultGraphicEngine(“Fallback font name”)’. System.ArgumentException: Unable to find font Calibri or fallback font Microsoft Sans Serif. Install missing fonts or specify a different fallback font through ‘LoadOptions.DefaultGraphicEngine = new DefaultGraphicEngine(“Fallback font name”)’.

Method that produces above exception (When using AdjustToContents())

public static byte[] GetReport()
        {
            using var wb = new XLWorkbook();
            var ws = wb.Worksheets.Add("testSheet");
            ws.Cell("B3").Value = "test";
            ws.Cell("B8").Value = "test";
            ws.Columns().AdjustToContents();

            using MemoryStream stream = new();
            wb.SaveAs(stream);
            stream.Position = 0;
            return stream.ToArray();
        }

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
vip-ehowlettcommented, Jan 10, 2023

You’re not understanding. What I did worked. It is being read into a stream.

This didn’t work for me because I don’t know how you’re embedding the font file in the assembly.

//Gets the Executing assembly (The compiled project actual file)
var assembly = Assembly.GetExecutingAssembly();

//Gets the names of the Embeded Resources (handy to detect full path of the embeded files)
var resources = assembly.GetManifestResourceNames();
foreach (var resource in resources) Console.WriteLine(resource);
0reactions
vip-ehowlettcommented, Jan 10, 2023

Thank you, I appreciate the help! I didn’t know you could do that. I’m new to the .net platform so that’s a neat trick to have.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding CSS files in Blazor client-side app. Doesn't work ...
I made a HTML design for the mainLayout in my Blazor application. I used third party icons and fonts and all worked fine...
Read more >
ASP.NET Core Blazor configuration
Learn about Blazor app configuration, including app settings, authentication, and logging configuration.
Read more >
How to Work With Client-Side Blazor
Initial download of framework (the first time you access any Blazor Wasm site, but once you have it, you have it!) Your app...
Read more >
Creating a Blazor WebAssembly Application — Part 1
In this article, I present an introduction to Blazor, explaining the difference between the hosting options (Client-side, Server-side and Hybrid) ...
Read more >
What's behind the hype about Blazor?
Blazor is a new client-side UI framework from the ASP.NET team. Its big selling point is the ability to write rich web UI...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found