Error "A strongly-named assembly is required" when referencing ServiceStack.Authentication.MongoDb.MongoDbAuthRepository version 2.10.3:

1

I have a ServiceStack Console project using the latest Nuget Packages, When instantiating the AppHost object in my code, I get the following exception:

Could not load file or assembly 'MongoDB.Driver, Version=2.10.3.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)

Now I am told that the ServiceStack MongoDB modules are already strongly signed, however I don't think that's true. there is an unsupported "signed" versions of version 2.10.4.0, which results in many more errors and is not an option.

when I uncomment the line

var mongoauthrepo = new MongoDbAuthRepository(mongoDb, true);

Then the Configure code executes, and the exception is not thrown, however this is no good to me obviously, it just means there is no attempt to load the module.

This problem prevents us from upgrading ServiceStack, we are currently stuck on version 4.5.4 of the main modules.

Here's the full code:

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                //Register ServiceStack license.
                Licensing.RegisterLicense(@"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");

                //Create instance.
                _selfHostRef = new AppHost();
                _selfHostRef.Init();

                Console.WriteLine("now listening at");
            }
            catch (Exception ex)
            {
                //Find the root cause of the issue
                Console.WriteLine(ex.Message);
                throw ex;
            }
        }

        static AppHost _selfHostRef;

        public class AppHost : AppHostHttpListenerPoolBase
        {
            public AppHost()
                : base("Automsoft REST API", typeof(AppHost).Assembly)
            {
            }

            public override void Configure(Funq.Container container)
            {
                // Create mongo client
                var mongoClient = new MongoClient("mongodb://localhost:38128");
                 var mongoDb = mongoClient.GetDatabase("RAPID");

                // Create Mongo Auth Repository   
                var mongoauthrepo = new MongoDbAuthRepository(mongoDb, true);
            }
        }

    }

This is my packages.config file:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Crc32C.NET" version="1.0.5.0" targetFramework="net461" />
  <package id="DnsClient" version="1.3.1" targetFramework="net461" />
  <package id="Microsoft.CSharp" version="4.5.0" targetFramework="net461" />
  <package id="MongoDB.Bson" version="2.10.4" targetFramework="net461" />
  <package id="MongoDB.Driver" version="2.10.4" targetFramework="net461" />
  <package id="MongoDB.Driver.Core" version="2.10.4" targetFramework="net461" />
  <package id="MongoDB.Libmongocrypt" version="1.0.0" targetFramework="net461" />
  <package id="ServiceStack" version="5.9.0" targetFramework="net461" />
  <package id="ServiceStack.Authentication.MongoDb" version="5.9.0" targetFramework="net461" />
  <package id="ServiceStack.Client" version="5.9.0" targetFramework="net461" />
  <package id="ServiceStack.Common" version="5.9.0" targetFramework="net461" />
  <package id="ServiceStack.Interfaces" version="5.9.0" targetFramework="net461" />
  <package id="ServiceStack.Text" version="5.9.0" targetFramework="net461" />
  <package id="SharpCompress" version="0.23.0" targetFramework="net461" />
  <package id="Snappy.NET" version="1.1.1.8" targetFramework="net461" />
  <package id="System.Buffers" version="4.5.1" targetFramework="net461" />
  <package id="System.Memory" version="4.5.4" targetFramework="net461" />
  <package id="System.Numerics.Vectors" version="4.5.0" targetFramework="net461" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.3" targetFramework="net461" />
  <package id="System.Runtime.InteropServices.RuntimeInformation" version="4.3.0" targetFramework="net461" />
</packages>
mongodb
authentication
exception
servicestack
asked on Stack Overflow Jun 25, 2020 by Oisin O'Reilly • edited Jun 25, 2020 by piet.t

1 Answer

0

Now I am told that the ServiceStack MongoDB modules are already strongly signed

ServiceStack .NET Framework dll's are signed, but the issue is with Mongo DB's MongoDB.Driver NuGet package:

"Could not load file or assembly 'MongoDB.Driver, Version=2.10.3.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)"

You can check whether a .dll is signed by viewing the .dll in a IL disassembler like JetBrains dotpeek.

First download the MongoDB.Driver NuGet package:

https://www.nuget.org/api/v2/package/MongoDB.Driver/2.10.4

Then rename .nupkg extension to .zip to extract the .dll's. Since you're using .NET Framework your project will use the .dll's in lib\net452.

If you open MongoDB.Driver.dll in dotPeek and inspect the assembly it will show:

// Assembly MongoDB.Driver, Version=2.10.4.0, Culture=neutral, PublicKeyToken=null

The PublicKeyToken=null indicates this assembly is not signed.

enter image description here

This appears to be a known issue with MongoDB C# drivers.

The only way to make it signed is to build the mongodb/mongo-csharp-driver projects yourself with a Strong Name Key.

answered on Stack Overflow Jun 25, 2020 by mythz

User contributions licensed under CC BY-SA 3.0