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.

WeakHashList Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.

See original GitHub issue

Describe the bug

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at Avalonia.Utilities.WeakHashList`1.GetAlive(Func`1 factory) in /_/src/Avalonia.Base/Utilities/WeakHashList.cs:line 210
   at Avalonia.Utilities.WeakEvent`2.Subscription.OnEvent(Object sender, TEventArgs eventArgs) in /_/src/Avalonia.Base/Utilities/WeakEvent.cs:line 157
   at Avalonia.Utilities.WeakEvents.<>c__DisplayClass5_1.<.cctor>b__7(Object _, PropertyChangedEventArgs e) in /_/src/Avalonia.Base/Utilities/WeakEvents.cs:line 29
   at CommunityToolkit.Mvvm.ComponentModel.ObservableObject.OnPropertyChanged(PropertyChangedEventArgs e)
   at CommunityToolkit.Mvvm.ComponentModel.ObservableObject.OnPropertyChanged(String propertyName)
   at CommunityToolkit.Mvvm.ComponentModel.ObservableObject.SetProperty[T](T& field, T newValue, String propertyName)
   at SvgToXaml.ViewModels.FileItemViewModel.set_Svg(SvgViewModel value) in /Users/wieslawsoltes/Documents/GitHub/SvgToXaml/src/SvgToXaml.Base/ViewModels/FileItemViewModel.cs:line 37
   at SvgToXaml.ViewModels.FileItemViewModel.<>c__DisplayClass28_0.<Load>b__0() in /Users/wieslawsoltes/Documents/GitHub/SvgToXaml/src/SvgToXaml.Base/ViewModels/FileItemViewModel.cs:line 86
   at System.Threading.Tasks.Task.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at SvgToXaml.ViewModels.FileItemViewModel.Load(DrawAttributes ignoreAttribute) in /Users/wieslawsoltes/Documents/GitHub/SvgToXaml/src/SvgToXaml.Base/ViewModels/FileItemViewModel.cs:line 84
   at SvgToXaml.ViewModels.MainWindowViewModel.<.ctor>b__31_9(FileItemViewModel x) in /Users/wieslawsoltes/Documents/GitHub/SvgToXaml/src/SvgToXaml.Base/ViewModels/MainWindowViewModel.cs:line 93
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Avalonia.Threading.JobRunner.RunJobs(Nullable`1 priority) in /_/src/Avalonia.Base/Threading/JobRunner.cs:line 38
   at Avalonia.Native.PlatformThreadingInterface.SignaledCallback.Signaled(Int32 priority, Int32 priorityContainsMeaningfulValue) in /_/src/Avalonia.Native/PlatformThreadingInterface.cs:line 39
   at Avalonia.Native.Interop.Impl.__MicroComIAvnSignaledCallbackVTable.Signaled(Void* this, Int32 priority, Int32 priorityContainsMeaningfulValue) in /_/src/Avalonia.Native/Interop.Generated.cs:line 4502
--- End of stack trace from previous location ---
   at Avalonia.Native.PlatformThreadingInterface.RunLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Native/PlatformThreadingInterface.cs:line 90
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) in /_/src/Avalonia.Base/Threading/Dispatcher.cs:line 61
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 120
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime[T](T builder, String[] args, ShutdownMode shutdownMode) in /_/src/Avalonia.Controls/ApplicationLifetimes/ClassicDesktopStyleApplicationLifetime.cs:line 209
   at SvgToXaml.Program.Main(String[] args) in /Users/wieslawsoltes/Documents/GitHub/SvgToXaml/src/SvgToXaml.Desktop/Program.cs:line 14

To Reproduce

Run SvgToXaml.Desktop app and add some items, change selections in left ListBox, exception sometimes happens.

Expected behavior

No exception

Screenshots

Desktop (please complete the following information):

  • OS: macOS M1
  • Version 11.0.0-preview1

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:5
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
grokyscommented, Dec 16, 2022

Thanks @sdijoseph !

1reaction
batzencommented, Nov 20, 2022

This also happens in my application. In my case i have instances of ObservableCollection which are updated on background threads, but those updates are protected by locks so it’s in fact thread safe. With Avalonia 10 this wasn’t an issue, but with 11 it just throws an NRE.

The exception is not always thrown in WeakHashList but sometimes later in Subscription.OnEvent and then in foreach(var item in alive.Span) where alive is from WeakHashList.GetAlive().

Read more comments on GitHub >

github_iconTop Results From Across the Web

Object Reference Not Set to an Instance of an Object
This exception is thrown when you try to access a member—for instance, a method or a property—on a variable that currently holds a...
Read more >
c# - What is a NullReferenceException, and how do I fix it?
Unhandled Exception : System.NullReferenceException: Object reference not set to an instance of an object. at Program.Main().
Read more >
How can I fix the error: System.NullReferenceException
When you have a statement like A.B.C = E.F; , and you receive an NullReferenceException 'Object reference not set to an instance of...
Read more >
Object reference not set to an instance of an object” error?
The “Object reference not set to an instance of an object” is a very famous error in C# that appears when you get...
Read more >
System.nullreferenceexception: 'object reference not set to ...
Let me just explain what the error means: You have tried to use a variable, property, or a method return value but it...
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