azure – 错误System.BadImageFormatException服务结构

问题

我正在构建服务结构应用程序.当我创建一个项目并运行它工作正常.但是当我在Api控制器中注入一个服务时,它给了我这个错误,我试图解决它,但还没有成功.

错误

System.BadImageFormatException
Could not load file or assembly ‘dotnet-aspnet-codegenerator-design’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

图片

添加了这项服务

protected override IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners()
        {
            return new ServiceInstanceListener[]
            {
                new ServiceInstanceListener(serviceContext =>
                    new KestrelCommunicationListener(serviceContext,"ServiceEndpoint",(url,listener) =>
                    {
                        ServiceEventSource.Current.ServiceMessage(serviceContext,$"Starting Kestrel on {url}");

                        return new WebHostBuilder()
                                    .UseKestrel()
                                    .ConfigureServices(
                                        services => services
                                            .AddSingleton<StatelessServiceContext>(serviceContext)
                                            .AddScoped(typeof(ISendMessage),typeof(SendMessage))
                                            )
                                    .UseContentRoot(Directory.GetCurrentDirectory())
                                    .UseStartup<Startup>()
                                    .UseServiceFabricIntegration(listener,ServiceFabricIntegrationoptions.None)
                                    .UseUrls(url)
                                    .Build();
                    }))
            };
        }

解决方法

这是我们前面遇到的一个问题,当你尝试添加asp.net核心控制器时.出于某种原因,visual studio添加了对“Microsoft.VisualStudio.Web.CodeGeneration.Design”的引用.

我的想法是删除引用,也不使用Project-> Add-> Controller添加控制器.

只需添加基本代码文件并从早期控制器复制内容即可.

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...