Asp.net core 无法加载DLL';api-ms-win-core-registry-l1-1-0.dll';

Asp.net core 无法加载DLL';api-ms-win-core-registry-l1-1-0.dll';,asp.net-core,.net-core,Asp.net Core,.net Core,我桌面上的应用程序asp.net core工作正常。但是当我在WindowsServer2007R2上部署时,我遇到了这个错误 Application startup exception: System.DllNotFoundException: Unable to load DLL 'api-ms-win-core-registry-l1-1-0.dll': The specified module could not be found. (Exception from HRESULT: 0x

我桌面上的应用程序asp.net core工作正常。但是当我在WindowsServer2007R2上部署时,我遇到了这个错误

Application startup exception: System.DllNotFoundException: Unable to load DLL 'api-ms-win-core-registry-l1-1-0.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
   at Interop.mincore.RegOpenKeyEx(SafeRegistryHandle hKey, String lpSubKey, Int32 ulOptions, Int32 samDesired, SafeRegistryHandle& hkResult)
   at Microsoft.Win32.RegistryKey.InternalOpenSubKeyCore(String name, RegistryRights rights, Boolean throwOnPermissionFailure)
   at Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.ResolveDefaultPolicy()
   at Microsoft.Extensions.DependencyInjection.DataProtectionServices.<GetDefaultServices>d__0.MoveNext()
   at Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAdd(IServiceCollection collection, IEnumerable`1 descriptors)
   at Microsoft.Extensions.DependencyInjection.DataProtectionServiceCollectionExtensions.AddDataProtection(IServiceCollection services)
   at Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddAuthentication(IServiceCollection services)
   at Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionExtensions.AddIdentity[TUser,TRole](IServiceCollection services, Action`1 setupAction)
   at Safety.Startup.ConfigureServices(IServiceCollection services)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(IServiceCollection services)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()
Hosting environment: Production
Content root path: C:\inetpub\wwwroot\website.com\httpdocs
Now listening on: http://localhost:16695
Application started. Press Ctrl+C to shut down.
应用程序启动异常:System.DllNotFoundException:无法加载DLL“api-ms-win-core-registry-l1-1-0.DLL”:找不到指定的模块。(来自HRESULT的异常:0x8007007E)
在Interop.mincore.RegOpenKeyEx(SafeRegistryHandle-hKey、String-lpSubKey、Int32-ulOptions、Int32-samDesired、SafeRegistryHandle和hkResult)
位于Microsoft.Win32.RegistryKey.InternalOpenSubKeyCore(字符串名、RegistryRights、Boolean throwOnPermissionFailure)
在Microsoft.AspNetCore.DataProtection.RegistryPolicyResolver.ResolveDefaultPolicy()中
在Microsoft.Extensions.DependencyInjection.DataProtectionServices.d_u0.MoveNext()中
在Microsoft.Extensions.DependencyInjection.Extensions.ServiceCollectionDescriptorExtensions.TryAdd(IServiceCollection集合,IEnumerable`1描述符)
位于Microsoft.Extensions.DependencyInjection.DataProtectionServiceCollectionExtensions.AddDataProtection(IServiceCollectionServices)
位于Microsoft.Extensions.DependencyInjection.AuthenticationServiceCollectionExtensions.AddAuthentication(IServiceCollectionServices)
在Microsoft.Extensions.DependencyInjection.IdentityServiceCollectionExtensions.AddIdentity[TUser,TRole](iSeries收集服务,操作'1 setupAction)
在安全状态下.Startup.ConfigureServices(IServiceCollection服务)
---来自引发异常的上一个位置的堆栈结束跟踪---
在System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()中
位于Microsoft.AspNetCore.Hosting.ConventionBasedStartup.ConfigureServices(iSeries收集服务)
在Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureApplicationServices()上
在Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication()上
托管环境:生产
内容根路径:C:\inetpub\wwwroot\website.com\httpdocs
现在收听:http://localhost:16695
应用程序已启动。按Ctrl+C组合键关闭。

我也有同样的问题。对我来说,错误的原因是我在Windows 10上开发并部署到Windows 2008 R2

修复方法是将project.json运行时编辑为win7-x64

原件:

 "runtimes": {
    "win10-x64": {}
  },
固定的:

 "runtimes": {
    "win7-x64": {}
  },
我确实尝试了两个运行时,但我的发布将失败

确保“目标运行时”发布设置设置为win7-x64:


进行更改后,可能需要运行
dotnet restore
。否则类似于“:Assets文件“C:\Spartan\Spartan\u KPI\u Updater\obj\project.Assets.json”没有“.NETCoreApp,Version=v1.1/win7-x64”的目标。请确保已为TargetFramework='netcoreapp1.1'还原此项目。谢谢!