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

Notification

Icon
Error

DateOnly serialization issue with latest xunit
gieniowski
#1 Posted : Friday, July 21, 2023 6:23:11 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/21/2023(UTC)
Posts: 3
Location: Poland

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Hi, ncruch fails in the scenario described below.

xunit test:
public class UnitTest1
{
[Theory]
[MemberData(nameof(Inline))]
public void Test1(DateOnly date)
{
Assert.True(true);
}

public static IEnumerable<object[]> Inline()
{
yield return new object[] { DateOnly.MinValue };
}
}

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

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.3" />
<PackageReference Include="xunit" Version="2.5.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

</Project>


Error:
An error occurred while analysing this project after it was built: System.Exception: Error while discovering test 'TestProject2.UnitTest1.Test1("0001-01-01")':System.Exception: Type 'System.DateOnly' is not marked as serializable. Resolution path =
System.DateOnly

at nCrunch.Common.Serialization.SerializationContractType..ctor(UInt16 typeId, Type type, IList`1 fields, Boolean isMarshalByRefType, Boolean hasPotentialInheritors, SerializationPath path, Boolean wasAddedDynamically)
at nCrunch.Common.Serialization.SerializationContract.AddTypeToContract(Type instanceType, Boolean isAddedDynamically)
at nCrunch.Common.Serialization.BinarySerializer.writeNewContract(SerializationContext context, Type instanceType)
at nCrunch.Common.Serialization.BinarySerializer.lookupAndWriteContractType(SerializationContext context, Type instanceType)
at nCrunch.Common.Serialization.BinarySerializer.WriteInstance(SerializationContext context, Object instance, Type knownInstanceType, Boolean cacheCollectionContents)
at nCrunch.Common.Serialization.BinarySerializer.Serialize(SerializationContext context, Object instance, Type knownInstanceType, Boolean cacheInstance, Boolean cacheCollectionContents)
at nCrunch.Common.Serialization.CustomTypeSerializers.ObjectArraySerializer.Serialize(SerializationContext context, SerializationContractType type, Object value, Boolean cacheCollectionContents)
at nCrunch.Common.Serialization.BinarySerializer.WriteInstance(SerializationContext context, Object instance, Type knownInstanceType, Boolean cacheCollectionContents)
at nCrunch.Common.Serialization.BinarySerializer.Serialize(SerializationContext context, Object instance, Type knownInstanceType, Boolean cacheInstance, Boolean cacheCollectionContents)
at nCrunch.Common.Serialization.BinarySerializer.Serialize(BufferWriter writer, Object instance, Type knownInstanceType, Boolean cacheInstance)
at nCrunch.Module.XUnit2.XUnitBinarySerializer.Serialize(BufferStream stream, Object graph)
at nCrunch.TestExecution.Frameworks.XUnit2.TestCaseArgumentData.StoreInTest(FrameworkTest test)
at nCrunch.Module.XUnit2.Integration.XUnitNCrunchDiscoveredTestContainer.StoreDiscoveredTest(ITestCase testCase, TestName testName)
at nCrunch.Module.XUnit2.Integration.XUnitDiscoveryMessageSink.discoverTest(ITestCase testCase)
at nCrunch.Module.XUnit2.Integration.XUnit2DiscoveryEnvironment.FindFrameworkTestsInAssembly(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
at nCrunch.TestExecution.TestFinder.<>c__DisplayClass0_2.<FindTestsForFrameworks>b__1()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.TestExecution.TestFinder.<>c__DisplayClass0_0.<FindTestsForFrameworks>b__0()
at nCrunch.Common.PerformanceTracking.PerfTracker.TrackActivity(String name, Action activity)
at nCrunch.TestExecution.TestFinder.FindTestsForFrameworks(ReflectedAssembly assembly, FilePath assemblyFilePath, IList`1 referencedAssemblyFilePaths, DescribedTestFrameworkDiscoverer[] describedDiscoverers, ComponentUniqueName testComponentUniqueName, PlatformType platformType, DynamicProxy[] dynamicProxies)
at nCrunch.TestExecution.RemoteTaskRunner.AnalyseAssembly(DescribedTestFrameworkDiscoverer[] applicableFrameworks, ComponentUniqueName testComponentUniqueName, PerfTracker perfTracker, TaskLogId taskLogId)

It starts failing after updating xunit nugets to the latest version. It works with older xunit present in visual studio test template:
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Could be worth mentioning that visual studio test runner works without any problems with latest version.
Remco
#2 Posted : Friday, July 21, 2023 1:30:34 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
Hi,

Thanks for sharing this issue. I'll take a closer look and will get back to you soon.
gieniowski
#3 Posted : Friday, July 21, 2023 2:01:28 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/21/2023(UTC)
Posts: 3
Location: Poland

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Thanks Remco!

Just realized that I have forgot to mention that I am using visual studio 2022 and tried it with two versions of nCrunch: 4.17.0.7 and 4.18.0.3.
Remco
#4 Posted : Saturday, July 22, 2023 11:22:09 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 931 times
Was thanked: 1257 time(s) in 1170 post(s)
1 user thanked Remco for this useful post.
gieniowski on 7/22/2023(UTC)
gieniowski
#5 Posted : Saturday, July 22, 2023 12:20:21 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 7/21/2023(UTC)
Posts: 3
Location: Poland

Thanks: 1 times
Was thanked: 1 time(s) in 1 post(s)
Yup, did the test. Works now, thank you!
1 user thanked gieniowski for this useful post.
Remco on 7/23/2023(UTC)
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.075 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download