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

System.InvalidCastException on CollectionView enumeration #592

Closed
BorzillaR opened this issue Oct 8, 2020 · 5 comments · Fixed by #601
Closed

System.InvalidCastException on CollectionView enumeration #592

BorzillaR opened this issue Oct 8, 2020 · 5 comments · Fixed by #601
Assignees
Labels
fixed Issue has been fixed in an upcoming or existing release
Milestone

Comments

@BorzillaR
Copy link

Describe the bug

I create CollectionViewSource and enumerate items in View.

CollectionViewSource source = new CollectionViewSource() { Source = new string[] { "str1", "str2", "str3" } };
            foreach(var item in source.View) {
            }

Code failed with "System.InvalidCastException: 'Specified cast is not valid.'" exception

image

Exception details:

System.InvalidCastException
  HResult=0x80004002
  Message=Specified cast is not valid.
  Source=WinRT.Runtime
  StackTrace:
   at WinRT.ExceptionHelpers.ThrowExceptionForHR(Int32 hr)

Call stack:

 	winrt.runtime.dll!WinRT.ExceptionHelpers.ThrowExceptionForHR(int hr)
winrt.runtime.dll!ABI.System.Collections.Generic.IEnumerable<object>.Windows.Foundation.Collections.IIterable<object>.First()
 	winrt.runtime.dll!ABI.System.Collections.Generic.IEnumerable<object>.FromAbiHelper.GetEnumerator()
 	winrt.runtime.dll!ABI.System.Collections.Generic.IEnumerable<System.__Canon>.GetEnumerator()
 	winrt.runtime.dll!ABI.System.Collections.Generic.IList<System.__Canon>.FromAbiHelper.GetEnumerator()
 	Microsoft.WinUI.dll!ABI.Microsoft.UI.Xaml.Data.ICollectionView.GetEnumerator()
	AttachedCollections.dll!AttachedCollections.MainWindow.MainWindow() Line 19	C#

Version Info

Windows 10 1903 (OS Build 18362.1082)

NuGet package version:

WinUI 3.0.0-preview2.200713.0

Windows app type:

UWP Win32
Yes
Device form factor Saw the problem?
Desktop Yes
@StephenLPeters
Copy link

@stevenbrix is this another manifestation of the cswinrt issue?

@BorzillaR
Copy link
Author

I have checked this issue in Preview 3 and it is still reproduced.

@stevenbrix stevenbrix transferred this issue from microsoft/microsoft-ui-xaml Nov 19, 2020
@stevenbrix
Copy link
Contributor

@angelazhangmsft this looks like a C#/WinRT issue that was missed for Preview3. Would you mind taking a look?

@angelazhangmsft
Copy link
Contributor

I'm able to repro this error with WinUI Preview 3. I also tried updating the FrameworkReference as follows and it still repros with same exception in WinRT.Runtime

<ItemGroup>
        <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref"
                            RuntimeFrameworkVersion="10.0.18362.11-preview" />
        <FrameworkReference Update="Microsoft.Windows.SDK.NET.Ref"
                            TargetingPackVersion="10.0.18362.11-preview" />
</ItemGroup>

@stevenbrix
Copy link
Contributor

Thanks for clarifying, is this something that can make the first .NET5 servicing release in December?

@AdamBraden AdamBraden added this to the Release 1.1 milestone Nov 20, 2020
@angelazhangmsft angelazhangmsft added the fixed Issue has been fixed in an upcoming or existing release label May 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed Issue has been fixed in an upcoming or existing release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants