473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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

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
2 19309
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: H. S. | last post by:
Hi, I am trying to compile the examples in arpack++ library on x86 Linux (flavor of Red Hat) running 2.4.24 kernel and g++ (3.2 20020903 version). Here is part of the compiler error I am...
2
by: Lateralus | last post by:
headers/vector3.h: In member function ‘Vector3 Vector3::operator*(Scalar)’: headers/vector3.h:13: error: no matching function for call to ‘Vector3::Vector3(Vector3)’...
2
by: MLH | last post by:
I have a form that ALWAYS prompts me as to whether I want to save the changes - every time I open it in design view - even if I don't make ANY changes. Why might that be?
1
by: Hans Nieser | last post by:
I was wondering wether it was normal that I get "field is never assigned to" warnings after defining a struct but not having actually referred to it in my code yet. Is this just something I'll have...
7
by: Olaf Baeyens | last post by:
I am testing VC++ 2005 and I get this warning: "warning C4996: 'strncpy' was declared deprecated" Does that mean that they might be phased out in VC++ 2006 or higher? Or does an alternative...
4
by: Steven | last post by:
Hi all, I have a solution with a VB.net project, and a installer-project. When I build the solution, I get the following message; WARNING: Language ID '0' not supported. To the installer...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: session_start(): Cannot send session cache...
3
by: neolempires2 | last post by:
hi..i'm new in sql progaming, i try to make make a query that in table field "match" return to "1" if no member record in another table and return to "0" if there is any record member : ex...
2
by: Fresh | last post by:
Hi, I met a problem, when I change warning level to 4 and to track warning as error, then a link warning show "warning LNK4075: ignoring '/INCREMENTAL' due to '/OPT:ICF' specification" I...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.