By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,995 Members | 1,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,995 IT Pros & Developers. It's quick & easy.

How can I get rid of "warning CS0649 : field is never assigned to"

P: n/a
I have a series of class variables that are assigned to through
reflection. Every time I compile one of these classes I get this
warning :

warning CS0649: Field 'xxx' is never assigned to, and will always have
its default value null

Is there any way I can supress this warning? I have a custom attribute
applied to each field, which the binder uses, and am explicitly
assigning to null. I would like to remove the '=null;' if I can.

[BindMe] protected TextBox theText = null;

ASP.Net pages do not have this problem when you place controls on them,
so I think this may be possible. The only post addressing this
directly is from 2002, and in this group.

I was hoping for something like [CompilerDisableWarning(649)] that I
could apply to my custom attributes.

Thanks for any help,
- Andrew Backer

Nov 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Andrew Backer wrote:
I have a series of class variables that are assigned to through
reflection. Every time I compile one of these classes I get this
warning :

warning CS0649: Field 'xxx' is never assigned to, and will always have
its default value null

Is there any way I can supress this warning? I have a custom attribute
applied to each field, which the binder uses, and am explicitly
assigning to null. I would like to remove the '=null;' if I can.

[BindMe] protected TextBox theText = null;

ASP.Net pages do not have this problem when you place controls on them,
so I think this may be possible. The only post addressing this
directly is from 2002, and in this group.

I was hoping for something like [CompilerDisableWarning(649)] that I
could apply to my custom attributes.

Thanks for any help,
- Andrew Backer

not sure for c#, but in visual c you can #pragma disable warning(CS0649)
I don't remember the syntax, but that's the idea...

you may try to look up how to do that in c#

marcel
Nov 17 '05 #2

P: n/a
Yes, there is something similar for c#, I think you even have the
syntax correct :)

I don't want to stick pragmas like that in each class that does this,
though. The current work aorund is to just assign = null.

I am hoping that there is some language/framework feature that will let
me disable this warning in much the same way custom attributes work. I
could then combine my attribute with this base, and be able to ignore
individual fields by tagging them...

[BindMe]
[IgnoreWarning(964)]
protected TextBox myField;

[BindMeAndIgnoreWarnings]
protected TextBox myField;

There must be a clever way to do this, since aspx pages do it. Perhaps
there is some other detail that I am missing that makes this not apply?
Any smartie from MS have any clues?

- Andrew

Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.