servicetitan/Stl.Fusion

[StateHasChangedAsync] System.NullReferenceException: 'Object reference not set to an instance of an object.'

timeshift92 opened this issue · 8 comments

Hello, how can fix, this error?

System.NullReferenceException
  HResult=0x80004003
  Message=Object reference not set to an instance of an object.
  Source=Blazorise
  StackTrace:
   at Blazorise.BaseComponent.get_ClassNames()
   at Blazorise.Bootstrap.Button.BuildRenderTree(RenderTreeBuilder builder)
   at Microsoft.AspNetCore.Components.Rendering.ComponentState.RenderIntoBatch(RenderBatchBuilder batchBuilder, RenderFragment renderFragment, Exception& renderFragmentException)
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.HandleExceptionViaErrorBoundary(Exception error, ComponentState errorSourceOrNull)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
--- End of stack trace from previous location ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Components.Rendering.HtmlRenderer.HandleException(Exception exception)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessRenderQueue()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.ProcessPendingRender()
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.AddToRenderQueue(Int32 componentId, RenderFragment renderFragment)
   at Microsoft.AspNetCore.Components.ComponentBase.StateHasChanged()
   at Stl.Fusion.Blazor.ComponentExt.<>c__DisplayClass11_0.<StateHasChangedAsync>g__Invoker|0() in C:\Projects\C#\Stl.Fusion\src\Stl.Fusion.Blazor\ComponentExt.cs:line 108

  This exception was originally thrown at this call stack:
    [External Code]
    Stl.Fusion.Blazor.ComponentExt.StateHasChangedAsync.__Invoker|0() in ComponentExt.cs

image

Hi, looks like you're getting this exception from Blazorise.BaseComponent - i.e. makes sense to look its source code, if it's still available, or decompile it.

One important thing, though: looks like it was called from Fusion's helper allowing to call StateHasChanged (protected method) on another component, which normally is ok only if another component is written in a way it expects this - i.e. it doesn't assume in its own code that only it may call this method.

In short, if you call StateHasChangedAsync on some other component, you must take into acc. the default behavior / assumptions about StateHasChanged.

i have run your example https://github.com/servicetitan/Stl.Fusion/tree/master/samples/TodoApp,
and did not change anything, when he looked on the stack, he swore at blazorise

I see - will check it out today, prob. Blazorise update.

@timeshift92 I fixed the issue. I guess you've updated to the latest Fusion version & got one - that's because v2.1 got a number of changes related to IState there, and in particular, the initial IState<T> value is default(T) now rather than the result of a call of parameterless constructor for type T. This is what was causing ~ a similar issue (NullReferenceException) in most of samples after I upgraded them.

Besides that, all the samples are now updated to the lastest Fusion.

Please confirm if the issue is gone on your end and I'll close the ticket :)

Everything is fine! Thank you