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

Fix For: Missing LibraryConfiguring Injection in DesignToken.razor.cs #2425

Closed
TimonFeldmann opened this issue Jul 20, 2024 · 1 comment · Fixed by #2426
Closed

Fix For: Missing LibraryConfiguring Injection in DesignToken.razor.cs #2425

TimonFeldmann opened this issue Jul 20, 2024 · 1 comment · Fixed by #2426
Labels
status:in-progress Work is in progress

Comments

@TimonFeldmann
Copy link
Contributor

🐛 Bug Report

This issue occurs exclusively in version 4.9.2, downgrading to 4.9.1 resolves the issue.

When injecting any design token and calling .SetValue() with any element reference, the DesignToken class fails to inject the registered LibraryConfiguration causing an Object reference not set to an instance of an object exception to be thrown inside UrlFormatterExtensions.cs.

💻 Repro or Code Sample

Component:

@using Microsoft.FluentUI.AspNetCore.Components.DesignTokens

<div class="container">
	<FluentTextField @ref="Test" @bind-Value=Title></FluentTextField>
</div>

@code {
	[Parameter, EditorRequired]
	public string Title { get; set; } = null!;

	FluentTextField Test;

	[Inject]
	private Density _density { get; set; } = default!;

	protected override async Task OnAfterRenderAsync(bool firstRender)
	{
		if (firstRender)
		{
			await _density.SetValueFor(Test.Element, 10);

			StateHasChanged();
		}
	}
}

Startup:

    public static class MauiProgram
    {
        public static MauiApp CreateMauiApp()
        {
            var builder = MauiApp.CreateBuilder();
            builder
                .UseMauiApp<App>()
                .ConfigureFonts(fonts =>
                {
                    fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
                });

            builder.Services.AddMauiBlazorWebView();
	    builder.Services.AddHttpClient();
            builder.Services.AddFluentUIComponents();

#if DEBUG
            builder.Services.AddBlazorWebViewDeveloperTools();
            builder.Logging.AddDebug();
#endif

            return builder.Build();
        }
    }

🤔 Expected Behavior

Calling .SetValue() on any DesignToken should not throw a null reference exception.

😯 Current Behavior

LibraryConfiguration is injected as null into DesignToken.razor.cs causing a null reference exception when attempting to set any DesignToken value.

🌍 Your Environment

  • OS & Device: Windows
  • .NET MAUI desktop application
  • .NET and Fluent UI Blazor library Version: .NET 8 / Fluent UI 4.9.2
@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Jul 20, 2024
@TimonFeldmann
Copy link
Contributor Author

TimonFeldmann commented Jul 21, 2024

I went ahead and checked out this repository to see if I could find the issue and I was able to locate the issue and confirm the fix locally.

It appears there was an existing DI constructor in DesignToken which set the IJSRuntime, but not the LibraryConfiguration which was introduced in 4.9.2.

I modified the constructor for DesignToken as well as the DesignTokenGenerator to add the DI for LibraryConfiguration for all design tokens:

Fix is included in #2426

@TimonFeldmann TimonFeldmann changed the title fix: Missing LibraryConfiguring Injection in DesignToken.razor.cs Fix For: Missing LibraryConfiguring Injection in DesignToken.razor.cs Jul 21, 2024
@vnbaaij vnbaaij added status:in-progress Work is in progress and removed triage New issue. Needs to be looked at labels Jul 21, 2024
@vnbaaij vnbaaij linked a pull request Jul 22, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:in-progress Work is in progress
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants