MC++ FAQ
Monday 01 | 10 | 2005
Properties in the WinForms Application class won't return correct results
If you're coding Windows Forms applications in MC++, you might notice that even if you put it the right attributes on your assembly, several properties of the System::Windows::Forms::Application class don't return the correct results. This includes properties like Application::ProductInfo or Application::CommonAppDataPath.

The problem seems to be a bug in the implementation of the Application class:

The problem is that for MC++ assemblies (unless you do some really weird things) there's not an "Entry Type" in the sense there is for C# or VB.NET. By Entry Type I mean a class where the Main() method is defined, but rather the entry point is a global function.

The problem is that the rest of the stuff that's missing in there is acquired in the Application class from the attributes in the assembly. However, it goes around it in an ugly way:

Instead of simply finding out what assembly started the process and looking at the custom attributes defined in it, it does something like this:

  • Find the assembly that started the process
  • Ask the assembly for the entry type
  • Ask the entry type for the assembly it is defined in
  • Ask that latter reference for the attributes.

Of course, in MC++ everything goes down the drain in the second step, because that entry type will be null, so no way to ask for the rest of the attributes.

That said, all the Application class does is provided easier access to the information encoded in the assembly's attributes. Given that, you can always work around this problem by directly using System::Reflection (using Assembly::GetCustomAttribute()) to query the attribute values yourself.

Note: This has been fixed in Visual C++ 2005 in the .NET Framework and C++/CLI..

Posted by tomasr at January 10, 2005 09:12 PM
Copyright(C) 2002, Tomas Restrepo, All rights reserved. Powered by Movable Type 2.63