how to put MongoDB.Driver.dll,MongoDB.Bson.dll and MongoDB.Driver.Core.dll into GAC?

0

I wanted to add these assemblies MongoDB.Bson.dll, MongoDB.Driver and MongoDB.Driver.Core into GAC using gacutil.exe but got the following error

Failure adding the assembly to the cache: Attempt to install an assembly without a strong name

So, I installed MongoDB driver in my c# project using NuGet package manager, when I tried to sign assemblies with a strong name using this [assembly:AssemblyKeyFile("C:\\Users\\DELL\\Desktop\\MyStrongKeys.snk")]and build my project it gave me the following three warnings

CSC : warning CS8002: Referenced assembly 'MongoDB.Driver, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name. CSC : warning CS8002: Referenced assembly 'MongoDB.Driver.Core, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name. CSC : warning CS8002: Referenced assembly 'MongoDB.Bson, Version=2.8.0.0, Culture=neutral, PublicKeyToken=null' does not have a strong name.

And when I tried to run the project it gives me the following exceptions

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

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

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

I want to know how can we add these assemblies into GAC?

c#
mongodb
.net-assembly
asked on Stack Overflow Apr 11, 2019 by Muhammad Hammad Ejaz • edited Apr 11, 2019 by Aarif

1 Answer

0

You are using the unsigned Nuget package and you need the dll's to be signed. Probably because your application is signed as well.

So the dll's need to have a strong name. That can be done just as Selvin said: "you have to either ask developer of this assemblies to sign 'em ... or get the code, generate key, compile and sign 'em by yourself".

The official MongoDB drivers are not signed, but there is an unofficial signed MongoDB driver Nuget package of these three files. See here, here and here. When you use these packages your problem might be solved.

The other solution is to sign the drivers yourself by building it from source/scratch.

Whether or not to sign your application is discussed here.

answered on Stack Overflow Nov 12, 2019 by ffonz

User contributions licensed under CC BY-SA 3.0