K
Karthik Vazhkudai
I have a class defined in VC.NET with the following code:
namespace AlertSystem
{
public __value class CFilterRegion
{
public:
System::Int16 X1;
System::Int16 Y1;
System::Int16 X2;
System::Int16 Y2;
System::Int16 X3;
System::Int16 Y3;
System::Int16 X4;
System::Int16 Y4;
}
I then import this alertsystem namespace in a VB.NET project and then
try to set the values of an object instantiated from the above
CFilterRegion class. The code is as below:
Dim obj2 As New CFilterRegion
Dim t As Type = GetType(CFilterRegion)
Try
t.InvokeMember("X1", BindingFlags.SetField, Nothing, obj2,
New Object() {666})
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
But an error is thrown stating that "Object type cannot be converted
to target type".
The weird thing is that when I define my CFIlterRegion class within
the same VB project (instead of importing from a VC.NET project) the
InvokeMember works fine for both SetField and GetField.
I would appreciate if anyone can throw some light on this issue that I
am having.
Thanks,
Karthik
namespace AlertSystem
{
public __value class CFilterRegion
{
public:
System::Int16 X1;
System::Int16 Y1;
System::Int16 X2;
System::Int16 Y2;
System::Int16 X3;
System::Int16 Y3;
System::Int16 X4;
System::Int16 Y4;
}
I then import this alertsystem namespace in a VB.NET project and then
try to set the values of an object instantiated from the above
CFilterRegion class. The code is as below:
Dim obj2 As New CFilterRegion
Dim t As Type = GetType(CFilterRegion)
Try
t.InvokeMember("X1", BindingFlags.SetField, Nothing, obj2,
New Object() {666})
Catch ex As Exception
Debug.WriteLine(ex.Message)
End Try
But an error is thrown stating that "Object type cannot be converted
to target type".
The weird thing is that when I define my CFIlterRegion class within
the same VB project (instead of importing from a VC.NET project) the
InvokeMember works fine for both SetField and GetField.
I would appreciate if anyone can throw some light on this issue that I
am having.
Thanks,
Karthik