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

Cannot provide a value for property 'LibraryConfiguration' on type 'Microsoft.FluentUI.AspNetCore.Components.FluentButton'. #2460

Closed
pmeems opened this issue Jul 25, 2024 · 2 comments
Labels
triage New issue. Needs to be looked at

Comments

@pmeems
Copy link

pmeems commented Jul 25, 2024

🐛 Bug Report

We have an application made with the default Blazor template.
In this application, we have the default Counter and Weather pages.
We only added FluentUI, some styling, and a test project using xUnit and bUnit.

When building the solution everything is OK, but when running the unit tests we get this error:

Cannot provide a value for property 'LibraryConfiguration' on type 'Microsoft.FluentUI.AspNetCore.Components.FluentButton'. 
There is no registered service of type 'Microsoft.FluentUI.AspNetCore.Components.LibraryConfiguration'.

Something similar was reported in #2425 and that issue should have been solved in v4.9.3.

We're now using v4.9.3 but we still get this error.

Our dependencies:

Project 'Foo.Client' has the following package references
   [net8.0]: 
   Top-level Package                                     Requested   Resolved
   > Meziantou.Analyzer                                  2.*         2.0.161 
   > Microsoft.AspNetCore.Components.WebAssembly         8.*         8.0.7   
   > Microsoft.FluentUI.AspNetCore.Components            4.*         4.9.3   
   > Microsoft.NET.ILLink.Tasks                    (A)   [8.0.7, )   8.0.7   
   > Microsoft.NET.Sdk.WebAssembly.Pack            (A)   [8.0.7, )   8.0.7   
   > Newtonsoft.Json                                     13.*        13.0.3  
   > System.Formats.Asn1                                 8.*         8.0.1   
   > System.Net.Http                                     4.*         4.3.4   
   > System.Text.Json                                    8.*         8.0.4   
   > System.Text.RegularExpressions                      4.*         4.3.1  

Project 'Foo.Client.Tests' has the following package references
   [net8.0]: 
   Top-level Package                     Requested   Resolved
   > bunit                               1.*         1.30.3  
   > coverlet.collector                  6.0.2       6.0.2   
   > coverlet.msbuild                    6.0.2       6.0.2   
   > Meziantou.Analyzer                  2.*         2.0.161 
   > Microsoft.NET.Test.Sdk              17.*        17.10.0 
   > Newtonsoft.Json                     13.*        13.0.3  
   > System.Formats.Asn1                 8.*         8.0.1   
   > System.Net.Http                     4.*         4.3.4   
   > System.Text.Json                    8.*         8.0.4   
   > System.Text.RegularExpressions      4.*         4.3.1   
   > xunit                               2.*         2.9.0   
   > xunit.runner.visualstudio           2.*         2.8.2  

The full exception:

Failed Foo.Client.Tests.CounterPageTests.IncrementButtonShouldIncreaseCounter [405 ms]
Error Message:
System.InvalidOperationException : Cannot provide a value for property 'LibraryConfiguration' on type 'Microsoft.FluentUI.AspNetCore.Components.FluentButton'. There is no registered service of type 'Microsoft.FluentUI.AspNetCore.Components.LibraryConfiguration'.
Stack Trace:
  at Microsoft.AspNetCore.Components.ComponentFactory.<>c__DisplayClass9_0.<CreatePropertyInjector>g__Initialize|1(IServiceProvider serviceProvider, IComponent component)
