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.

Error: Not all code paths return a value - how do I fix it?

How do I deal with this? I am getting an error for each get in the
Game class (see code below).

In the simplified example below I have reduced this to just 3 fields,
one which can be NULL. I have added 3 records to the table and ran the
program but it fails with the error above.

The application is supposed to create the hashtable of records as a
static feature which will be permanently available to my application.
To demonstrate that the HashTable is actually there I display the
contents in an ASP.NET page called Games.

When I run my application I get the error below:

= = = = = = = = = =
C:\Inetpub\wwwroot\ChatMark1\Game.cs(40):
'ChatMark1.Game.GameID.get': not all code paths return a value

= = = = = = = = = =
public class Global : System.Web.HttpApplication
{

public static string gameConnection = "packet size=4096;user
id=sa;pwd=monkey;data source=ASROCK;persist security
info=False;initial catalog=ChatMark1";
public static GameHashTable games;
private System.ComponentModel.IContainer components = null;

public Global()
{
InitializeComponent();
}

protected void Application_Start(Object sender, EventArgs e)
{
Global.GameLoad();
}

public static string GameConnection
{
get
{
return gameConnection;
}
}

public static void GameLoad()
{
SqlConnection connGames = new SqlConnection(gameConnection);
connGames.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Games",
connGames);
SqlDataReader reader;
reader = cmd.ExecuteReader();

Game game;
games = new GameHashTable();
while (reader.Read())
{
game = new Game((int)reader[0], (DateTime)reader[1],
(string)reader[2]);
games.Add(game);
}
connGames.Close();
}

public static GameHashTable Games
{
get
{
return games;
}
}

}
= = = = = = = = = =
// Games.aspx.cs.

public class Games : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgGames;

private void Page_Load(object sender, System.EventArgs e)
{
dgGames.DataSource = Global.Games;
dgGames.DataBind();
}
}

= = = = = = = = = =
public class GameHashTable : IEnumerable
{
Hashtable _games;

public GameHashTable()
{
// Contructor
_games = new Hashtable();
}
public IEnumerator GetEnumerator()
{
return _games.Values.GetEnumerator();
}
public Game this[int GameID]
{
get {return (Game) _games[GameID];}
set {Add(value);}
}
public void Add(Game Item)
{
if (Item == null)
throw new ArgumentException("Game can not be null");
_games.Add(Item.GameID, Item);

}
public void Remove(Game Item)
{
_games.Remove(Item.GameID);
}
}
= = = = = = = = = =

public class Game
{
private int _gameID;
private DateTime _playTime;
private string _image;

public Game(
int initialGameID,
DateTime initialPlayTime,
string initialImage )
{
GameID = initialGameID;
PlayTime = initialPlayTime;
Image = initialImage;
}
public int GameID
{
get {GameID = _gameID;}
set {_gameID = value;}
}
public DateTime PlayTime
{
get {PlayTime = _playTime;}
set {_playTime = value;}
}
public string Image
{
get {Image = _image;}
set {_image = value;}
}

}

= = = = = = = = = =

My Games Table in the ChatMark1 database.

CREATE TABLE Games (
gameID int IDENTITY (1, 1) NOT NULL ,
playTime datetime NOT NULL DEFAULT (getdate()),
image varchar (50) NULL ,
CONSTRAINT PK_Games PRIMARY KEY CLUSTERED (gameID) ON PRIMARY
) ON PRIMARY
Nov 17 '05 #1
3 8620

"Oberon" <Ob****@solstice.com> wrote in message
news:td********************************@4ax.com...
How do I deal with this? I am getting an error for each get in the
Game class (see code below).

In the simplified example below I have reduced this to just 3 fields,
one which can be NULL. I have added 3 records to the table and ran the
program but it fails with the error above.

The application is supposed to create the hashtable of records as a
static feature which will be permanently available to my application.
To demonstrate that the HashTable is actually there I display the
contents in an ASP.NET page called Games.

When I run my application I get the error below:

= = = = = = = = = =
C:\Inetpub\wwwroot\ChatMark1\Game.cs(40):
'ChatMark1.Game.GameID.get': not all code paths return a value

