views:

39

answers:

4

So I'm trying to compile an Asteroids game. It's almost working, all the files are in place etc etc...

The issue comes when it hits this code.

FileStream myFileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.Read);
string myTempFile = @"F:\Documents\Junior School\Computer Programming (Java 1)\AsteroidsWithSound\AsteroidsWithSound\temp\mysound" + i.ToString() + ".wav";

It gives me an Error/Warning, not sure exactly what it is called but it says

ArgumentException was unhandled. Empty path name is not legal.

I've read online about chunks of code like this causing this issue but could never find a resolution. Any help would be awesome.

EDIT: Filename is defined in this chunk.

string filename = this.Player.FileName;
this.Player.Open("");
File.Delete(filename);
this.isReady = true;
A: 

Can you see the file path in the debugger for your variable "filename"?

cinqoTimo
A: 

That suggests that the filename variable refers to an empty string.

You haven't shown the code that sets the value of filename, but that's the bit to look at.

Jon Skeet
This seems to be where it is defined string filename = this.Player.FileName; this.Player.Open(""); File.Delete(filename); this.isReady = true;
Cistoran
@Cistoran: Okay, so then you need to look at Player.FileName - presumably *that* is empty.
Jon Skeet
Player.FileName isn't even in the code excepted commented out stuff.
Cistoran
@Cistoran: Well that would explain it - what file did you think it would try to open?
Jon Skeet
A: 

First of, try and see what you get when you put a Watch on filename, and break at the exception-throwing line. If it's empty, then find out when was it set to the empty string, if it's not empty, then something's very wrong here and it might be the result of another (evil) code piece somewhere.

Next, I'll suggest you use File.readXXXXX to read the file and not a new FileStream. The File class can handle the open-read-close procedure very nicely.

Hope it helps

Neowizard
A: 

The issue was I was calling PlaySound(""); when Asteroids was made. I comment out that line of code and it works. Trying to play a file that isn't there will generally break things.

Cistoran