小编hii*_*t95的帖子

运行项目 netcore 时出现错误 "{"stateMachine":{"<>1__state":-2,"<>t__builder":{"

当我运行项目 netcore 时,我收到一条消息 {"stateMachine":{"<>1__state":-1,"<>t__builder":{ 我不知道如何解决这个问题。我在命令行中看到错误

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1] 执行请求时发生未处理的异常。Newtonsoft.Json.JsonSerializationException:检测到类型为“System.Runtime.CompilerServices.AsyncTaskMethodBuilder”的属性“task”的自引用循环

Microsoft.AspNetCore.Server.Kestrel[13] 连接 ID“0HLFMHMJ7MBQN”,请求 ID“0HLFMHMJ7MBQN:00000001”:应用程序抛出了一个未处理的异常。Newtonsoft.Json.JsonSerializationException:检测到类型为“System.Runtime.CompilerServices.AsyncTaskMethodBuilder”的属性“task”的自引用循环

这是文件 Startup.cs

 public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
        services.AddDbContext<AppDbContext>(options =>
               options.UseSqlServer(Configuration.GetConnectionString("AppDbConnection"),
                   b => b.MigrationsAssembly("liyobe.Data")));

        services.AddIdentity<AppUser, AppRole>()
            .AddEntityFrameworkStores<AppDbContext>()
            .AddDefaultTokenProviders();
        // Configure Identity
        services.Configure<IdentityOptions>(options =>
        {
            // Password settings
            options.Password.RequireDigit = true;
            options.Password.RequiredLength = 6;
            options.Password.RequireNonAlphanumeric = false;
            options.Password.RequireUppercase = false;
            options.Password.RequireLowercase = false;

            // Lockout settings
            options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30);
            options.Lockout.MaxFailedAccessAttempts = 10;

            // User settings
            options.User.RequireUniqueEmail = true;
        });

        services.AddAutoMapper();

        // Add application services.
        services.AddScoped<UserManager<AppUser>, UserManager<AppUser>>();
        services.AddScoped<RoleManager<AppRole>, RoleManager<AppRole>>();

        //CreateMapper(services, …
Run Code Online (Sandbox Code Playgroud)

c# automapper .net-core asp.net-core

6
推荐指数
1
解决办法
2679
查看次数

映射器未初始化。用适当的配置呼叫初始化

将NetMap 2.1 Projet用于AutoMaper时出现错误

映射器未初始化。用适当的配置调用初始化。如果您尝试通过容器或其他方式使用mapper实例,请确保没有对静态Mapper.Map方法的任何调用,并且如果您使用的是ProjectTo或UseAsDataSource扩展方法,请确保传递适当的IConfigurationProvider实例Mapper.cs中的AutoMapper.Mapper.get_Configuration(),第23行

我已经配置了

 public class AutoMapperConfig
{
    public static MapperConfiguration RegisterMappings()
    {
        return new MapperConfiguration(cfg =>
        {
            cfg.AddProfile(new DomainToViewModelMappingProfile());
            cfg.AddProfile(new ViewModelToDomainMappingProfile());
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

文件DomainToViewModelMappingProfile.cs

public class DomainToViewModelMappingProfile : Profile{
      public DomainToViewModelMappingProfile(){
             CreateMap<Function, FunctionViewModel>();
             CreateMap<AppUser, AppUserViewModel>();
             CreateMap<AppRole, AppRoleViewModel>();
 }
}
Run Code Online (Sandbox Code Playgroud)

文件启动

 services.AddSingleton(Mapper.Configuration);
        services.AddScoped<IMapper>(sp => new Mapper(sp.GetRequiredService<AutoMapper.IConfigurationProvider>(), sp.GetService));
Run Code Online (Sandbox Code Playgroud)

有人可以帮助我吗?谢谢!

c# automapper asp.net-core

1
推荐指数
1
解决办法
5459
查看次数

Autofac 未找到任何构造函数

我使用 Autofac 创建一个带有 DependencyInjection 的项目 WindowsForm 应用程序。我在构建时遇到问题。这是我的Program.cs

        var builder = new ContainerBuilder();
        builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly());
        builder.RegisterType<UnitOfWork>().As<IUnitOfWork>().InstancePerDependency();
        builder.RegisterType<DbFactory>().As<IDbFactory>().InstancePerDependency();
        builder.RegisterType<DITestDbContext>().AsSelf().InstancePerDependency();
        // Repositories
        builder.RegisterAssemblyTypes(typeof(ProductCategoryRepository).Assembly)
            .Where(t => t.Name.EndsWith("Repository"))
            .AsImplementedInterfaces().InstancePerDependency();

        // Services
        builder.RegisterAssemblyTypes(typeof(ProductCategoryService).Assembly)
           .Where(t => t.Name.EndsWith("Service"))
           .AsImplementedInterfaces().InstancePerDependency();
        Autofac.IContainer container = builder.Build();

        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(container.Resolve<Form1>());
Run Code Online (Sandbox Code Playgroud)

我遇到一条错误消息

DependencyResolutionException:激活特定注册期间发生错误。有关详细信息,请参阅内部异常。注册:Activator = ProductCategoryService (ReflectionActivator)、服务 = [DITest.Service.IProductCategoryService]、生命周期 = Autofac.Core.Lifetime.CurrentScopeLifetime、共享 = None、所有权 = OwnedByLifetimeScope

DependencyResolutionException:激活特定注册期间发生错误。有关详细信息,请参阅内部异常。注册:Activator = UnitOfWork (ReflectionActivator),服务 = [DITest.Data.Infrastruct.IUnitOfWork],生命周期 = Autofac.Core.Lifetime.CurrentScopeLifetime,共享 = None,所有权 = OwnedByLifetimeScope

NoConstructorsFoundException:找不到类型“DITest.Data.Infrastruct.UnitOfWork”的可访问构造函数。

有人知道怎么修这个东西吗。感谢您!!

.net c# dependency-injection autofac winforms

-1
推荐指数
1
解决办法
7767
查看次数