When I compile the following code with the C++ compiler version
14.00.50215.44 (Microsoft Visual Studio 2005 beta 2) using the command line
'cl -W4 -clr:oldSyntax test.cpp' at run time I get a Null Reference Exception
due to the dynamic_cast. With the C++ compiler version 13.10.3077 from Visual
Studio 2003 using the command line 'cl -W4 -clr test.cpp' no such error is
generated.
#using <mscorlib.dll >
using namespace System;
using namespace System::Reflect ion;
using namespace System::Runtime ::InteropServic es;
public __gc class AttributesSampl e
{
public:
void Mymethod (int, [Out] String** str2m, String**)
{
*str2m = S"in Mymethod";
}
};
void PrintAttributes (Type* attribType, int iAttribValue)
{
if (attribType->IsEnum)
{
FieldInfo* fields[] =
attribType->GetFields(stat ic_cast<Binding Flags>(BindingF lags::Public |
BindingFlags::S tatic));
for (int i = 0; i < fields->Length; i++)
{
int fieldvalue = *dynamic_cast<I nt32*>(fields[i]->GetValue(0)) ;
//exception here
if ((fieldvalue & iAttribValue) == fieldvalue)
{
Console::WriteL ine(fields[i]->Name);
}
}
}
}
int main()
{
Type* MyType = Type::GetType(S "AttributesSamp le");
MethodBase* Mymethodbase = MyType->GetMethod(S"My method");
MethodAttribute s Myattributes = Mymethodbase->Attributes;
PrintAttributes (__typeof(Syste m::Reflection:: MethodAttribute s), (int)
Myattributes);
return 0;
}
Is this a bug? 5 1280
Hi Paul! When I compile the following code with the C++ compiler version 14.00.50215.44 (Microsoft Visual Studio 2005 beta 2) using the command line 'cl -W4 -clr:oldSyntax test.cpp' at run time I get a Null Reference Exception due to the dynamic_cast. With the C++ compiler version 13.10.3077 from Visual Studio 2003 using the command line 'cl -W4 -clr test.cpp' no such error is generated.
It does not matter if you use the command-line or the IDE.
#using <mscorlib.dll >
using namespace System; using namespace System::Reflect ion; using namespace System::Runtime ::InteropServic es;
public __gc class AttributesSampl e { public: void Mymethod (int, [Out] String** str2m, String**) { *str2m = S"in Mymethod"; } };
void PrintAttributes (Type* attribType, int iAttribValue) { if (attribType->IsEnum) { FieldInfo* fields[] = attribType->GetFields(stat ic_cast<Binding Flags>(BindingF lags::Public | BindingFlags::S tatic)); for (int i = 0; i < fields->Length; i++) { int fieldvalue = *dynamic_cast<I nt32*>(fields[i]->GetValue(0)) ; //exception here if ((fieldvalue & iAttribValue) == fieldvalue) { Console::WriteL ine(fields[i]->Name); } } } }
int main() { Type* MyType = Type::GetType(S "AttributesSamp le"); MethodBase* Mymethodbase = MyType->GetMethod(S"My method"); MethodAttribute s Myattributes = Mymethodbase->Attributes; PrintAttributes (__typeof(Syste m::Reflection:: MethodAttribute s), (int) Myattributes); return 0; }
Is this a bug?
It seems to be!
The problem is that the VC2003 compiler generated the following IL-code:
<snipped>
obj1 = infoArray1[num1].GetValue(null) ;
int num1 = (int) obj1;
</snipped>
And the VC2005 B2 compiler /with /oldsyntax) generates:
<snipped>
obj1 = infoArray1[num1].GetValue(null) ;
int num1 = *(!(obj1 is int) ? 0 : ((int) obj1));
</snipped>
So please report a (detailed!) bug-report at: http://lab.msdn.microsoft.com/productfeedback/
If you do not want to do this, please let me know, than I can do it for you.
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/ Is this a bug? It seems to be!
But it looks like a bug in the VC2003 compiler!
Because "dynamic_ca st" should excatly do what the VC2005 compiler is doing:
Check if the object has the correct type (or derived) and then cast it
to this type or return "null".
The problem is that the VC2003 compiler generated the following IL-code:
<snipped> obj1 = infoArray1[num1].GetValue(null) ; int num1 = (int) obj1; </snipped>
This is wrong...
And the VC2005 B2 compiler /with /oldsyntax) generates:
<snipped> obj1 = infoArray1[num1].GetValue(null) ; int num1 = *(!(obj1 is int) ? 0 : ((int) obj1)); </snipped>
This is correct.
But it should be documented in the "breaking-changes"...
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/
Hi Jochen,
Thanks for the reply. Although I found the problem first in my own code I
based it on the sample code (and reproduced it in the sample code as well).
The sample code is at: http://msdn.microsoft.com/library/de...eldsTopic2.asp.
Therefore it looks like this sample code is wrong.
I have submitted a bug report anyway.
Regards,
Paul.
Hi Paul! I have submitted a bug report anyway.
Can you please post the link, so other people can easily find it...
--
Greetings
Jochen
My blog about Win32 and .NET http://blog.kalmbachnet.de/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: AJ |
last post by:
Have I just wasted money on buying VS.NET Beta 2?
I can run the start page but as soon as I try to load a
solution file, I get an error within the Microsoft
Development Environment as the Common Language Runtime
isn't loaded. No samples work from MSDN CD, MSDN
WebSite, Other WebSites Samples, nothing seems to work.
I was hoping to start getting to grips with .NET using
this beta thingy and if it was any good, I was going to
|
by: Prasad |
last post by:
Hello EveryBody,
I am using cvs as my version control tool, I came accross CVS SCC plugin for Microsoft Visual Studio name "Jalindi Igloo" I plan to develop a tool like this, but have no idea to start with. After surfing on the web sites i found Microsoft SCC API is used to develop such tools, any idea on how to get this API and start the devlopment of this tool, Also links to sample source codes will do.
Thanx
Prasad
|
by: Benjamin.Nitschke |
last post by:
Today I installed Microsoft Visual Studio 2005 Beta 2 from the Visual
Studio Beta Experience Kit. After installing (which takes way to long)
when I open Visual Studio 2005 I only get a message box saying "A
problem was encountered loading the Microsoft Visual Studio menu.
Please run setup and select Repair". I did that and that took another
hour to install and I still got the same problem. Can't see any log
file or system event message...
|
by: Eric Sassaman [MS] |
last post by:
Online Chat: Visual C++ 2005 Beta
Join the Visual C++ team to discuss your questions and comments on the Beta
release of Visual C++ 2005. Whether you are a first-time user of the Visual
C++ Express Edition Beta (http://lab.msdn.microsoft.com/express/visualc) or
an experienced developer exploring the full Visual Studio 2005 suite, we
want to answer your questions to provide you with a smooth development
experience. So please bring your...
|
by: Jason Shohet |
last post by:
I'm using Visual Studio, with ASP.NET. Is VSS on a separate CD.
Also, is it possible to use the VSS beta (2005) with .NET if I'm not using
the .NET beta.
And finally, where do I get the VSS beta... when I go to msdn, it just
directs me to a page with Whidbey downloads.... nothing mentioned on VSS
TY
Jason Shohet
| |
by: Maury |
last post by:
I just downloaded .Net Framework Beta2 and Visual Web Developer Express
Edition Beta and Visual C# Express Edition.
I installed .Net Framework Beta2, then I installed
Visual Web Developer Express Edition Beta but the installation failed
because the installation package can't find the Beta 2 (?).
So I tried to install Visual C# Express Edition and all is ok
(it works fine)
I tried to reinstall Beta2 and
|
by: Dr. Zharkov |
last post by:
Hello. To see the graphics of technology DirectX 9.0 SDK Update - June 2005
in project Visual Basic, WindowsApplication1 from Visual Studio 2005 Beta 1,
in file My Project, MyApplication.vb in a method:
<Global.System.Diagnostics.DebuggerStepThrough()> _
Protected Overrides Sub OnCreateMainForm()
|
by: interwanderer |
last post by:
something very odd...
I have installed visual studio 2005 on my machine.
I created a console application with visual basic 2005 or C#.
I typed something in. tried to delete.. but i couldn't
I can't use enter, delete or tab for some odd reason....
this works perfectly fine with visual studio 6 and visual studio.net 2003 on
the same machine
|
by: micky |
last post by:
i've download vs studio team suite
but it look like beta 2 CTP versio such as folder structure..
there are msdn, visio, vs ,vss folder
and to check version this iso file i opened setup.ini
and then i found the following text....
it says "Visual Studio® 2005 Beta 2 Setup" as banner name value
Ver=8.0
|
by: nhmark64 |
last post by:
Hi,
What is the relationship between "Microsoft .NET Framework 3.5 –
Beta 1" and "Visual Studio Code Name "Orcas" Beta 1"? Should I
install 1 first than the other, or just 1? I need to start a C# LINQ
project for my job.
Thanks,
Mark
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |