You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
foreach(ODataProperty property in resourceWrapper.Resource.Properties)
The property type for ODataResource.Properties is IEnumerable<ODataPropertyInfo> and not IEnumerable<ODataProperty> as it was in OData .NET 8.
While the statement compiles okay, if an object of ODataPropertyInfo is present in the Properties collection property, an exception is thrown.
Reproduce steps
The issue can be reproduced using the following sample code:
using System;using System.Collections.Generic;classODataPropertyInfo{publicstringName{get;set;}}classODataProperty:ODataPropertyInfo{publicobjectValue{get;set;}}classProgram{staticvoidMain(string[]args){varproperties=newList<ODataPropertyInfo>(){new ODataProperty {Name="Id",Value=13},new ODataPropertyInfo {Name="Password"},new ODataProperty {Name="LogonName",Value="foobar"}};foreach(ODataProperty property in properties){
Console.WriteLine($"Name = {property.Name}, Value = {property.Value}");}}}
Exception:
Unhandled Exception:
System.InvalidCastException: Specified cast is not valid.
at Program.Main (System.String[] args) [0x0007a] in <86b2fbb858794e808f5e125cc32a50ce>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidCastException: Specified cast is not valid.
at Program.Main (System.String[] args) [0x0007a] in <86b2fbb858794e808f5e125cc32a50ce>:0
Expected behavior
The property without value (i,e,. ODataPropertyInfo) should be handled gracefully.
The text was updated successfully, but these errors were encountered:
Assemblies affected
Describe the bug
After introducing support for reading properties without value in OData .NET 9, there's a subtle bug in this line of code
AspNetCoreOData/src/Microsoft.AspNetCore.OData/Formatter/Deserialization/ODataResourceDeserializer.cs
Line 492 in 1368836
The property type for
ODataResource.Properties
isIEnumerable<ODataPropertyInfo>
and notIEnumerable<ODataProperty>
as it was in OData .NET 8.While the statement compiles okay, if an object of
ODataPropertyInfo
is present in theProperties
collection property, an exception is thrown.Reproduce steps
The issue can be reproduced using the following sample code:
Exception:
Expected behavior
The property without value (i,e,.
ODataPropertyInfo
) should be handled gracefully.The text was updated successfully, but these errors were encountered: