473,473 Members | 1,847 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

strange compile error for a simple example bug??

Hello!

I have a very simple example below. The problem is that I get the following
compile error
Error 1 Cannot implicitly convert type 'System.Reflection.MemberInfo[]' to
'MemberInfo[]' F:\C#\ConsoleApplication12\ConsoleApplication12\Me mberInfo.cs
27 46 ConsoleApplication12

I can't understand why I get this compile error because according to the
documentation it should work.
Is this a bug perhaps ??

class MemberInfo
{
int MYVALUE;

public void THIS_IS_A_METHOD()
{}

public int myValue
{
set { MYVALUE = value; }
}

static void Main(string[] args)
{
string testclass = "MemberInfo";
Console.WriteLine("\nFöljande är medlemsinfo för klassen:{0}",
testclass);

Type MyType = Type.GetType(testclass);

MemberInfo[] Mymemberinfoarray = MyType.GetMembers();
}
}

//Tony
Oct 8 '08 #1
2 1363
Well you named your class memberInfo.

It's saying System.Reflection.MemberInfo does not cast into
MyNamespace.MemberInfo.

MemberInfo[] Mymemberinfoarray = MyType.GetMembers();

should be

System.Reflection.MemberInfo[] Mymemberinfoarray =
MyType.GetMembers();
Oct 8 '08 #2
Tony Johansson <jo*****************@telia.comwrote:
I have a very simple example below. The problem is that I get the following
compile error
Error 1 Cannot implicitly convert type 'System.Reflection.MemberInfo[]' to
'MemberInfo[]' F:\C#\ConsoleApplication12\ConsoleApplication12\Me mberInfo.cs
27 46 ConsoleApplication12

I can't understand why I get this compile error because according to the
documentation it should work.
Is this a bug perhaps ??
Well it's a bug, but in your code. You've declared a class called
"MemberInfo". That means whenever you refer to the name "MemberInfo" in
your code, it will mean *your* class.

Now Type.GetMembers returns an array with elements
System.Reflection.MemberInfo, which is unrelated to your MemberInfo
class - so you can't cast from one to the other.

I strongly suggest you change the name of your class to avoid it
conflicting with types in the framework.

--
Jon Skeet - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com
Oct 8 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil | last post by:
Hi, I don't understand this strange behaviour: I compile this code : #include <Python.h> #include"Numeric/arrayobject.h" static PyObject *
6
by: leonecla | last post by:
Hi everybody, I'm facing a very very strange problem with a very very simple C program... My goal should be to write to a binary file some numbers (integers), each one represented as a sequence...
6
by: Mårten Herberthson | last post by:
Introduction: As we all know, values of any class may be assigned to a reference of a superclass. This is simple polymorphism. So if you have a class A and a class B that inherits from A you can...
1
by: pitjpz | last post by:
We have moved our Database to another server. The server it was on used SQL 4 and the new one its on now uses SQL5 the only problem we can find is that when you attempt to delete a record from...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.