Closed
Description
Using .NET 6, OData 8.0.11 and 6.0.0-preview.3 version of the library.
In my model configuration I have something like this:
var persons = builder.EntitySet<Person>("Persons");
var searchPersonsAction = persons.EntityType.Collection.Action("Search");
searchPersonsAction.ReturnsCollectionFromEntitySet<Person>("Persons");
searchPersonsAction.Parameter<DateOnly>("birthdate");
Now when the swagger page is displayed an exception is being thrown:
System.TypeLoadException: Could not load type 'Microsoft.OData.Edm.Date' from assembly 'Asp.Versioning.OData.ApiExplorer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMarkHandle stackMark, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark, AssemblyLoadContext assemblyLoadContext)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError)
at Microsoft.OData.Edm.EdmExtensions.DeriveFromWellKnowPrimitive(String edmFullName)
at Microsoft.OData.Edm.EdmExtensions.GetClrType(IEdmType edmType, IEdmModel edmModel)
at Asp.Versioning.OData.ClassProperty..ctor(IEdmOperationParameter parameter, TypeSubstitutionContext context)
at Asp.Versioning.OData.DefaultModelTypeBuilder.<>c__DisplayClass5_1.<NewActionParameters>b__3(IEdmOperationParameter p)
at System.Linq.Enumerable.WhereSelectListIterator`2.ToArray()
at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
at Asp.Versioning.OData.ClassSignature..ctor(String name, IEnumerable`1 properties, ApiVersion apiVersion)
at Asp.Versioning.OData.DefaultModelTypeBuilder.<>c__DisplayClass5_0.<NewActionParameters>b__1(EdmTypeKey _)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Asp.Versioning.OData.DefaultModelTypeBuilder.NewActionParameters(IEdmModel model, IEdmAction action, String controllerName, ApiVersion apiVersion)
at Asp.Versioning.ApiExplorer.ODataApiDescriptionProvider.UpdateModelTypes(ApiDescription description, IODataRoutingMetadata metadata)
at Asp.Versioning.ApiExplorer.ODataApiDescriptionProvider.OnProvidersExecuted(ApiDescriptionProviderContext context)
at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.GetCollection(ActionDescriptorCollection actionDescriptors)
at Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider.get_ApiDescriptionGroups()
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerDocumentWithoutFilters(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwaggerAsync(String documentName, String host, String basePath)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
What I already tried is
- in services.AddSwaggerGen specify a MapType to map a DateOnly to an OpenApiSchema with Type "string" and Format "date"
- in AddOData(...).AddJsonOptions add a custom Json convertor to JsonSerializerOptions.Converters to read/write a DateOnly type