加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

azure – 错误System.BadImageFormatException服务结构

发布时间:2020-12-16 04:25:45 所属栏目:asp.Net 来源:网络整理
导读:问题 我正在构建服务结构应用程序.当我创建一个项目并运行它工作正常.但是当我在Api控制器中注入一个服务时,它给了我这个错误,我试图解决它,但还没有成功. 错误 System.BadImageFormatException Could not load file or assembly ‘dotnet-aspnet-codegenera
问题

我正在构建服务结构应用程序.当我创建一个项目并运行它工作正常.但是当我在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添加控制器.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读