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

Serialization of int[][] does not work. #1386

Open
rdelmont opened this issue Jan 9, 2025 · 2 comments
Open

Serialization of int[][] does not work. #1386

rdelmont opened this issue Jan 9, 2025 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@rdelmont
Copy link

rdelmont commented Jan 9, 2025

Assemblies affected
ASP.NET Core OData 8.2.7

Describe the bug
Having a int[][] property in the returned DTO causes an error when serializing.

System.Runtime.Serialization.SerializationException
HResult=0x8013150C
Message=ODataResourceSerializer cannot write an object of type 'Collection(Edm.Int32)'.
Source=Microsoft.AspNetCore.OData
StackTrace:
at Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.GetResourceType(Object graph, ODataSerializerContext writeContext) in D:\a_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSerializer.cs:line 1873

Reproduce steps
Just add a int[][] property in the returned object

Data Model
public sealed class PlaneDto
{
public Guid Id { get; set; }
public double[]? Normal { get; set; }
public double[]? Point { get; set; }
public double[]? Points { get; set; }
public int[][]? Contours { get; set; }
}

EDM (CSDL) Model

<EntityType Name="PlaneDto" BaseType="DataLoopCore.Services.MetrologyData.V2.Dtos.Data.MeasurementObjectDto">
  <Property Name="datumLabel" Type="Edm.String" />
  <Property Name="normal" Type="Collection(Edm.Double)" Nullable="false" />
  <Property Name="point" Type="Collection(Edm.Double)" Nullable="false" />
  <Property Name="points" Type="Collection(Edm.Double)" Nullable="false" />
  <Property Name="contours" Type="Collection(System.Int32[])" />
</EntityType>

Request/Response
No response.

Expected behavior
A JSON object structured like:
{
"@odata.type": "#Dtos.Data.PlaneDto",
"id": "07dce6fe-ff12-4a88-86ae-2d8bb552088f",
"normal": [ -0.99999999974639, 8.22496291971287E-06, 2.09659328342425E-05 ],
"point": [ -22.4877607468324, 0.000184960998336979, 0.000471476881530173 ],
"points": [
-22.4822136189295,
-13.6948240459868,
269.9512,
-22.4820373695539,
7.7337680567001,
269.9512,
-22.4820382114908,
7.72519531946929,
269.914405720526,
-22.4820924772204,
3.43135458418128,
269.010603875648,
-22.482096711542,
3.14035286630288,
268.922802234785,
-22.4821017805847,
2.8683067344908,
268.78775108443
],
"contours": [
[ 1, 2, 3 ],
[ 2, 3, 4 ]
]
}

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context

Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.GetResourceType(object graph, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 1873
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSerializer.cs(1873)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteResourceAsync(object graph, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext, Microsoft.OData.Edm.IEdmTypeReference expectedType) Line 442
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSerializer.cs(442)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteObjectInlineAsync(object graph, Microsoft.OData.Edm.IEdmTypeReference expectedType, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 89
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSerializer.cs(89)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteResourceSetItemAsync(object item, Microsoft.OData.Edm.IEdmStructuredTypeReference elementType, bool isUntypedCollection, Microsoft.OData.Edm.IEdmTypeReference resourceSetType, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.IODataEdmTypeSerializer resourceSerializer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 253
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSetSerializer.cs(253)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteResourceSetAsync(System.Collections.IEnumerable enumerable, Microsoft.OData.Edm.IEdmTypeReference resourceSetType, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 139
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSetSerializer.cs(139)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectInlineAsync(object graph, Microsoft.OData.Edm.IEdmTypeReference expectedType, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 108
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSetSerializer.cs(108)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteComplexAndExpandedNavigationPropertyAsync(Microsoft.OData.Edm.IEdmProperty edmProperty, Microsoft.OData.UriParser.SelectItem selectItem, Microsoft.AspNetCore.OData.Formatter.ResourceContext resourceContext, Microsoft.OData.ODataWriter writer) Line 1118
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSerializer.cs(1118)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteComplexPropertiesAsync(Microsoft.AspNetCore.OData.Formatter.Serialization.SelectExpandNode selectExpandNode, Microsoft.AspNetCore.OData.Formatter.ResourceContext resourceContext, Microsoft.OData.ODataWriter writer) Line 1019
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSerializer.cs(1019)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteResourceAsync(object graph, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext, Microsoft.OData.Edm.IEdmTypeReference expectedType) Line 463
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSerializer.cs(463)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSerializer.WriteObjectInlineAsync(object graph, Microsoft.OData.Edm.IEdmTypeReference expectedType, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 89
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSerializer.cs(89)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteResourceSetItemAsync(object item, Microsoft.OData.Edm.IEdmStructuredTypeReference elementType, bool isUntypedCollection, Microsoft.OData.Edm.IEdmTypeReference resourceSetType, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.IODataEdmTypeSerializer resourceSerializer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 253
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSetSerializer.cs(253)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteResourceSetAsync(System.Collections.IEnumerable enumerable, Microsoft.OData.Edm.IEdmTypeReference resourceSetType, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 139
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSetSerializer.cs(139)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectInlineAsync(object graph, Microsoft.OData.Edm.IEdmTypeReference expectedType, Microsoft.OData.ODataWriter writer, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 108
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSetSerializer.cs(108)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.Serialization.ODataResourceSetSerializer.WriteObjectAsync(object graph, System.Type type, Microsoft.OData.ODataMessageWriter messageWriter, Microsoft.AspNetCore.OData.Formatter.Serialization.ODataSerializerContext writeContext) Line 71
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\Serialization\ODataResourceSetSerializer.cs(71)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.ODataOutputFormatterHelper.WriteToStreamAsync(System.Type type, object value, Microsoft.OData.Edm.IEdmModel model, Microsoft.OData.ODataVersion version, System.Uri baseAddress, Microsoft.Net.Http.Headers.MediaTypeHeaderValue contentType, Microsoft.AspNetCore.Http.HttpRequest request, Microsoft.AspNetCore.Http.IHeaderDictionary requestHeaders, Microsoft.AspNetCore.OData.Formatter.Serialization.IODataSerializerProvider serializerProvider) Line 163
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\ODataOutputFormatterHelper.cs(163)
Microsoft.AspNetCore.OData.dll!Microsoft.AspNetCore.OData.Formatter.ODataOutputFormatter.WriteResponseBodyAsync(Microsoft.AspNetCore.Mvc.Formatters.OutputFormatterWriteContext context, System.Text.Encoding selectedEncoding) Line 250
	at D:\a\_work\1\s\src\Microsoft.AspNetCore.OData\Formatter\ODataOutputFormatter.cs(250)
Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Formatters.TextOutputFormatter.WriteAsync(Microsoft.AspNetCore.Mvc.Formatters.OutputFormatterWriteContext context)
Microsoft.AspNetCore.Mvc.Core.dll!Microsoft.AspNetCore.Mvc.Infrastructure.ObjectResultExecutor.ExecuteAsyncCore(Microsoft.AspNetCore.Mvc.ActionContext context, Microsoft.AspNetCore.Mvc.ObjectResult result, System.Type objectType, object value)
...

@rdelmont rdelmont added the bug Something isn't working label Jan 9, 2025
@marabooy marabooy self-assigned this Jan 14, 2025
@xuzhg
Copy link
Member

xuzhg commented Jan 14, 2025

I created a sample to use the Edm.Untyped for collection of collection primitive. See details at https://github.com/xuzhg/WebApiSample/tree/main/v8.x/CollectionOfCollectionUsingEdmUntyped.

@rdelmont
Copy link
Author

Thx @xuzhg , using Edm.Untyped works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants