Unhandled Exception occurred. Unable to process the request. Could not create an instance of type Microsoft.AspNetCore.Http.IFormFile. Type is an interface or abstract class and cannot be instantiated.
See original GitHub issueDescribe the bug We are using Core 3.1 and we have a API to upload a file. Here is the how the endpoint looks like
[ProducesResponseType(typeof(ApiResponse<bool>), 200)]
[HttpPost("File")]
public async Task<IActionResult> AddFile(
[FromHeader] string customerId,
[FromForm] IFormFile file,
CancellationToken token = default(CancellationToken))
{
}
Auditing is enabled and when we consume this endpoint we are getting an exception This was working in Core 2.1, but as soon as this is converted to Core 3.1 it started giving exception for Audit.WebApi
The detailed exception is as follows
"ResponseException": {
"Details": " at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultCreator)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)\r\n at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)\r\n at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)\r\n at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)\r\n at Audit.WebApi.AuditApiHelper.<>c.<SerializeParameters>b__2_1(KeyValuePair`2 v)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)\r\n at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)\r\n at Audit.WebApi.AuditApiHelper.SerializeParameters(IDictionary`2 parameters)\r\n at Audit.WebApi.AuditApiAdapter.GetActionParameters(ControllerActionDescriptor actionDescriptor, IDictionary`2 actionArguments, Boolean serializeParams)\r\n at Audit.WebApi.AuditApiAdapter.CreateOrUpdateAction(ActionExecutingContext actionContext, Boolean includeHeaders, Boolean includeRequestBody, Boolean serializeParams, String eventTypeName)\r\n at Audit.WebApi.AuditApiAdapter.BeforeExecutingAsync(ActionExecutingContext actionContext, Boolean includeHeaders, Boolean includeRequestBody, Boolean serializeParams, String eventTypeName)\r\n at Audit.WebApi.AuditApiAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)\r\n at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)\r\n at Prozesscenter.Response.Decorate.Core.ResponseMiddleware.Invoke(HttpContext context)",
"ExceptionMessage": "Unhandled Exception occurred. Unable to process the request. Could not create an instance of type Microsoft.AspNetCore.Http.IFormFile. Type is an interface or abstract class and cannot be instantiated. Path 'file.ContentDisposition', line 1, position 37."
}
To Reproduce
Create an endpoint which has a parameter of type IFormFile
and configure web Api auditing
Expected behavior There should not be any exception and the Audit API has to log the details.
Libraries (specify the Audit.NET extensions being used including version):
- Audit.WebApi: 15.2.2
- Audit.EntityFramework: 15.2.2
Target .NET framework: For example:
- .NET Standard 2.1
Additional context If I add [AuditIgnore] the issue is not happening, this makes it clear that the issue is happening from AuditWebApi
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
Hey @thepirat000 Give me some time, I can create a sample and attach
Closing assuming you are no longer having this issue. Otherwise please add the code to reproduce and I’ll reopen