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

C# compiler gives wrong "variable undeclared or unasigned' error

It is not the first time I see this happen. I am using VS.NET 2003 with .NET
Framework 1.1. In this particular situation I have a custom user control in
a windows form. There is a member variable declared with the fully qualified
class name (some.namespace.mycontrolclass). Then in the
InitializeComponent() it is instantiated and there is a block of code lines
that set the various properties of the control class, then further down the
usual this.Controls.Add(this.mycontrol).

Well, when I compile I get an error indicating "The variable
'mycontrolclass' is either undeclared or was never assigned." That seems
crazy considering it is:
a) declared in the same class with the full name
b) instantiated at the beginning of the InitializeComponent().
c) then further on it is initialized in the same method, and
d) even further down the same method (InitializeComponent) it is used in the
Add method (where the 'error' is pointed).

This has been declared *and* initialized. Could it be that the C# compiler
is somehow losing a bolt or two because the referenced assembly does not
have a strong name? anyway, I don't see why it should just throw such
meaningless and unjust error.
Nov 16 '05 #1
2 2023
~~~ .NET Ed ~~~ <ti*********@abolishspam.now> wrote:
It is not the first time I see this happen. I am using VS.NET 2003 with .NET
Framework 1.1. In this particular situation I have a custom user control in
a windows form. There is a member variable declared with the fully qualified
class name (some.namespace.mycontrolclass). Then in the
InitializeComponent() it is instantiated and there is a block of code lines
that set the various properties of the control class, then further down the
usual this.Controls.Add(this.mycontrol).

Well, when I compile I get an error indicating "The variable
'mycontrolclass' is either undeclared or was never assigned." That seems
crazy considering it is:
a) declared in the same class with the full name
b) instantiated at the beginning of the InitializeComponent().
c) then further on it is initialized in the same method, and
d) even further down the same method (InitializeComponent) it is used in the
Add method (where the 'error' is pointed).

This has been declared *and* initialized. Could it be that the C# compiler
is somehow losing a bolt or two because the referenced assembly does not
have a strong name? anyway, I don't see why it should just throw such
meaningless and unjust error.


Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Ed,

Can you post the code for the control? While it certainly is possible
that the compiler is doing something wrong, I tend not to think that
initially (I've been wrong when going head to head with the compiler too
often).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"~~~ .NET Ed ~~~" <ti*********@abolishspam.now> wrote in message
news:O5**************@TK2MSFTNGP12.phx.gbl...
It is not the first time I see this happen. I am using VS.NET 2003 with
.NET
Framework 1.1. In this particular situation I have a custom user control
in
a windows form. There is a member variable declared with the fully
qualified
class name (some.namespace.mycontrolclass). Then in the
InitializeComponent() it is instantiated and there is a block of code
lines
that set the various properties of the control class, then further down
the
usual this.Controls.Add(this.mycontrol).

Well, when I compile I get an error indicating "The variable
'mycontrolclass' is either undeclared or was never assigned." That seems
crazy considering it is:
a) declared in the same class with the full name
b) instantiated at the beginning of the InitializeComponent().
c) then further on it is initialized in the same method, and
d) even further down the same method (InitializeComponent) it is used in
the
Add method (where the 'error' is pointed).

This has been declared *and* initialized. Could it be that the C# compiler
is somehow losing a bolt or two because the referenced assembly does not
have a strong name? anyway, I don't see why it should just throw such
meaningless and unjust error.

Nov 16 '05 #3

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

Similar topics

30
by: Neil Zanella | last post by:
Hello, Allow me to share my frustrations with GNU g++. This is the second time something similar happens to me: I can't find anything wrong with my C++ program and yet I get segfaults, and...
19
by: Alf P. Steinbach | last post by:
// As usual the error message directs one to the report the bug. // // And as usual there is absolutely no way to do so without paying for // the privilege... // // Or using three or four hours...
5
by: Sean Wolfe | last post by:
I have a request for the c# compiler one that is an obvious oversight in my opinion. I'm not sure if this is already being implemented in Whidebey, bu i would hope to find it in there, or in the...
0
by: Tim Sharrock | last post by:
We have hit an internal compiler error when processing a very long array initialiser (for a lookup table). Most of the compiler versions we tried compiled the code successfully, but very slowly...
0
by: Bart De Boeck | last post by:
Hi, What do you think of the following compiler error : code : ------------------------------------- StringBuilder* oBuilder = new StringBuilder();
2
by: Itjalve | last post by:
This gives me a fatal error. I'm using .NET VC7.1 and made a win32 consol app, I have no problems with VC6. Debug build. I have removed nearly all my code this is whats left. From the beginning...
3
by: manoj.pattanaik | last post by:
Hi, I am trying to compile following piece of code (bb.cpp) using aCC (HP ANSI C++ B3910B A.03.37) compiler on HP-UX 11.23. It gives error:485 //bb.cpp -- Starts #include <iostream> using...
4
by: cnixuser | last post by:
Hello, I am posting reguarding some modifications I made to a text editor program that I wrote in my java class at my school today. The file I was modifying is a very simple java text editor with...
8
by: Jess | last post by:
Hi, I have a template function that triggered some compiler error. The abridged version of the class and function is: #include<memory> using namespace std; template <class T>
1
by: kvarada | last post by:
Hello Experts, I am building my application on WinNT.4.0_i386_MSVC.7.1 platform. When I build the application on a stand alone machine, it builds fine. But when I build the same application from a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.