473,372 Members | 924 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,372 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 8618

"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: 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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.