【问题标题】:Problem running project after Identity scaffolding in ASP.NET Core MVC project on Linux在 Linux 上的 ASP.NET Core MVC 项目中使用 Identity 脚手架后运行项目时出现问题
【发布时间】:2020-01-16 20:24:46
【问题描述】:

我试过添加

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

但是 2.2.0 是目前可用的最新版本,与错误不匹配。重建应用后错误仍然相同。

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'。系统无法 找到指定的文件。

文件名:'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(元数据令牌 caCtorToken, MetadataImport& 范围, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder1& 属性,RuntimeModule 装饰模块,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) 在 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、Binder binder、Object[] 参数、CultureInfo 文化)
在 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.InvokeCore(对象 例如,IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.c__DisplayClass9_0.g__Startup|0(IServiceCollection 服务集合)在 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.Invoke(对象 例如,IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.ConfigureServicesBuilder.c__DisplayClass8_0.b__0(IServiceCollection 服务)在 Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.UseStartup(类型 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:10行

Startup.cs 第 36 行:

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

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

然后我以相反的顺序构建了这些相同的包。 现在它们都在 3.1.1.sdk101-2 到今天,我的项目又开始运行了。

【问题讨论】:

标签: c# asp.net-core-mvc entity-framework-core razor-pages asp.net-core-identity


【解决方案1】:

我注意到了同样的事情,请查看框架的 ms 更新,几天前有一个更新,预计已经安装了较新的 nuget 包。

您遇到的问题是 nuget 包与您的 SDK 不匹配,至少我是这样。在进行 Windows 更新并安装新的 Core Runtime 后,Version=3.1.1.0 一切正常

【讨论】:

  • 这对我有帮助。我所做的是从解决方案资源管理器中右键单击项目 -> 管理 nuget 包 -> 转到更新选项卡并更新可用更新。
【解决方案2】:

我通过重新安装解决了这个问题: .Net 核心 SDK 3.1.101 和 ASP.NET Core 运行时 3.1.1

https://dotnet.microsoft.com/download/dotnet-core/3.1

【讨论】:

    【解决方案3】:

    问题在于 ASP.NET Core 标识包的最新 3.1.1 版本。当我恢复到以前的稳定 3.1.0 版本时,它工作正常。见下图:

    对我来说,安装最新的 SDK 和 Core Runtime 并不能解决问题。

    Affected Libraries

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-07
      • 2020-08-24
      • 2014-09-21
      • 1970-01-01
      相关资源
      最近更新 更多