Search code examples
c#comcredential-providers

.NET6: registering COM DLL with regsvr32 results in 80040111


I'm playing around with CredentialProviders for Win10/11, following Steve Syfuh's blog post and repo. Using the repo as is (.net framework 4.6.1) works nicely, but I'd like to do it in .net6.

I've read the docs about COM for .net core and tried to follow, but whatever I do, I get the following error:

The module [myproject].comhost.dll was loaded but the call to DllRegisterServer failed with error code 0x80040111.

My steps were:

  • put [ComVisible(true)] and unique GUIDs to the public classes that should be reachable (namely CredentialProvider, CredentialView, CredentialProviderCredential)
  • edit .csproj file and add <EnableComHosting>True</EnableComHosting>
  • run the midl tool to get credentialprovider.tlb and add it to the .csproj file:
<ItemGroup>
    <ComHostTypeLibrary Include="..\interop\credentialprovider.tlb" Id="1" />
</ItemGroup>
  • elevate the cmd to run regsvr32 [myproject].comhost.dll and get the error above

I've found this question with similar content (but I cannot run it on my machine, and the [myproject].dll is right next to the comhost one), I tried suggestions in Hans Passant's link, but all in vain.

Does anyone has any suggestions as to what could be the issue, please?

I guess I can still do it in .net framework 4.8 (that again works), but I'd like to meddle with it a bit and I'd like to stick to newest version of .net (and also some of the packages I'd like to use don't support framework anymore).


Solution

  • Okay, so after checking it from time to time, I figured it out. My only issue was that I renamed the original CredProvider.Net.Interop2.dll to Interop2.dll. Once I renamed the DLL back to its original name, it started to work like a charm again.

    Weird though, since in the project file I anyway indicated the right path:

    <ItemGroup>
      <Reference Include="CredProvider.NET.Interop2">
        <HintPath>..\midl\Interop2.dll</HintPath>
      </Reference>
    </ItemGroup>
    

    But I'll leave it to wiser men than I am. (And for my project, I'll recreate the DLL anyway together with a suitable name.)

    In the end, I share the results, in case someone else wants to play with Credential Providers in current C# versions: CredentialProvider.Net6. I also corrected all the VS warnings that annoyed me. There are a few bugs though inherited from the original repo, but I'll leave them be - finding and correcting them is relatively easy and create a nice exercise to really understand credential providers :-)