Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Strong name validation failed
narshe
#1 Posted : Wednesday, April 7, 2021 2:01:28 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/12/2013(UTC)
Posts: 10
Location: United States of America

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
My test project has frameworks net50, netcoreapp3.1, netcoreapp2.1, net47, net452. Only net47 and net452 are showing this error. I'm using xUnit.

Code:
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)

Remco
#2 Posted : Wednesday, April 7, 2021 10:34:58 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,334

Thanks: 822 times
Was thanked: 1099 time(s) in 1042 post(s)
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.
narshe
#3 Posted : Thursday, April 8, 2021 2:57:41 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/12/2013(UTC)
Posts: 10
Location: United States of America

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
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.
Remco
#4 Posted : Thursday, April 8, 2021 11:37:48 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,334

Thanks: 822 times
Was thanked: 1099 time(s) in 1042 post(s)
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.
narshe
#5 Posted : Friday, April 9, 2021 3:21:42 PM(UTC)
Rank: Member

Groups: Registered
Joined: 3/12/2013(UTC)
Posts: 10
Location: United States of America

Thanks: 2 times
Was thanked: 1 time(s) in 1 post(s)
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.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.241 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download