I have a strange issue with the is and as Operator in NETMF (V4.3).
I have a class with an property Data of type object.
This property can contain a string, a Byte[] or an class that can implement specific Interface, lets call it IMyData
When I now do a safe cast of Data to IMyData, I would expect to get null if Data containas a Byte[].
But I actually do not get null.
When I hover the local variable in the Debugger I see the Byte Array.
But when I then call a Interface method I get an CLR_WRONG_TYPE exception.
Here some Code to reproduce
public Interface IMyInterface
{
bool SomeProperty { get; }
}
public class SomeClass
{
public object Data { get; set; }
public void SomeMethod()
{
var myData = Data as IMyInterface; // if data contains a Byte[] I would expect the result to be null, but it isn't
if (myData != null) // this check return true
{
if(myData.SomeProperty) // this throws a System.Exception CLR_WRONG_TYPE
{
//...
}
}
}
//...
var x = new SomeClass();
x.Data = new byte[5];
x.SomeMethod();
if I type “Data is IEnumerable” or any class in the intermediate window, I always get true. If I type “Data is int[]” I get false as expected.
Would be greate if anyone could confirm this, then I will Report it to the NETMF team.
I use VS2015, but switched back to the old Compiler instead of rosslyn.
My Device is a custom G120 board with FW V4.3.6 (I know it’s not the latest, but this should not make any difference here)
Also Debug or Release makes no difference.