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

4

我的asp.net core应用在桌面上可以正常运行。但是当我部署到Windows Server 2007 R2时,出现了以下错误。

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.
1个回答

1

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

解决方法是编辑你的project.json文件,将runtimes设置为win7-x64。

原始内容:

 "runtimes": {
    "win10-x64": {}
  },

固定:

 "runtimes": {
    "win7-x64": {}
  },

我曾尝试同时使用两个运行时,但发布失败了。

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

Visual Studio Publish Setting


在进行更改后可能需要运行 dotnet restore。否则会出现类似以下的错误提示:": Assets file 'C:\Spartan\Spartan_KPI_Updater\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v1.1/win7-x64'. Ensure you have restored this project for TargetFramework='netcoreapp1.1' " 谢谢! - Nate Anderson

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接