473,325 Members | 2,870 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,325 software developers and data experts.

Compiler bug on field assignment

If ExecuteQuery method sets fields, C# 3.5 compiler issues invalid warning
at compile time:

Field '... .Contents' is never assigned to

To reproduce, create class

class Entity<T>
{
public T Contents;
}

and compile lines

Northwind db = CreateDB();
var res = db.ExecuteQuery<Entity<int>>(@"select 1 as Contents from
Customers");
How to fix ?

Andrus.

Jul 21 '08 #1
4 1309
Aside: Why set a field? Why not a property?

The warning is valid; from the compiler's perspective that field is
never set. You could perhaps just add a dummy private method to set it?

Marc
Jul 21 '08 #2
The warning is valid; from the compiler's perspective that field is
never set.
Compiler does not produce warning if field is changed to property.

Why compiler considers that property is set but field is not set ?

Andrus.
Jul 21 '08 #3
On Jul 21, 12:00*pm, "Andrus" <kobrule...@hot.eewrote:
The warning is valid; from the compiler's perspective that field is
never set.

Compiler does not produce warning if field is changed to property.

Why compiler considers that property is set but *field is not set ?
It's not that it considers the property to be set - just that it
doesn't warn about unused properties.

If you really want to just get rid of the warning, you could use
#pragma warning disable [code] before the field and then #pragma
warning restore [code] after the field.

Jon
Jul 21 '08 #4
Andrus wrote:
If ExecuteQuery method sets fields, C# 3.5 compiler issues invalid
warning at compile time:

Field '... .Contents' is never assigned to

To reproduce, create class

class Entity<T>
{
public T Contents;
}

and compile lines

Northwind db = CreateDB();
var res = db.ExecuteQuery<Entity<int>>(@"select 1 as Contents from
Customers");
How to fix ?
Ignore the warning. You'd have the same problem with any other data
accessed only through reflection (say for example the only way to set a
field was through deserialization).
>
Andrus.

Jul 21 '08 #5

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

Similar topics

11
by: John | last post by:
The following code: ------------------------------------- #include <stdio.h> int a=10 main() { printf("a=%d a++=%d ++a=%d \n",a, a++,++a); return 0; } ------------------------------------...
29
by: junky_fellow | last post by:
Consider the following piece of code: struct junk { int i_val; int i_val1; char c_val; }; int main(void) {
3
by: Alexander Arlievsky | last post by:
Hi, C# compiler issues error message on the following lines: GetStruct().Depth = 10; if GetStruct() returns structure (value type). It seems to be correct - else you will modify temporary value...
17
by: Student | last post by:
Hi All, I have an assignment for my Programming language project to create a compiler that takes a C++ file as input and translate it into the C file. Here I have to take care of inheritance and...
6
by: AnotherMike | last post by:
Hello, Can anyone tell me why this won't compile. I'm getting the error: "The type 'GenericsTest.GenericType3' must be convertible to 'GenericsTest.GenericType2<GenericsTest.IInterface2>' in...
7
by: blangela | last post by:
What does the default assignment operator (compiler supplied assignment operator, sometimes also referred to as the implicit assignment operator or the synthesized assignment operator) do when the...
6
by: =?Utf-8?B?RGF2ZQ==?= | last post by:
I found a really strange quirk in the C# compiler, which I can't beleive is proper behaviour. If I define a class thus: public class MyClass { public override string ToString() { return...
5
by: Jess | last post by:
Hi, I understand that if I define a constructor, then the compiler won't synthesize any constructor for me. How about copy constructor and assignment operator? WIll compiler stop synthesizing...
43
by: JohnQ | last post by:
Are a default constructor, destructor, copy constructor and assignment operator generated by the compiler for a struct if they are not explicitely defined? I think the answer is yes, because...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
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: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.