site/xunit.analyzers/rules/xUnit1047.md
A violation of this rule occurs when a value passed to the TheoryDataRow constructor might not
be serializable.
Non-serializable data makes it impossible for the developer to run individual data rows inside of Visual Studio's Test Explorer.
To fix a violation of this rule, use data that is known to be serializable. This includes all the
supported built-in types (listed below) or any type which implements IXunitSerializable, as well as
arrays of any supported type and nullable versions of any supported value type. A type might or
might not be serializable if it's an interface (that does not derive from IXunitSerializable)
or an unsealed class or struct (that does not implement IXunitSerializable).
Developers using build 0.6.0 or later can also implement an external serializer by implementing
IXunitSerializer and registering it in their test assembly. For more information, see
the v3 documentation on custom serialization.
Supported built-in types (as of v3 0.5.0) include:
BigIntegerboolbyte and sbytecharDateTime, DateTimeOffset, and TimeSpanDateOnly and TimeOnly (.NET 8+ only)decimalfloat and doubleGuidIndex and Range (.NET 8+ only)int and uintlong and ulongshort and ushortstringTypeUriVersionAdditional built-in types supported for v3 (as of 0.5.0) include:
GuidIndex and Range (.NET 8+ only)UriVersionusing System;
using Xunit;
public class MyClass
{
public TheoryDataRow GetDataRow()
{
IDisposable disposableValue = GetDisposableValue();
return new TheoryDataRow(disposableValue);
}
}
using System;
using Xunit;
using Xunit.Sdk;
public interface IDisposableSerializable : IDisposable, IXunitSerializable { }
public class MyClass
{
public TheoryDataRow GetDataRow()
{
IDisposableSerializable disposableValue = GetDisposableValue();
return new TheoryDataRow(disposableValue);
}
}