xunit
xunit copied to clipboard
Object of type 'System.Int32' cannot be converted to type 'System.Nullable`1[System.Int64]'.
Description
Just updated xunit and xunit.runner.visualstudio, and now some tests that were working with the previous versions, are throwing an exception saying that they can't convert an int from the InlineData to a long? which is a parameter of the test.
xunit 2.4.1 > 2.4.2 xunit.runner.visualstudio 2.4.3 > 2.4.5
Steps to reproduce
Fails after upgrade
[Theory] [InlineData(1)] public void GetUserAsync(long? userId) { Assert.NotNull(userId); }
However, if I specify that the value is a long (1L), it will work
[Theory] [InlineData(1L)] public void GetUserAsync(long? userId) { Assert.NotNull(userId); }
Exception
System.ArgumentException
Object of type 'System.Int32' cannot be converted to type 'System.Nullable1[System.Int64]'. at System.RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast) at System.RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr) at System.Reflection.MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig) at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters) at Xunit.Sdk.TestInvoker
1.CallTestMethod(Object testClassInstance) in //src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 150
at Xunit.Sdk.TestInvoker1.<>c__DisplayClass48_0.<<InvokeTestMethodAsync>b__1>d.MoveNext() in /_/src/xunit.execution/Sdk/Frameworks/Runners/TestInvoker.cs:line 257 --- End of stack trace from previous location where exception was thrown --- at Xunit.Sdk.ExecutionTimer.AggregateAsync(Func
1 asyncAction) in //src/xunit.execution/Sdk/Frameworks/ExecutionTimer.cs:line 48
at Xunit.Sdk.ExceptionAggregator.RunAsync(Func`1 code) in /_/src/xunit.core/Sdk/ExceptionAggregator.cs:line 90
Duplicate of https://github.com/xunit/xunit/issues/2572