BUG Compiler

G

Guest

Hi,

Repro:

Make a call to the Cursor ctor like this.Cursor = new Cursor(GetType(),
"SomeCur.cur");

DO NOT have the following line in the program... using System.Reflection;

Watch the Cursor ctro FAIL yet no compiler warning.

Add the using System.Reflection; reference

Build, again no compiler errror or warning (this time correctly) and call
the Cursor ctor, it succeeds.

Why no compiler warning or error?

Thanks.
 
N

Nicholas Paldino [.NET/C# MVP]

The line:

using System.Reflection;

Is not actually setting a reference, but rather, it is declaring the
shorthand for a namespace, which is different.

What is the error that you are getting when you call it?
 
G

Guest

ArgumentNullException.

Yet it is perfectly correct parameters. Works fine with the using
System.Reflection but craps out without it.



Nicholas Paldino said:
The line:

using System.Reflection;

Is not actually setting a reference, but rather, it is declaring the
shorthand for a namespace, which is different.

What is the error that you are getting when you call it?


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hi,

Repro:

Make a call to the Cursor ctor like this.Cursor = new Cursor(GetType(),
"SomeCur.cur");

DO NOT have the following line in the program... using System.Reflection;

Watch the Cursor ctro FAIL yet no compiler warning.

Add the using System.Reflection; reference

Build, again no compiler errror or warning (this time correctly) and call
the Cursor ctor, it succeeds.

Why no compiler warning or error?

Thanks.
 
H

Herfried K. Wagner [MVP]

* said:
Repro:

Make a call to the Cursor ctor like this.Cursor = new Cursor(GetType(),
"SomeCur.cur");

DO NOT have the following line in the program... using System.Reflection;

Watch the Cursor ctro FAIL yet no compiler warning.

Why should there be a compiler warning? You do not use any objects from
the 'System.Reflection' namespace.

Please do not make excessive use of X-posts.
 
A

Alvin Bruney

Obviously the Constructor for Cursor NEEDs it to get the resource numbnuts.

Jeez, even I can see that from the code.
 
W

Willy Denoyette [MVP]

IMO this has nothing to do with Reflection, take a look at your call stack,
probably your resource name is different from the one you used to embed the
cursor resource, resuling in a nullreference exception for the (embedded)
stream.

try this:

using System;
using System.Windows.Forms;
using System.Drawing;
namespace HelpCursor
{
class CursorForm : Form
{
static void Main()
{
CursorForm form = new CursorForm();
form.Text = "Hello";
form.BackColor = Color.Blue;
form.Paint += new PaintEventHandler(form.HelloPaintHandler);
Application.Run(form);

}
void HelloPaintHandler(object sender, PaintEventArgs args)
{
CursorForm form = sender as CursorForm;
Graphics grp = args.Graphics;
grp.DrawString("Setting help cursor", form.Font, Brushes.Black, 0, 0);
this.Cursor = new Cursor(GetType(), @"Help.Cur");
}
}
}

compile with : csc /t:winexe cursp1.cs /res:help,HelpCursor.Help.Cur
the help.cur file from the VS distribution(or any other cursor file).


Willy.
 
P

Pete Davis

First of all, with your attitude, you don't really deserve a response, but
Jon is likely to code it correctly. If the original poster has coded it
incorrectly, the only way to know is if he posts the code, numbnuts!


Alvin Bruney said:
why dont you just code what he said numbnuts
 
A

Alvin Bruney

Temper temper :p


Pete Davis said:
First of all, with your attitude, you don't really deserve a response, but
Jon is likely to code it correctly. If the original poster has coded it
incorrectly, the only way to know is if he posts the code, numbnuts!
 
1

100

Hi,
I haven't got this particular Cursor constructor working either. I think
there is some problem in the Cursor class.
Actually, I haven't tried hard.
To load a cursor from resource get the cursor resouce as a stream and use
Cursor's constructor which accepts
streams.

I don't see any reason to have "using System.Reflection" line since you
don't use any type defined in this namespace.

HTH
B\rgds
100
 
S

Stu Smith

You're the fake Alvin Bruney, right, as opposed to the clever one?
Can you keep your email constant so I don't have to keep adding you to my
kill-file?


Alvin Bruney said:
why dont you just code what he said numbnuts
 
A

Alvin Bruney

Yes sir overlord

whatever you say sir overlord.

3 bags full overlord


Stu Smith said:
You're the fake Alvin Bruney, right, as opposed to the clever one?
Can you keep your email constant so I don't have to keep adding you to my
kill-file?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top