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.

In the .net7 CollectionViewSource has a different behaviour than in the .net6

See original GitHub issue

Basically, in .net7 when you run the attached project and press the button, it will display a list of items. If you run the unit test it will throw an exception on this line

EntityCollectionView = new CollectionViewSource { Source = Entities }.View;

Because the View is null.

If you change the TargetFramework to net6 the test passes because View contains an instance.

Is this a bug?

Regards Daniel Kaczmarek

WpfApp2.zip

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
stevehartercommented, Nov 15, 2022

Appears to be related or a duplicate of https://github.com/dotnet/wpf/issues/7205

Callstack:

   System.NullReferenceException : Object reference not set to an instance of an object.
  Stack Trace:
   at System.Windows.StyleHelper.GetExpression(DependencyObject d, DependencyProperty dp)
   at System.Windows.Data.BindingOperations.GetBindingExpressionBase(DependencyObject target, DependencyProperty dp)
   at System.Windows.Data.CollectionViewSource.<EnsureView>b__103_0(Object x)
   at MS.Internal.Data.ViewManager.EnsureCollectionRecord(Object collection, Func`2 GetSourceItem)
   at MS.Internal.Data.ViewManager.GetExistingView(Object collection, CollectionViewSource cvs, Type collectionViewType, Func`2 GetSourceItem)
   at MS.Internal.Data.ViewManager.GetViewRecord(Object collection, CollectionViewSource cvs, Type collectionViewType, Boolean createView, Func`2 GetSourceItem)
   at MS.Internal.Data.DataBindEngine.GetViewRecord(Object collection, CollectionViewSource key, Type collectionViewType, Boolean createView, Func`2 GetSourceItem)
   at System.Windows.Data.CollectionViewSource.EnsureView(Object source, Type collectionViewType)
   at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e)
   at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args)
   at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType)
   at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal)
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)
   at WpfApp2.MainWindowViewModel.CreateEntityCollectionView() in C:\temp\Wpf2App\WpfApp2\WpfApp2\MainWindowViewModel.cs:line 33
   at TestProject1.Tests.Test1() in C:\temp\Wpf2App\WpfApp2\TestProject1\UnitTest1.cs:line 18
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
2reactions
ThomasGoulet73commented, Feb 2, 2023

I believe the fix is already in the release/7.0 branch but it was not included in a public release yet. It should be included in the upcoming .Net 7.0.3.

Read more comments on GitHub >

github_iconTop Results From Across the Web

.NET 7 Performance Improvements in .NET MAUI - .NET Blog
NET 7, .NET MAUI applications should see an improvement to startup time as well as smoothing scrolling, navigation, and general UI performance.
Read more >
Strange behavior of CollectionViewSource code-behind ...
In my program i have custom class for async loading data at startup in Worklist.Result (observablecollection). At this moment i need use custom ......
Read more >
WinForms UI Controls - .NET 7 Support, Visual Studio, C#
NET 6 / .NET 7 Support includes 190+ UI Controls and Libraries, including Data Grid, Data Visualization and Reporting, and many more.
Read more >
CollectionViewSource updates and SelectedItem looses ...
I am using a radGridView in Master/Detail scenario using MVVM; the selected item is displayed in a custom form that allows editing.
Read more >
.NET
This article explains how to enable users to download multiple files as a single zip archive from a .NET Core Web API. 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