S
Sergey Golovkin via .NET 247
Hi
I have very strange situations.
The following code always crashes any .Net appication that uses it.
What I have:
1. The Managed C++ code (test.h and test.cpp) that defines enumeration "Els" and function that returns an array of values of this enum "Els" as output parameter "outParam".
-------------------------------- test.h --------------------------
#pragma once
using namespace System::Runtime::InteropServices;
#define V_OK 17235968
#define V_HALT 17235969
#define V_CRASH 17235970
namespace managedC
{
public __value enum Els : unsigned int
{
Ok = V_OK,
Halt = V_HALT,
Crash = V_CRASH
};
public __gc class testClass
{
public:
static void TestMethodEnum([OutAttribute] Els (*outParam)[]);
};
}
-------------------------------- test.h --------------------------
-------------------------------- test.cpp --------------------------
#include "test.h"
#using <mscorlib.dll>
namespace managedC
{
void testClass::TestMethodEnum([OutAttribute] Els (*outParam)[])
{
*outParam = new Els[2];
for(int i = 0; i < (*outParam)->Length; i++)
(*outParam) = Els::Crash;
}
}
-------------------------------- test.cpp --------------------------
2. The C# code that has infinite loop and calls method "TestMethodEnum" inside.
-------------------------------- test.cs --------------------------
using System;
using System.Collections;
using managedC;
namespace marshalBug
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
for(int i = 0; ; i++)
{
Els[] paramEnum;
testClass.TestMethodArray(out paramEnum);
foreach(Els t in paramEnum)
Console.WriteLine(t);
GC.Collect();
}
}
}
}
-------------------------------- test.cs --------------------------
This code works only one circle until GC.Collect(). The CG crashes.
Who can me say what is this ? Is this a bug in compiler ?
Are there anybody who have the same situalion ?
Thanks
ps:
Are there any fixes or SP for VC 2003 ?
I have very strange situations.
The following code always crashes any .Net appication that uses it.
What I have:
1. The Managed C++ code (test.h and test.cpp) that defines enumeration "Els" and function that returns an array of values of this enum "Els" as output parameter "outParam".
-------------------------------- test.h --------------------------
#pragma once
using namespace System::Runtime::InteropServices;
#define V_OK 17235968
#define V_HALT 17235969
#define V_CRASH 17235970
namespace managedC
{
public __value enum Els : unsigned int
{
Ok = V_OK,
Halt = V_HALT,
Crash = V_CRASH
};
public __gc class testClass
{
public:
static void TestMethodEnum([OutAttribute] Els (*outParam)[]);
};
}
-------------------------------- test.h --------------------------
-------------------------------- test.cpp --------------------------
#include "test.h"
#using <mscorlib.dll>
namespace managedC
{
void testClass::TestMethodEnum([OutAttribute] Els (*outParam)[])
{
*outParam = new Els[2];
for(int i = 0; i < (*outParam)->Length; i++)
(*outParam) = Els::Crash;
}
}
-------------------------------- test.cpp --------------------------
2. The C# code that has infinite loop and calls method "TestMethodEnum" inside.
-------------------------------- test.cs --------------------------
using System;
using System.Collections;
using managedC;
namespace marshalBug
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
for(int i = 0; ; i++)
{
Els[] paramEnum;
testClass.TestMethodArray(out paramEnum);
foreach(Els t in paramEnum)
Console.WriteLine(t);
GC.Collect();
}
}
}
}
-------------------------------- test.cs --------------------------
This code works only one circle until GC.Collect(). The CG crashes.
Who can me say what is this ? Is this a bug in compiler ?
Are there anybody who have the same situalion ?
Thanks
ps:
Are there any fixes or SP for VC 2003 ?