= = = = = = = = = =
public class Global : System.Web.HttpApplication
{

public static string gameConnection = "packet size=4096;user
id=sa;pwd=monkey;data source=ASROCK;persist security
info=False;initial catalog=ChatMark1";
public static GameHashTable games;
private System.ComponentModel.IContainer components = null;

public Global()
{
InitializeComponent();
}

protected void Application_Start(Object sender, EventArgs e)
{
Global.GameLoad();
}

public static string GameConnection
{
get
{
return gameConnection;
}
}

public static void GameLoad()
{
SqlConnection connGames = new SqlConnection(gameConnection);
connGames.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Games",
connGames);
SqlDataReader reader;
reader = cmd.ExecuteReader();

Game game;
games = new GameHashTable();
while (reader.Read())
{
game = new Game((int)reader[0], (DateTime)reader[1],
(string)reader[2]);
games.Add(game);
}
connGames.Close();
}

public static GameHashTable Games
{
get
{
return games;
}
}

}
= = = = = = = = = =
// Games.aspx.cs.

public class Games : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgGames;

private void Page_Load(object sender, System.EventArgs e)
{
dgGames.DataSource = Global.Games;
dgGames.DataBind();
}
}

= = = = = = = = = =
public class GameHashTable : IEnumerable
{
Hashtable _games;

public GameHashTable()
{
// Contructor
_games = new Hashtable();
}
public IEnumerator GetEnumerator()
{
return _games.Values.GetEnumerator();
}
public Game this[int GameID]
{
get {return (Game) _games[GameID];}
set {Add(value);}
}
public void Add(Game Item)
{
if (Item == null)
throw new ArgumentException("Game can not be null");
_games.Add(Item.GameID, Item);

}
public void Remove(Game Item)
{
_games.Remove(Item.GameID);
}
}
= = = = = = = = = =

public class Game
{
private int _gameID;
private DateTime _playTime;
private string _image;

public Game(
int initialGameID,
DateTime initialPlayTime,
string initialImage )
{
GameID = initialGameID;
PlayTime = initialPlayTime;
Image = initialImage;
}
public int GameID
{
get {GameID = _gameID;}
set {_gameID = value;}
}
public DateTime PlayTime
{
get {PlayTime = _playTime;}
set {_playTime = value;}
}
public string Image
{
get {Image = _image;}
set {_image = value;}
}

}

= = = = = = = = = =

My Games Table in the ChatMark1 database.

CREATE TABLE Games (
gameID int IDENTITY (1, 1) NOT NULL ,
playTime datetime NOT NULL DEFAULT (getdate()),
image varchar (50) NULL ,
CONSTRAINT PK_Games PRIMARY KEY CLUSTERED (gameID) ON PRIMARY
) ON PRIMARY


The best place to start is exactly where it says the problem is:
C:\Inetpub\wwwroot\ChatMark1\Game.cs on line 40. Also, from within the IDE
you can double click on the error and it will take you there. However, the
bottom line is that you need to return a value from your get'ers, for
example:

public int GameID
{
get {return _gameID;}
set {_gameID = value;}
}
Nov 17 '05 #2
"Oberon" <Ob****@solstice.com> a écrit dans le message de news:
td********************************@4ax.com...

How do I deal with this? I am getting an error for each get in the
Game class (see code below). public class Game
{
private int _gameID;
private DateTime _playTime;
private string _image;

public Game(
int initialGameID,
DateTime initialPlayTime,
string initialImage )
{
GameID = initialGameID;
PlayTime = initialPlayTime;
Image = initialImage;
}
public int GameID
{
get {GameID = _gameID;}
set {_gameID = value;}
}
public DateTime PlayTime
{
get {PlayTime = _playTime;}
set {_playTime = value;}
}
public string Image
{
get {Image = _image;}
set {_image = value;}
}

}


You have declared you properties incorrectly; for some reason you ar trying
to set the property in the getter !!!

public int GameID
{
get {return _gameID;}
set {_gameID = value;}
}

public DateTime PlayTime
{
get {return _playTime;}
set {_playTime = value;}
}

public string Image
{
get {return _image;}
set {_image = value;}
}

Joanna

--
Joanna Carter
Consultant Software Engineer
Nov 17 '05 #3
Oh dear,

That's just the kind of error beginners make isn't it?

public int GameID
{
get {GameID = _gameID;}
set {_gameID = value;}
}

In my mind I thought that 'GameID = _gameID' would set the property to
the value of the hidden field. Silly me.

Thanks.
On Thu, 19 May 2005 07:18:42 -0400, "Andy Walldorff"
<an************@daytonrcs.REMOVE.com> wrote:

"Oberon" <Ob****@solstice.com> wrote in message
news:td********************************@4ax.com.. .
How do I deal with this? I am getting an error for each get in the
Game class (see code below).

In the simplified example below I have reduced this to just 3 fields,
one which can be NULL. I have added 3 records to the table and ran the
program but it fails with the error above.

