- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 .NET CORE 应用程序中使用 AutoMapper。我在 ConfigureServices.cs
方法文件中的 Startup.cs
中配置了 AutoMapper,如下所示:
public void ConfigureServices(IServiceCollection services)
{
/* Some Code */
/* AutoMapper Configuration */
services.AddAutoMapper(typeof(AutoMapperProfileConfiguration).GetType().Assembly);
services.AddMvcCore();
/* Some Code */
}
AutoMapperProfileConfiguration
如下:
public class AutoMapperProfileConfiguration : Profile
{
public AutoMapperProfileConfiguration()
{
CreateMap<LoginRequestDto, Users>();
}
}
然后我在下面的类中使用了这个映射器:
public LoginResponseDto CreateAnAccount(LoginRequestDto loginRequestDto)
{
var userInfo = _mapper.Map<Users>(loginRequestDto);
userInfo.Id = Guid.NewGuid();
_context.InsertItem<Users>(userInfo);
var insertedUserDetails = _context.GetItemById<Users>(userInfo.Id);
insertedUserDetails.Wait();
return _mapper.Map<LoginResponseDto>(insertedUserDetails.Result);
}
但是当我尝试将 loginRequestDto
中存在的数据映射到 Users
类时,它给了我以下异常:
AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types:
Object -> Users
System.Object -> NeighborhoodHelpers.UserMicroservice.Entities.Models.Users
at lambda_method(Closure , Object , Users , ResolutionContext )
at NeighborhoodHelpers.UserMicroservice.DataAccessProvider.UserDataAccess.UserDataAccess.CreateAnAccount(LoginRequestDto loginRequestDto) in D:\Gursimran\Hackathon2\NeighborhoodHelpers.UserMicroservice.API\NeighborhoodHelpers.UserMicroservice.DataAccessProvider\UserDataAccess\UserDataAccess.cs:line 29
at NeighborhoodHelpers.UserMicroservice.Services.UserServices.UserService.CreateAnAccount(LoginRequestDto loginRequestDto) in D:\Gursimran\Hackathon2\NeighborhoodHelpers.UserMicroservice.API\NeighborhoodHelpers.UserMicroservice.Services\UserServices\UserService.cs:line 22
at NeighborhoodHelpers.UserMicroservice.API.Controllers.LoginController.CreateAnAccount(LoginRequestDto loginRequestDto) in D:\Gursimran\Hackathon2\NeighborhoodHelpers.UserMicroservice.API\NeighborhoodHelpers.UserMicroservice.API\Controllers\LoginController.cs:line 34
at lambda_method(Closure , Object , Object[] )
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.InvokeFilterPipelineAsync()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
我正在使用 .NET Core 3.1。请帮我解决一下这个。我无法使用 AutoMapper 功能。
最佳答案
像下面这样更改您的 Startup.cs:
services.AddAutoMapper(typeof(AutoMapperProfileConfiguration));
关于c# - AutoMapper.AutoMapperMappingException : Missing type map configuration or unsupported mapping in . 网络核心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65467481/
当我收到此异常时,是否可以通过某种方式从automapper中获取更多详细信息: AutoMapper.AutoMapperMappingException 通常,它会告诉我这两种映射类型,但不会告诉
当我在我的代码中实现 IReadOnlyList 时,我的单元测试抛出了一个 AutoMapperMappingException。 通过深入研究文章和文档,我猜测 AutoMapper 需要对 re
我猜测除了异常之外的所有信息都是额外的并且几乎不相关(并且在这里是为了完整性)。问题是:根据下面的异常,到底遇到了什么问题? 我无法理解异常消息。据我所知,将 BsonDocument 映射到 Chi
public class ClientViewModel { [Required(ErrorMessage = "The Client Code field is requir
Automapper 出现特殊错误 错误信息: Mapping types: TransportOffer -> TransportOfferDto Model.TransportOffer -> D
_quatationRepository = new QuatationRepository(); IList quatationObj = _quatationRepository.GetAll(q
我有类似 this. 的问题但是这个答案对我不起作用。 我正在做一个小项目。我有两个域模型(Post,Source): public class Post { public Post()
在最近一两周内,我们的代码中开始出现一个奇怪的错误。我正在尝试确定映射失败的根本原因。最内部的异常本身就令人费解:Type 'System.String' does not have a defaul
我在 .NET CORE 应用程序中使用 AutoMapper。我在 ConfigureServices.cs 方法文件中的 Startup.cs 中配置了 AutoMapper,如下所示: publ
我在我的 ASP.NET Core 2.1 Web 应用程序中使用 AutoMapper 7.0.1 和 AutoMapper.Extensions.Microsoft.DependencyInjec
我的实体 public partial class Users { public Users() { sexs = new HashSet(); } [
我是一名优秀的程序员,十分优秀!