question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MSTest v2.2.4 not working for some data tests: System.ArgumentException: Object of type 'System.Int32' cannot be converted to type 'System.UInt32

See original GitHub issue

Description

After upgrading to MSTest 2.2.4 I’m getting System.ArgumentException for data tests with some data types

Steps to reproduce

  • MSTest 2.2.4
  • Create this test:
[TestMethod]
[DataRow(0U)]
[DataRow(1U)]
[DataRow(2U)]
public async Task TestWithUint(uint index)
{
    //ellided
}

Expected behavior

  • Test to run without exceptions as prior to v2.2.4

Actual behavior

  • Getting the exception:
    System.ArgumentException: Object of type 'System.Int32' cannot be converted to type 'System.UInt32'.
  Stack Trace: 
    RuntimeType.TryChangeType(Object value, Binder binder, CultureInfo culture, Boolean needsSpecialCast)
    RuntimeType.CheckValue(Object value, Binder binder, CultureInfo culture, BindingFlags invokeAttr)
    MethodBase.CheckArguments(Object[] parameters, Binder binder, BindingFlags invokeAttr, CultureInfo culture, Signature sig)
    RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
    MethodBase.Invoke(Object obj, Object[] parameters)
    ThreadOperations.ExecuteWithAbortSafety(Action action)

Environment

Windows 21H1 build 19043.1023 VS 16.9.6

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
paul-michalikcommented, Jul 6, 2021

After 2.2.4, as long as the values in data source are serializable, every row for the specific test case is considered a separate test case. If our assumptions break parallel test runs that’s a regression. Is it possible for you to share a quick repro with us?

@Haplois I will share a complete project when I have more time, but in general, consider a test case like this:

[
  DataTestMethod,
  DynamicData(dynamicDataSourceName: nameof(GetData), DynamicDataSourceType.Method)
]
public async Task Create_Tasks_Requests_From_Invalid_Tasks_Definitions_Should_Return_BadRequest_Errors(Events.APIGatewayProxyRequest request, Requests.CreateTaskCommand.Arguments arguments)
{
    // test code
}

with GetData similar to this:

public static IEnumerable<object[]> GetData() =>
 new [] {
    new [] object {
         // initialize pair of objects
    },
    new [] object {
         // initialize pair of objects
    },
 }

If I run such test cases in parallel (method level parallelism) then I see all kinds of exception suggesting that the the test framework attempts to pull the enumerable on different threads. I have plenty of data sources structured like this:

public static IEnumerable<object[]> GetData()
{
    yield new InputData {
       // ...
    };

    yield new InputData {
       // ...
    };

    // etc.
}

These obviously can’t be pulled in parallel either.

0reactions
Haploiscommented, Jul 7, 2021

@paul-michalik thanks for reporting this. We’ll we working on fixing this. You can track it here #906.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - MSTest - DataTestMethod throws exception System. ...
I have a simple parameterized unit test in a .NET Core 3.1 test project (using MSTest) which runs successfully. It looks something like...
Read more >
Type issues with data driven tests in MSTest | Damir's Corner
ArgumentException : Object of type 'System.Decimal' cannot be converted to type 'System.Double'. The error was limited to tests with non-integer ...
Read more >
A brand new website interface for an even better experience!
MSTest v2.2.4 not working for some data tests: System.ArgumentException: Object of type 'System.Int32' cannot be converted to type 'System.UInt32.
Read more >
XUnit: Using TheoryData with Theory - Code and languages —
Multiple in the XUnit 2.4.2 assertion library. ... System.ArgumentException : Object of type 'System.Int32' cannot be converted to type ...
Read more >
C# 11 and . NET 7 - Modern Cross-Platform Development ...
Chapter 3: Controlling Flow, Converting Types, and Handling Exceptions ... Building websites using a content management system • 533.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found