Build/Test Issues

Strong name validation failed

Started by narshe on 6,280 views

My test project has frameworks net50, netcoreapp3.1, netcoreapp2.1, net47, net452. Only net47 and net452 are showing this error. I'm using xUnit.

An error occurred while analysing this project after it was built: System.IO.FileLoadException: Could not load file or assembly 'CsvHelper.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A)
File name: 'CsvHelper.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8c4959082be5c823' ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A)
The Zone of the assembly that failed was:
MyComputer
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
   at System.Reflection.Assembly.LoadFrom(String assemblyFile)
   at nCrunch.Common.ExecutionPlatform.LoadAssembly(FilePath assemblyFilePath)
   at nCrunch.TestExecution.RemoteTaskRunner.AnalyseAssembly(DescribedTestFrameworkDiscoverer[] applicableFrameworks, ComponentUniqueName testComponentUniqueName, PerfTracker perfTracker, TaskLogId taskLogId)

Hi, thanks for sharing this problem.

Something must have gone wrong in the signing of this assembly. It isn't usually necessary for test assemblies to be signed, so you can probably resolve this issue by turning on the prevent signing of assembly setting for the project involved and anything that depends on it.
How can I use InternalsVisibleTo with this? If I remove the PublicKey I can't build. If I prevent signing in NCrunch, I get this error.

Friend access was granted by 'CsvHelper, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null', but the public key of the output assembly ('') does not match that specified by the InternalsVisibleTo attribute in the granting assembly.
You can use an #if NCRUNCH directive to replace the key token in the declaration.

For example:

#if NCRUNCH
[assembly: InternalsVisibleTo("Friend1")]
#else
[assembly: InternalsVisibleTo("Friend1, PublicKey=xyz")]
#endif

If you don't actually need the test project to be signed, I would recommend just not signing it in general. Such a change would remove complexity from your build system and might even bump performance up a little.
I don't need the test project to be signed, but I can't build using InternalsVisibleTo when my library is signed and the test project is not. I get this error:

CS1726: Friend assembly reference 'CsvHelper.Tests' is invalid. Strong-name signed assemblies must specify a public key in their InternalsVisibleTo declarations.

Your preprocessor directive should work though.
This post has been deleted.

Post a reply

Log in to reply.