Home
Home copied to clipboard
Reflection within the .GetParameters() incorrectly resolves array types
Library/API/IoT binding
System
Visual Studio version
VS2022 17.2.1
.NET nanoFramework extension version
No response
Target name(s)
ST_NUCLEO144_F746ZG, M5Core2
Firmware version
1.8.0.112, 1.8.0.323
Device capabilities
No response
Description
When using reflection to get the constructors parameters. The IsArray method is always false. See code comments below:
How to reproduce
This code will run on the full dotnet stack perfectly but always return false on nanoFramework. No matter what type of array is defined the 'isArray' method is always false.
Expected behaviour
This code should output to the debug window 'true'. As the constructor parameters included an array of bytes 'byte[] bytes'.
Screenshots
No response
Sample project or code
using System;
using System.Diagnostics;
using System.Reflection;
namespace nanoFramework.Simple
{
public class Program
{
public static void Main()
{
ConstructorInfo[] constructors = (typeof(ClassWithPrimitiveArrayBinding)).GetConstructors();
foreach (ConstructorInfo constructor in constructors)
{
foreach (ParameterInfo parameter in constructor.GetParameters())
{
// This should return true as the bytes parameter is an array
Debug.WriteLine(parameter.ParameterType.IsArray.ToString());
}
}
}
public class ClassWithPrimitiveArrayBinding
{
public byte[] Bytes { get; set; }
// This constructor includes a byte array
public ClassWithPrimitiveArrayBinding(byte[] bytes)
{
Bytes = bytes;
}
}
}
}
Aditional information
No response