The application is supposed to create the hashtable of records as a
static feature which will be permanently available to my application.
To demonstrate that the HashTable is actually there I display the
contents in an ASP.NET page called Games.

When I run my application I get the error below:

= = = = = = = = = =
C:\Inetpub\wwwroot\ChatMark1\Game.cs(40):
'ChatMark1.Game.GameID.get': not all code paths return a value

= = = = = = = = = =
public class Global : System.Web.HttpApplication
{

public static string gameConnection = "packet size=4096;user
id=sa;pwd=monkey;data source=ASROCK;persist security
info=False;initial catalog=ChatMark1";
public static GameHashTable games;
private System.ComponentModel.IContainer components = null;

public Global()
{
InitializeComponent();
}

protected void Application_Start(Object sender, EventArgs e)
{
Global.GameLoad();
}

public static string GameConnection
{
get
{
return gameConnection;
}
}

public static void GameLoad()
{
SqlConnection connGames = new SqlConnection(gameConnection);
connGames.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM Games",
connGames);
SqlDataReader reader;
reader = cmd.ExecuteReader();

Game game;
games = new GameHashTable();
while (reader.Read())
{
game = new Game((int)reader[0], (DateTime)reader[1],
(string)reader[2]);
games.Add(game);
}
connGames.Close();
}

public static GameHashTable Games
{
get
{
return games;
}
}

}
= = = = = = = = = =
// Games.aspx.cs.

public class Games : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgGames;

private void Page_Load(object sender, System.EventArgs e)
{
dgGames.DataSource = Global.Games;
dgGames.DataBind();
}
}

= = = = = = = = = =
public class GameHashTable : IEnumerable
{
Hashtable _games;

public GameHashTable()
{
// Contructor
_games = new Hashtable();
}
public IEnumerator GetEnumerator()
{
return _games.Values.GetEnumerator();
}
public Game this[int GameID]
{
get {return (Game) _games[GameID];}
set {Add(value);}
}
public void Add(Game Item)
{
if (Item == null)
throw new ArgumentException("Game can not be null");
_games.Add(Item.GameID, Item);

}
public void Remove(Game Item)
{
_games.Remove(Item.GameID);
}
}
= = = = = = = = = =

public class Game
{
private int _gameID;
private DateTime _playTime;
private string _image;

public Game(
int initialGameID,
DateTime initialPlayTime,
string initialImage )
{
GameID = initialGameID;
PlayTime = initialPlayTime;
Image = initialImage;
}
public int GameID
{
get {GameID = _gameID;}
set {_gameID = value;}
}
public DateTime PlayTime
{
get {PlayTime = _playTime;}
set {_playTime = value;}
}
public string Image
{
get {Image = _image;}
set {_image = value;}
}

}

= = = = = = = = = =

My Games Table in the ChatMark1 database.

CREATE TABLE Games (
gameID int IDENTITY (1, 1) NOT NULL ,
playTime datetime NOT NULL DEFAULT (getdate()),
image varchar (50) NULL ,
CONSTRAINT PK_Games PRIMARY KEY CLUSTERED (gameID) ON PRIMARY
) ON PRIMARY


The best place to start is exactly where it says the problem is:
C:\Inetpub\wwwroot\ChatMark1\Game.cs on line 40. Also, from within the IDE
you can double click on the error and it will take you there. However, the
bottom line is that you need to return a value from your get'ers, for
example:

public int GameID
{
get {return _gameID;}
set {_gameID = value;}
}


Nov 17 '05 #4

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

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
6
by: Peter Afonin | last post by:
Hello: I'm trying to convert the connection class that I created in VB.Net for ASP.Net application into C#. I'm doing something incorrectly, because I'm getting the following error when trying...
12
by: Jose Fernandez | last post by:
Hello. I'm building a web service and I get this error. NEWS.News.CoverNews(string)': not all code paths return a value This is the WebMethod public SqlDataReader CoverNews(string Sport)...
4
by: OutdoorGuy | last post by:
Greetings, I am attempting to compile the code below, but I am receiving an error message when I do so. The error message is: "CSO161: 'Forloop.CalcAvg(int)': Not all code paths return a...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
7
by: siri11 | last post by:
hi everyone!!!! I have written a function that shud return a decimal value.But I'm getting an error in c#.net(windows Application) which is a build error--->not all code paths return a value.Can...
1
by: fretIT | last post by:
Hello, when I write web method using C# in Visual basic 2005, I can't return the string value to the client request. I got such kind of error Not all code paths return a value. Don't know how...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.