【发布时间】: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, ListBuilder
1& 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 到今天,我的项目又开始运行了。
【问题讨论】:
-
最好重新安装 Microsoft.AspNetCore.Razor.Runtime 包
-
我的问题是没有安装 SDK 更新,dotnet.microsoft.com/download/dotnet-core/3.1 在我这样做之后,DLL 地狱自行解决了。
标签: c# asp.net-core-mvc entity-framework-core razor-pages asp.net-core-identity