在 Linux 上的 ASP.NET 核心 MVC 项目中的身份脚手架后问题 运行 项目
Problem running project after Identity scaffolding in ASP.NET Core MVC project on Linux
我试过添加
<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>
完整错误:
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.
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(ListBuilder
1&
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, Action
1 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 行:
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<AppDbContext>();
已解决!
我按以下顺序分别卸载了 dotnet 包:
dotnet-sdk-bin (AUR)
dotnet-runtime-bin (AUR)
dotnet-host-bin (AUR)
然后我以相反的顺序构建了这些相同的包。
现在它们都在 3.1.1.sdk101-2,我的项目又是 运行。
我也注意到了同样的事情,请查看框架的 ms 更新,几天前有一个更新,希望安装较新的 nuget 包。
您遇到的问题是 nuget 包与您的 SDK 不匹配,至少我是这样的。在进行 windows 更新并安装新的 Core Runtime 后,Version=3.1.1.0 一切正常
我通过重新安装解决了这个问题:
.Net 核心 SDK 3.1.101
和
ASP.NET 核心运行时 3.1.1
问题出在 ASP.NET Core Identity Packages 的最新 3.1.1 版中。当我恢复到以前的稳定 3.1.0 版本时它工作正常。请参阅下面的快照:
对我来说,安装最新的 SDK 和核心运行时并没有解决问题。
Affected Libraries
我试过添加
<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>
完整错误:
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.
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, ListBuilder
1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctor, Boolean& ctorHasParameters, Boolean& isVarArg) at System.Reflection.CustomAttribute.AddCustomAttributes(ListBuilder
1& 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, Action
1 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 行:
services.AddDefaultIdentity<IdentityUser>()
.AddEntityFrameworkStores<AppDbContext>();
已解决! 我按以下顺序分别卸载了 dotnet 包: dotnet-sdk-bin (AUR) dotnet-runtime-bin (AUR) dotnet-host-bin (AUR)
然后我以相反的顺序构建了这些相同的包。 现在它们都在 3.1.1.sdk101-2,我的项目又是 运行。
我也注意到了同样的事情,请查看框架的 ms 更新,几天前有一个更新,希望安装较新的 nuget 包。
您遇到的问题是 nuget 包与您的 SDK 不匹配,至少我是这样的。在进行 windows 更新并安装新的 Core Runtime 后,Version=3.1.1.0 一切正常
我通过重新安装解决了这个问题: .Net 核心 SDK 3.1.101 和 ASP.NET 核心运行时 3.1.1
问题出在 ASP.NET Core Identity Packages 的最新 3.1.1 版中。当我恢复到以前的稳定 3.1.0 版本时它工作正常。请参阅下面的快照:
对我来说,安装最新的 SDK 和核心运行时并没有解决问题。
Affected Libraries