When I try to run it from Test Explorer with MTP enabled, I see the following warning in the Test Output window:
\nError creating theory test case for for 'WhenCreateDataCollection.AndCounterIsSupported_ReturnsCollectionWithCounterType'; falling back to single test case. Exception message: 'Cannot serialize type 'System.Diagnostics.PerformanceCounterType' because it lives in the GAC Parameter name: value'
I thought I could fix the warning by creating a custom IXunitSerializer
. When I step through the test in the debugger it hits my breakpoint in the call to IsSerializable
(which returns true
), but it never hits my breakpoint in the Serialize
method and I still get the warning. This is what my serializer looks like:
public class PerformanceCounterTypeSerializer : IXunitSerializer\n{\n public Boolean IsSerializable(Type type, Object value, out String failureReason)\n {\n if (type == typeof(PerformanceCounterType))\n {\n failureReason = null;\n return true;\n }\n\n failureReason = $\"Theory data of type {type.FullName} is not currently supported.\";\n return false;\n }\n\n public String Serialize(Object value)\n {\n if (value is PerformanceCounterType performanceCounterType)\n {\n return performanceCounterType.ToString();\n }\n\n throw new NotSupportedException($\"Custom serialization (of type {value.GetType().FullName}) is not currently supported.\");\n }\n\n public Object Deserialize(Type type, String value)\n {\n if (type == typeof(PerformanceCounterType))\n {\n return (PerformanceCounterType)Enum.Parse(typeof(PerformanceCounterType), value);\n }\n\n throw new NotSupportedException($\"Custom deserialization (of type {type.FullName}) is not currently supported\");\n }\n}\n
I assume the custom serializer was registered properly because otherwise my IsSerializable
method wouldn't be called. Am I doing something else wrong? Is there a better way to handle this kind of test data?
I am able to reproduce this with
\n[assembly: RegisterXunitSerializer(typeof(PerformanceCounterTypeSerializer), typeof(PerformanceCounterType))]
This is caused by inappropriate GAC-checking code in TypeHelper.GetTypeName
, logic which should've been solely relegated to EnumSerializer
.
This is fixed by 4f4077c and available in v3 2.0.1-pre.6
https://xunit.net/docs/using-ci-builds
-
I have a test that looks like this:
When I try to run it from Test Explorer with MTP enabled, I see the following warning in the Test Output window:
I thought I could fix the warning by creating a custom
I assume the custom serializer was registered properly because otherwise my |
Beta Was this translation helpful? Give feedback.
-
I am able to reproduce this with [assembly: RegisterXunitSerializer(typeof(PerformanceCounterTypeSerializer), typeof(PerformanceCounterType))] This is caused by inappropriate GAC-checking code in This is fixed by 4f4077c and available in v3 |
Beta Was this translation helpful? Give feedback.
I am able to reproduce this with
This is caused by inappropriate GAC-checking code in
TypeHelper.GetTypeName
, logic which should've been solely relegated toEnumSerializer
.This is fixed by 4f4077c and available in v3
2.0.1-pre.6
https://xunit.net/docs/using-ci-builds