Asked by:
error in assemblyBuilder when moving from Win7 to Win10

Question
-
HI,
I am migrating a from Win7 to WIN10 in VS2015 using .net35SP1. The project runs fine on Win7 but on Win10 it give a runtime error of "Strong name key container not found."
I have searched around some and have tried solutions suggested before including installing Microsoft.Net.Compilers package 2.6.1 and adding <Features>$(Features);UseLegacyStrongNameProvider</Features> to the <PropertyGroup> in the project file. Is anyone able to tell me what needs to be done in order for this to work at runtime once again.
assemblyFileName = String.Format("Company.Configuration.{0}.v{1}.dll", fileName, fileVersion); // Define the assembly's name var an = new AssemblyName { Version = new Version(assemblyVersion), Name = ns }; // Sign the assembly if (!String.IsNullOrEmpty(keyPairFile)) { // Get the KeyPair file to sign the assembly StrongNameKeyPair kp; using (var fs = new FileStream(keyPairFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { kp = new StrongNameKeyPair(fs); } an.KeyPair = kp; } // Define a new assembly that we can save to disk var assemblyBuilder = Thread .GetDomain() .DefineDynamicAssembly(an, AssemblyBuilderAccess.RunAndSave ); ... // Save the dll assemblyBuilder.Save(assemblyFileName);
- Edited by wizardkalor Monday, March 16, 2020 7:04 PM
Monday, March 16, 2020 6:43 PM
All replies
-
are you sure your keyPairFile contains the private key?
perhaps you enabled verification skipping (sn -vr) on your Windows 7 system, but forgot to do this on the new system (been there, done that)Monday, March 16, 2020 7:13 PM -
I tried creating a new key on a Win10 machine just in case it was machine specific. That had no effect either.
Monday, March 16, 2020 7:28 PM -
Hi wizardkalor,
Thank you for posting here.
Could you provide more details about your exception with which line of the code thrown the exception?
Besides, hope the following reference could be helpful.
Why do I lose my key container when I reboot?
Best Regards,
Xingyu Zhao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Tuesday, March 17, 2020 3:16 AM -
The very last line in the posted code (assemblyBuilder.Save(assemblyFileName)) is the line of code where the error occurs.Tuesday, March 17, 2020 9:02 AM
-
Maybe we are not using this correctly either.
The project file contains no line like
<KeyContainerName>MyKeyName</KeyContainerName> like in the link provided by Xingyu Zhao.
instead we have <AssemblyOriginatorKeyFile>KeyFile.snk</AssemblyOriginatorKeyFile>
Tuesday, March 17, 2020 10:05 AM -
Not really a fix but the error goes away if i remove this code from what was originally posted.
if (!String.IsNullOrEmpty(keyPairFile)) { // Get the KeyPair file to sign the assembly StrongNameKeyPair kp; using (var fs = new FileStream(keyPairFile, FileMode.Open, FileAccess.Read, FileShare.Read)) { kp = new StrongNameKeyPair(fs); } an.KeyPair = kp; }
Tuesday, March 17, 2020 6:18 PM -
Hi wizardkalor,
As mentioned in the reference, have you tried to delete the key container and create a new one?
Best Regards,
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Wednesday, March 18, 2020 6:45 AM -
Yes, we have deleted and created a new strong name key and still received the same error.Wednesday, March 18, 2020 10:14 AM
-
Hi wizardkalor,
There may be other possible causes of this error, I afraid that it may related to windows 10.
To help you find a solution, you can report a problem in Developer Community for more help.
Thank you for your understanding.
Best Regards,
Xingyu Zhao
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.Thursday, March 19, 2020 10:04 AM