Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.TypeInitializationException when using SkiaSharp in net9.0-browserwasm #18994

Open
nksharma1999 opened this issue Dec 4, 2024 · 3 comments
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/needs-information Indicates an issue needs more information in order to work on it. triage/untriaged Indicates an issue requires triaging or verification

Comments

@nksharma1999
Copy link

Current behavior

Platform: net9.0 wasm

image

Error

System.TypeInitializationException: The type initializer for 'SkiaSharp.SKFontStyle' threw an exception.
---> System.DllNotFoundException: libSkiaSharp
at SkiaSharp.SKFontStyle..ctor(Int32 weight, Int32 width, SKFontStyleSlant slant)
at SkiaSharp.SKFontStyle..ctor(SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant)
at SkiaSharp.SKFontStyle.SKFontStyleStatic..ctor(SKFontStyleWeight weight, SKFontStyleWidth width, SKFontStyleSlant slant)
at SkiaSharp.SKFontStyle..cctor()
--- End of inner exception stack trace ---

Expected behavior

Required UI:
image

How to reproduce it (as minimally and precisely as possible)

  1. Run the provided code in a net9.0-browserwasm project.
  2. Observe the error in the console.

Code:

private ObservableCollection<PieSeries<int>> CreatePieSeries() {
	var systemValues = new[] { random.Next(1, 100), random.Next(1, 100), random.Next(1, 100) };
	var fillColors = new[] { 
		TurbineStatusColorCodes.SYSTEM_NOT_OK_COLOR,
		TurbineStatusColorCodes.SYSTEM_OK_COLOR,
		TurbineStatusColorCodes.NOCOMM_COLOR 
	};
	var labelColors = new[] { SKColors.White, SKColors.Black, SKColors.Black };

	return PieChartHelper.CreatePieSeries(systemValues, fillColors, labelColors);
}
public static class PieChartHelper {
	private const int MAX_RADIAL_COLUMN_WIDTH = 10;
	private const int DATA_LABELS_FONT_SIZE = 7;
	private const string FONT_FAMILY = "Arial";


	public static ObservableCollection<PieSeries<T>>? CreatePieSeries<T>(T[] values, string[] colors, SKColor[] labelColors) {
		if (values == null || colors == null || labelColors == null) {
			return null;
		}

		var minLength = Math.Min(values.Length, Math.Min(colors.Length, labelColors.Length));

		var pieSeries = new ObservableCollection<PieSeries<T>>();

		for (var i = 0; i < minLength; i++) {
			try {
				pieSeries.Add(CreatePieSeriesItem(values[i], colors[i], labelColors[i]));
			}
			catch (Exception ex) {
				Console.WriteLine($"Error creating PieSeries item: {ex}");
			}
		}

		return pieSeries;
	}


	private static PieSeries<T> CreatePieSeriesItem<T>(T value, string fillColor, SKColor labelColor) {
		try {
			return new PieSeries<T> {
				Values = new[] { value },
				MaxRadialColumnWidth = MAX_RADIAL_COLUMN_WIDTH,
				Fill = new SolidColorPaint(SKColor.Parse(fillColor)),
				DataLabelsPaint = new SolidColorPaint(labelColor) {
					SKTypeface = SKTypeface.FromFamilyName(FONT_FAMILY, SKFontStyle.Bold)
				},
				DataLabelsSize = DATA_LABELS_FONT_SIZE,
				DataLabelsFormatter = point => point.Coordinate.PrimaryValue.ToString()
			};
		}
		catch (Exception ex) {
			Console.WriteLine(ex);
			return new PieSeries<T>();
		}
	}
}

Workaround

No response

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

WebAssembly

IDE

Visual Studio 2022

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

No response

@nksharma1999 nksharma1999 added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Dec 4, 2024
@MartinZikmund
Copy link
Member

@nksharma1999 Are you referencing the SkiaSharp.Views.Uno.WinUI NuGet package in your .csproj?

@jeromelaban jeromelaban added the triage/needs-information Indicates an issue needs more information in order to work on it. label Dec 4, 2024
@nksharma1999
Copy link
Author

@MartinZikmund i am using LiveChartsCore.SkiaSharpView.Uno.WinUI

@github-actions github-actions bot removed the triage/needs-information Indicates an issue needs more information in order to work on it. label Dec 5, 2024
@jeromelaban
Copy link
Member

@nksharma1999 you mention a provided project, but it does not seem to be attached. Can you provide it?

@jeromelaban jeromelaban added the triage/needs-information Indicates an issue needs more information in order to work on it. label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/needs-information Indicates an issue needs more information in order to work on it. triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

No branches or pull requests

3 participants