Search code examples
.netwindowsx509certificate2

Importing certificate failes with "Internal Error"


I use .NET\C# to manage Windows user's certificate. When I use X509Store.Add() method it works for some users, but it sometimes fails with "Internal Error".

What could be a cause?


Solution

  • It turned out that the problem was only with new users which were created by code. Further investigation revealed that there was the cause was a missing home directory. Windows has troubles with importing a certificate (with priv key) to a user without its profile directory already created, hence "Internal Error".

    The solution was to force creation of the home directory for all new users created by code.