Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / June 2005

Tip: Looking for answers? Try searching our database.

Compiler bug in VC++ .Net 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sergey Golovkin - 06 Jun 2005 13:57 GMT
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 ?
Jochen Kalmbach [MVP] - 06 Jun 2005 14:11 GMT
Hi Sergey!
>     void testClass::TestMethodEnum([OutAttribute] Els (*outParam)[])
>     {
[quoted text clipped - 3 lines]
>             (*outParam) = Els::Crash;
>     }

You should replace the line
  (*outParam) = Els::Crash;
with
  (*outParam)[i] = Els::Crash;

Signature

Greetings
  Jochen

   My blog about Win32 and .NET
   http://blog.kalmbachnet.de/

mapi33dev - 06 Jun 2005 15:05 GMT
Hi Jochen

Of course this line is :
           (*outParam)[i] = Els::Crash;

BUT FORUM WEB UI REPLACES IT TO SMILE :-((

-------------------------------- 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)[i] = Els::Crash;
   }
}
-------------------------------- test.cpp --------------------------
-------------------------------- 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 --------------------------

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.