Error getting value from 'Items' on 'AutoMapper.ResolutionContext'.

106 views
Skip to first unread message

Ben Wong

unread,
Mar 14, 2020, 11:38:08 PM3/14/20
to AutoMapper-users
Hi, I'm getting a strange error with AutoMapper. I hope somebody can tell me what's going on by looking at the stack trace. The mystery is that the response was always sent w/o a problem. Furthermore, the below stack trace is actually from a test after I had replaced all instances of mapper.Map with manual mapping. Nothing seemed to change. Part of me was starting to wonder whether Newtonsoft used Automapper internally, but I was a bit skeptical that something like this would have gone unaddressed.
The project is ASP.NET Core 3, and the AutoMapper.Extensions.Microsoft.DependencyInjection pkg is v7.0.0.

Will the below exception occur if I have a profile set up wrong? As mentioned, this was copied from a test where no profiles were actually being used, and when they were in effect, the response seemed to work anyway! I am nevertheless, concerned that I may have some underlying issue present.

Thanks for any help you can give!

fail: Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer[2]
      Connection ID "18374686511347007497", Request ID "8000000d-0007-ff00-b63f-84710c7967bb": An unhandled exception was thrown by the application.
Newtonsoft.Json.JsonSerializationException: Error getting value from 'Items' on 'AutoMapper.ResolutionContext'.
 ---> System.InvalidOperationException: You must use a Map overload that takes Action<IMappingOperationOptions>!
   at AutoMapper.ResolutionContext.CheckDefault()
   at AutoMapper.ResolutionContext.get_Items()
   at Newtonsoft.Json.Serialization.ExpressionValueProvider.GetValue(Object target)
   --- End of inner exception stack trace ---
   at Newtonsoft.Json.Serialization.ExpressionValueProvider.GetValue(Object target)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeDictionary(JsonWriter writer, IDictionary values, JsonDictionaryContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)
   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)
   at Newtonsoft.Json.JsonSerializer.Serialize(JsonWriter jsonWriter, Object value)
   at Newtonsoft.Json.Linq.JToken.FromObjectInternal(Object o, JsonSerializer jsonSerializer)
   at Newtonsoft.Json.Linq.JObject.FromObject(Object o, JsonSerializer jsonSerializer)
   at Audit.Core.Providers.FileDataProvider.SaveFileAsync(String fullPath, AuditEvent auditEvent)
   at Audit.Core.Providers.FileDataProvider.InsertEventAsync(AuditEvent auditEvent)
   at Audit.Core.AuditScope.SaveEventAsync(Boolean forceInsert)
   at Audit.Core.AuditScope.EndAsync()
   at Audit.Core.AuditScope.DisposeAsync()
   at Audit.Mvc.AuditAttribute.AfterResultAsync(ResultExecutedContext filterContext)
   at Audit.Mvc.AuditAttribute.OnResultExecutionAsync(ResultExecutingContext context, ResultExecutionDelegate next)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|29_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeResultFilters()
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()

Reply all
Reply to author
Forward
0 new messages