at Microsoft.AspNetCore.Components.ComponentFactory.InstantiateComponent(IServiceProvider serviceProvider, Type componentType, IComponentRenderMode callerSpecifiedRenderMode, Nullable`1 parentComponentId)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.InstantiateChildComponentOnFrame(RenderTreeFrame[] frames, Int32 frameIndex, Int32 parentComponentId)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewComponentFrame(DiffContext& diffContext, Int32 frameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InitializeNewSubtree(DiffContext& diffContext, Int32 frameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.InsertNewFrame(DiffContext& diffContext, Int32 newFrameIndex)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.AppendDiffEntriesForRange(DiffContext& diffContext, Int32 oldStartIndex, Int32 oldEndIndexExcl, Int32 newStartIndex, Int32 newEndIndexExcl)
at Microsoft.AspNetCore.Components.RenderTree.RenderTreeDiffBuilder.ComputeDiff(Renderer renderer, RenderBatchBuilder batchBuilder, Int32 componentId, ArrayRange`1 oldTree, ArrayRange`1 newTree)
at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.RenderInExistingBatch(RenderQueueEntry renderQueueEntry)
at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
--- End of stack trace from previous location ---
at Bunit.Rendering.TestRenderer.AssertNoUnhandledExceptions() in /_/src/bunit.core/Rendering/TestRenderer.cs:line 629
at Bunit.Rendering.TestRenderer.Render[TResult](RenderFragment renderFragment, Func`2 activator) in /_/src/bunit.core/Rendering/TestRenderer.cs:line 480
at Bunit.Rendering.TestRenderer.RenderFragment(RenderFragment renderFragment) in /_/src/bunit.core/Rendering/TestRenderer.cs:line 101
at Bunit.Extensions.TestContextBaseRenderExtensions.RenderInsideRenderTree(TestContextBase testContext, RenderFragment renderFragment) in /_/src/bunit.core/Extensions/TestContextBaseRenderExtensions.cs:line 43
at Bunit.Extensions.TestContextBaseRenderExtensions.RenderInsideRenderTree[TComponent](TestContextBase testContext, RenderFragment renderFragment) in /_/src/bunit.core/Extensions/TestContextBaseRenderExtensions.cs:line 23
at Bunit.TestContext.Render[TComponent](RenderFragment renderFragment) in /_/src/bunit.web/TestContext.cs:line 68
at Bunit.TestContext.RenderComponent[TComponent](Action`1 parameterBuilder) in /_/src/bunit.web/TestContext.cs:line 54
at Foo.Client.Tests.CounterPageTests.IncrementButtonShouldIncreaseCounter() in D:\Data\a7\621\s\src\Foo.Client.Tests\CounterPageTests.cs:line 22
--- End of stack trace from previous location ---

💻 Repro or Code Sample

🤔 Expected Behavior

When using Microsoft.FluentUI.AspNetCore.Components v4.9.1 we don't get this error.
We expect our code to run with the latest version of Microsoft.FluentUI.
If we need to change our code we expect a detailed explanation what to change.

💁 Possible Solution

I don't have a fix, but I expect a similar fix as done for #2425 needs to be done.

🔦 Context

We use floating version so we always use the latest versions of the packages. For Microsoft.FluentUI we now need to pin the version on 4.9.1 to get is working again.

🌍 Your Environment

  • OS & Device: [e.g. MacOS, iOS, Windows, Linux] on [iPhone 7, PC]
  • Browser [e.g. Microsoft Edge, Google Chrome, Apple Safari, Mozilla FireFox]
  • .NET and Fluent UI Blazor library Version [e.g. 8.0.2 and 4.4.1]

We experience this issue locally on our Window pc with Visual Studio v17.10 and also on our Azure Build Agent (Windows).

@microsoft-github-policy-service microsoft-github-policy-service bot added the triage New issue. Needs to be looked at label Jul 25, 2024
@dvoituron
Copy link
Collaborator

Since version 4.9.2, we've added a configuration to manage JavaScript loading. See #2388
In your unit tests, you must inject this LibraryConfiguration service:

Services.AddSingleton( new LibraryConfiguration()
{
    CollocatedJavaScriptQueryString = null,
});

@pmeems
Copy link
Author

pmeems commented Jul 25, 2024

Thank you. I completely missed that we needed to add these lines, now.

I'll close this issue.

@pmeems pmeems closed this as completed Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage New issue. Needs to be looked at
Projects
None yet
Development

No branches or pull requests

2 participants