C
C#6mo ago
Trif☼

✅ System.IO.FileNotFoundException

But the file exists, what could be the problem?
22 Replies
daniel2
daniel26mo ago
Your code? Your file path?
Trif☼
Trif☼OP6mo ago
So I run the project and I get this specific error: System.IO.FileNotFoundException: 'Could not find file 'D:\Universitate\dotNet\bin\Debug\net8.0\Assets\player.json'.'
Angius
Angius6mo ago
Well, does that file exist?
Trif☼
Trif☼OP6mo ago
yea
daniel2
daniel26mo ago
Show your code
Angius
Angius6mo ago
Does it exist, really? At this exact location? With this exact name?
Trif☼
Trif☼OP6mo ago
c++
public static SpriteSheet? LoadSpriteSheet(string fileName, string folder, GameRenderer renderer){
var json = File.ReadAllText(Path.Combine(folder, fileName));
var spriteSheet = JsonSerializer.Deserialize<SpriteSheet>(json, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
if(spriteSheet != null){
spriteSheet.LoadTexture(renderer, folder);
}
return spriteSheet;
}
c++
public static SpriteSheet? LoadSpriteSheet(string fileName, string folder, GameRenderer renderer){
var json = File.ReadAllText(Path.Combine(folder, fileName));
var spriteSheet = JsonSerializer.Deserialize<SpriteSheet>(json, new JsonSerializerOptions() { PropertyNameCaseInsensitive = true });
if(spriteSheet != null){
spriteSheet.LoadTexture(renderer, folder);
}
return spriteSheet;
}
i get the error from var json
daniel2
daniel26mo ago
What get passed to this function
Trif☼
Trif☼OP6mo ago
I would give you details, but this is for uni, I just pulled this and I have to implement whatever, like it's sort of a project made by our teacher and we have to add features so yeah, idk more than this
Angius
Angius6mo ago
Show me a screenshot of the file existing at this location I have a suspicion that the file exists, yes, but elsewhere Like, say, in the project root And it's not set to be copied over to the bin directory
Trif☼
Trif☼OP6mo ago
oooohhhh
Trif☼
Trif☼OP6mo ago
No description
Angius
Angius6mo ago
Doesn't look much like this path, does it?
Trif☼
Trif☼OP6mo ago
yeah:)))
Angius
Angius6mo ago
So, assuming you use VS, right-click the Assets directory, open its properties, and set it to be copied Always, or if newer Either works
Trif☼
Trif☼OP6mo ago
um
Trif☼
Trif☼OP6mo ago
No description
Trif☼
Trif☼OP6mo ago
from where?
Angius
Angius6mo ago
Right-click on it You should have a Properties in the settings Alternatively, set it for each individual file
Trif☼
Trif☼OP6mo ago
got it thanks it works
Buddy
Buddy6mo ago
$close
MODiX
MODiX6mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server