Closed as duplicate of#1462
Description
Describe the bug
Using a nested type like this in a DataRow:
object obj = new object[]
{
(byte)0,
new object[]
{
(short)597,
(short)492
},
new object[0],
(byte)0,
(byte)0,
"\u0001"
};
All the Bytes and Shorts become Int32's
Steps To Reproduce
[TestClass]
public class DataRowTest
{
[DataTestMethod]
// These get corrupted
[DataRow((byte)0, new object[] { (byte)0 })] // fails
[DataRow((short)0, new object[] { (short)0 })] // fails
[DataRow((long)0, new object[] { (long)0 })] // fails
// [DataRow((int)0, new object[] { (byte)0 })] // Succeeds while it should fail
public void CheckNestedInputTypes(object org, object nested)
{
Assert.IsTrue(org.GetType().Name.Equals(((object[])nested)[0].GetType().Name), // nested: fails, type changed to Int32
string.Concat("Expected ", org.GetType().Name, " but got ", ((object[])nested)[0].GetType().Name));
}
[DataTestMethod]
// These work correctly:
[DataRow((byte)0, (byte)0)] // Succeeds (correct)
[DataRow((short)0, (short)0)] // Succeeds (correct)
// [DataRow((int)0, (byte)0)] // Fails (correct)
public void CheckInputTypes(object org, object nested)
{
Assert.IsTrue(org.GetType().Name.Equals(nested.GetType().Name)); // not nested, works fine
}
}
Expected behavior
I expect bytes, shorts and longs to stay bytes, shorts and longs and not upgrade/downgrade to Int32.
Actual behavior
Anything smaller than Int32 gets upgraded, for larger types it depends on the value if they get downgraded or not.
Additional context
Ran into this bug when migrating my MsgPack project to NetStandard2.1 and migrating this test to MSTest instead of NUnit (hoping to get a smoother integrated experience in Visual Studio). The NUnit version worked fine by the way.