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

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a

"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

P: n/a
"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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.