在Linux上的ASP.NET Core MVC项目中进行身份验证后,运行项目时出现问题

问题描述:

我尝试添加

<PackageReference Include="Microsoft.AspNetCore.Razor.Runtime" Version="2.2.0" />

但是,当前提供的最新版本2.2.0与错误不匹配.重建应用程序后,错误仍然相同.

However 2.2.0 is the latest version available at this time, which doesn't match the error. The error is still the same after rebuilding the app.

project.csproj:

project.csproj:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.1" />

    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>

    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.1" />

    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.1">
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
      <PrivateAssets>all</PrivateAssets>
    </PackageReference>

    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.0" />

    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.0" />
  </ItemGroup>
</Project>

完整错误:

未处理的异常. System.IO.FileNotFoundException:无法加载 文件或程序集'Microsoft.AspNetCore.Razor.Runtime,Version = 3.1.1.0, 文化=中性,PublicKeyToken = adb9793829ddae60'.系统无法 找到指定的文件.

Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Razor.Runtime, Version=3.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

文件名:"Microsoft.AspNetCore.Razor.Runtime,版本= 3.1.1.0, 文化=中性,PublicKeyToken = adb9793829ddae60'位于 System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule模块, Int32 typeToken,RuntimeTypeHandle [] typeInstantiationContext, 的RuntimeTypeHandle [] methodInstantiationContext) System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type [] genericTypeArguments,Type [] genericMethodArguments)位于 System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken,MetadataImport&作用域,RuntimeModule装饰模块, MetadataToken装饰令牌,RuntimeType属性,FilterType,布尔值 mustBeInheritable,ListBuilder 1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder 1& 属性,RuntimeModule装饰模块,Int32 装饰的MetaDataToken,运行时类型attributeFilterType,布尔值 mustBeInheritable,ListBuilder 1 derivedAttributes) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](Assembly element) at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartFactory.GetApplicationPartFactory(Assembly assembly) at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateDefaultParts(String entryAssemblyName) at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersCore(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersWithViewsCore(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersWithViews(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services) at Microsoft.AspNetCore.Identity.IdentityBuilderUIExtensions.AddRelatedParts(IdentityBuilder builder) at Microsoft.AspNetCore.Identity.IdentityBuilderUIExtensions.AddDefaultUI(IdentityBuilder builder) at Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionUIExtensions.AddDefaultIdentity[TUser](IServiceCollection services, Action 1 configureOptions)位于 Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionUIExtensions.AddDefaultIdentity [TUser](IServiceCollection 服务)在pieshop.Startup.ConfigureServices(IServiceCollection) 服务)在/home/juan/code/web-projects/pieshop/src/Startup.cs:line中 36在System.RuntimeMethodHandle.InvokeMethod(对象目标, Object []参数,签名sig,布尔构造函数,布尔 wrapExceptions) System.Reflection.RuntimeMethodInfo.Invoke(对象obj,BindingFlags invokeAttr,活页夹活页夹,Object []参数,CultureInfo文化)
在 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object 例如IServiceCollection服务) Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<> c__DisplayClass9_0.g__Startup | 0(IServiceCollection serviceCollection) Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(对象 例如IServiceCollection服务) Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<> c__DisplayClass8_0.b__0(IServiceCollection 服务) Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType,HostBuilderContext上下文,IServiceCollection服务) 在 Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<> c__DisplayClass12_0.b__0(HostBuilderContext 上下文中的IServiceCollection服务) Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()在 Microsoft.Extensions.Hosting.HostBuilder.Build()在 pieshop.Program.Main(String [] args)在 /home/juan/code/web-projects/pieshop/src/Program.cs:line 10

File name: 'Microsoft.AspNetCore.Razor.Runtime, Version=3.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext) at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments) at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder1& attributes, RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder1 derivedAttributes) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType) at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeAssembly assembly, RuntimeType caType) at System.Reflection.RuntimeAssembly.GetCustomAttributes(Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttributes(Assembly element, Type attributeType, Boolean inherit) at System.Attribute.GetCustomAttribute(Assembly element, Type attributeType, Boolean inherit) at System.Reflection.CustomAttributeExtensions.GetCustomAttribute[T](Assembly element) at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartFactory.GetApplicationPartFactory(Assembly assembly) at Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager.PopulateDefaultParts(String entryAssemblyName) at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.AddMvcCore(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersCore(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersWithViewsCore(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddControllersWithViews(IServiceCollection services) at Microsoft.Extensions.DependencyInjection.MvcServiceCollectionExtensions.AddMvc(IServiceCollection services) at Microsoft.AspNetCore.Identity.IdentityBuilderUIExtensions.AddRelatedParts(IdentityBuilder builder) at Microsoft.AspNetCore.Identity.IdentityBuilderUIExtensions.AddDefaultUI(IdentityBuilder builder) at Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionUIExtensions.AddDefaultIdentity[TUser](IServiceCollection services, Action1 configureOptions) at Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionUIExtensions.AddDefaultIdentity[TUser](IServiceCollection services) at pieshop.Startup.ConfigureServices(IServiceCollection services) in /home/juan/code/web-projects/pieshop/src/Startup.cs:line 36 at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass9_0.g__Startup|0(IServiceCollection serviceCollection) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(Object instance, IServiceCollection services) at Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.<>c__DisplayClass8_0.b__0(IServiceCollection services) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(Type startupType, HostBuilderContext context, IServiceCollection services) at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass12_0.b__0(HostBuilderContext context, IServiceCollection services) at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider() at Microsoft.Extensions.Hosting.HostBuilder.Build() at pieshop.Program.Main(String[] args) in /home/juan/code/web-projects/pieshop/src/Program.cs:line 10

Startup.cs的第36行:

Line 36 of Startup.cs:

services.AddDefaultIdentity<IdentityUser>()
    .AddEntityFrameworkStores<AppDbContext>();

解决了! 我按以下顺序分别卸载了dotnet软件包: dotnet-sdk-bin(AUR) dotnet-runtime-bin(AUR) dotnet-host-bin(AUR)

Solved! I uninstalled the dotnet packages separately in the following order: dotnet-sdk-bin (AUR) dotnet-runtime-bin (AUR) dotnet-host-bin (AUR)

然后我以相反的顺序构建了这些相同的软件包. 截止到今天,它们都位于3.1.1.sdk101-2,我的项目再次运行.

Then I built these same packages in the reverse order. Now they are all at 3.1.1.sdk101-2 as of today and my project is running again.

我注意到了同一件事,请查看该框架的ms更新,几天前有更新,希望新的nuget软件包具有已安装.

I had noticed the same thing, please look at the ms updates for the framework, there was an update a few days ago that the newer nuget packages expect to have been installed.

您遇到的问题是nuget软件包与您的SDk不匹配,至少这就是我所拥有的.在Windows更新并安装了新的Core Runtime之后,Version = 3.1.1.0一切都很好

The issue you are having is that the nuget packages are not matching your SDk, at least that's what I had. After doing a windows update and installing the new Core Runtime, Version=3.1.1.0 all was okey