从ASP.Net Core 1.1迁移到2.0时出现BadImageFormatException [英] BadImageFormatException when migrating from ASP.Net Core 1.1 to 2.0

查看:140
本文介绍了从ASP.Net Core 1.1迁移到2.0时出现BadImageFormatException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将ASP.Net Core 1.1应用程序迁移到了刚刚发布的新2.0版本.现在,我得到以下异常:

I just migrated an ASP.Net Core 1.1 application to the new 2.0 version that was just released. Now I get the following exception:

System.BadImageFormatException:'无法加载文件或程序集 'dotnet-aspnet-codegenerator-design'或其依赖项之一.一个 试图加载格式不正确的程序.'

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.'

在以下行(AddMvc)上引发了异常:

The exception is thrown on the following line (AddMvc):

public IServiceProvider ConfigureServices(IServiceCollection services)
{
    ...
    services.AddMvc(options =>
        {
            options.Filters.Add(new MiddlewareFilterAttribute(typeof(LocalizationPipeline)));
        })
        .AddJsonOptions(options =>
        {
            // Maintain property names during serialization. See:
            // https://github.com/aspnet/Announcements/issues/194
            options.SerializerSettings.ContractResolver = new DefaultContractResolver();
        })
        .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
        .AddDataAnnotationsLocalization();
}

我正在使用AnyCPU目标平台来定位.Net Framework 4.7.如果使用的是win10-x64 RID ,任何帮助. 每个Nuget软件包都是最新的,等等.

I'm targeting the .Net Framework 4.7, using AnyCPU target platform. I'm using the win10-x64 RID if this is of any help. Every Nuget package is up to date etc.

有什么主意吗?谷歌搜索我没有运气.

Any idea? I've got no luck by googling.

推荐答案

当我从 x86 切换到 x64 时(从核心1.1升级到2.0后,发生了相同的异常) ).

the same exception occurred when I switched from x86 to x64 (after upgrading from core 1.1 to 2.0).

由于在运行时确实不需要dotnet-aspnet-codegenerator-design,因此我删除了该引用.但是随后,Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv程序集发生了相同的异常.

Since dotnet-aspnet-codegenerator-design is not really needed at runtime, I removed that reference. But then an identical exception occurred with the Microsoft.AspNetCore.Server.Kestrel.Transport.Libuv assembly.

幸运的是,该问题与我没有更改 .NET Core运行时标识符(RID)的事实有关.这仍然是在win7-x86上设置的,因此我将其更改为win7-x64,可以加载Libuv devepency.

Luckily, that problem was related to the fact I didn't change the .NET Core Runtime Identifier (RID). This was still set on win7-x86, so I changed it to win7-x64 and the Libuv devepency could load.

我希望可以对dotnet-aspnet-codegenerator-design进行一些修复,因为这种依赖性对于脚手架控制器和视图可能是必需的...

I hope there will be some fix for dotnet-aspnet-codegenerator-design since that dependency is probably necessary for scaffolding controllers and views...

更新:Github上存在此问题( https://github.com/aspnet/Scaffolding/issues/601 )

Update: there is an issue for this on Github (https://github.com/aspnet/Scaffolding/issues/601)

这篇关于从ASP.Net Core 1.1迁移到2.0时出现BadImageFormatException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