Unable to load DLL 'api-ms-win-core-registry-l1-1-0.dll'

4

My app asp.net core on my desktop works fine. But when I deploy on my Windows Server 2007 R2 I got this error.

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.
asp.net-core
.net-core
asked on Stack Overflow Nov 27, 2016 by Serge • edited Jul 18, 2018 by ekad

1 Answer

1

I had the same question and problem. The cause of the error for me was I develop on Windows 10 and deploy to Window 2008 R2.

The fix is to edit your project.json runtimes to win7-x64.

Original:

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

Fixed:

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

I did try to have both runtimes, but my publish would fail.

Make sure your "Target Runtime" publish setting is set to win7-x64:

Visual Studio Publish Setting

answered on Stack Overflow Mar 9, 2017 by Michael Twohey

User contributions licensed under CC BY-SA 3.0