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

Notification

Icon
Error

Tests not running in signed assemblies/with security transparency
kentcb
#1 Posted : Saturday, April 15, 2017 8:32:43 AM(UTC)
Rank: Member

Groups: Registered
Joined: 2/10/2016(UTC)
Posts: 20
Location: Australia

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
Hi,

I'm converting another of my projects over to the new world of improved csproj + netstandard, and am seeing this error with NCrunch 3.7.0.4:

System.TypeInitializationException: The type initializer for 'KBCsv.CsvReader' threw an exception.
at KBCsv.CsvReader.FromCsvString(String csv)
at KBCsv.UnitTests.CsvReaderFixture.header_record_defaults_to_null() in C:\Users\Kent\Repository\KBCsv\Src\KBCsv.UnitTests\CsvReaderFixture.cs:line 187
System.IO.FileLoadException: Could not load file or assembly 'nCrunch.TestRuntime.DotNetCore, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. A strongly-named assembly is required. (Exception from HRESULT: 0x80131044)
at KBCsv.CsvReader..cctor()

If I disable signing of my assemblies then I get a different error:

System.TypeInitializationException: The type initializer for 'KBCsv.CsvReader' threw an exception.
at KBCsv.CsvReader.FromCsvString(String csv)
at KBCsv.UnitTests.CsvReaderFixture.header_record_cannot_be_set_if_passed_first_record() in C:\Users\Kent\Repository\KBCsv\Src\KBCsv.UnitTests\CsvReaderFixture.cs:line 224
System.MethodAccessException: Attempt by security transparent method 'KBCsv.CsvReader..cctor()' to access security critical method 'nCrunch.TestRuntime.TestCoverageEventListener.NCrunchExitMethod(Int32, Int32 ByRef, UInt32)' failed.
at KBCsv.CsvReader..cctor() in C:\Users\Kent\Repository\KBCsv\Src\KBCsv\CsvReader.cs:line 95

If I disable security transparency on my assemblies, then my tests execute fine.

How can I get my tests to run regardless of signing/security transparency?

Thanks
Remco
#2 Posted : Saturday, April 15, 2017 8:55:57 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for sharing this issue.

When NCrunch instruments your code, it adds a reference to nCrunch.TestRuntime.DotNetCore. This is not a signed assembly, which usually isn't a problem for .NET projects.

How has this project been configured? Is there any chance you can share its XML with me?
kentcb
#3 Posted : Saturday, April 15, 2017 9:25:17 AM(UTC)
Rank: Member

Groups: Registered
Joined: 2/10/2016(UTC)
Posts: 20
Location: Australia

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
Sure thing. But can you clarify exactly what you want me to share? The csproj for the assembly under test? For the unit test project?

Thanks
Remco
#4 Posted : Saturday, April 15, 2017 10:06:28 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
It looks like this is coming from the csproj under test, assuming that this is the assembly containing the CsvReader class. If you could share the contents of the .csproj, that would be extremely helpful.
kentcb
#5 Posted : Saturday, April 15, 2017 12:15:39 PM(UTC)
Rank: Member

Groups: Registered
Joined: 2/10/2016(UTC)
Posts: 20
Location: Australia

Thanks: 5 times
Was thanked: 2 time(s) in 2 post(s)
Yep - here you go:

Code:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard1.0</TargetFramework>
    <Version>1.0.0</Version>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <Authors>Kent Boogaart</Authors>
    <Company />
    <PackageLicenseUrl>https://github.com/kentcb/KBCsv/blob/master/LICENSE</PackageLicenseUrl>
    <PackageProjectUrl>https://github.com/kentcb/KBCsv</PackageProjectUrl>
    <PackageIconUrl>https://raw.githubusercontent.com/kentcb/KBCsv/master/Art/Logo64x64.png</PackageIconUrl>
    <RepositoryUrl>https://github.com/kentcb/KBCsv</RepositoryUrl>
    <PackageTags>.NET CSV comma separated value library netstandard portable KBCsv</PackageTags>
    <Description>KBCsv is an efficient, easy to use .NET parsing and writing library for the CSV (comma-separated values) format, delivered as a netstandard 1.0 library. Online at https://github.com/kentcb/KBCsv.</Description>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <SignAssembly>True</SignAssembly>
    <AssemblyOriginatorKeyFile>..\KBCsv.snk</AssemblyOriginatorKeyFile>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="Properties\ExceptionHelper.xml" />
  </ItemGroup>

  <ItemGroup>
    <Compile Include="..\AssemblyInfoCommon.cs" Link="Properties\AssemblyInfoCommon.cs" />
    <Compile Include="..\AssemblyInfoCommonSecurity.cs" Link="Properties\AssemblyInfoCommonSecurity.cs" />
  </ItemGroup>

  <ItemGroup>
    <EmbeddedResource Include="Properties\ExceptionHelper.xml" />
  </ItemGroup>
</Project>


PS. Is it just me, or are the BBCode icons for Code and Quote the wrong way around?
Remco
#6 Posted : Monday, April 17, 2017 11:00:40 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for sharing this. I haven't yet managed to reproduce the security issue, but I assume that this is tied to the nCrunch.TestRuntime.DotNetCore assembly not being signed. It appears that this assembly really should be signed in the same way as its sibling (nCrunch.TestRuntime.dll).

I've see about getting this included in the next release. For the time being, I recommend keeping the signing of your assemblies and security transparency disabled when running under NCrunch. It should be possible to do this using the #!NCRUNCH compiler directive around the attributes you're using to declare your security.
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.038 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download