C
C#7mo ago
Trif☼

✅ System.IO.FileNotFoundException

But the file exists, what could be the problem?
22 Replies
daniel2
daniel27mo ago
Your code? Your file path?
Trif☼
Trif☼OP7mo 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
Angius7mo ago
Well, does that file exist?
Trif☼
Trif☼OP7mo ago
yea
daniel2
daniel27mo ago
Show your code
Angius
Angius7mo ago
Does it exist, really? At this exact location? With this exact name?
Trif☼
Trif☼OP7mo 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
daniel27mo ago
What get passed to this function
Trif☼
Trif☼OP7mo 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
Angius7mo 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☼OP7mo ago
oooohhhh
Trif☼
Trif☼OP7mo ago
No description
Angius
Angius7mo ago
Doesn't look much like this path, does it?
Trif☼
Trif☼OP7mo ago
yeah:)))
Angius
Angius7mo 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☼OP7mo ago
um
Trif☼
Trif☼OP7mo ago
No description
Trif☼
Trif☼OP7mo ago
from where?
Angius
Angius7mo ago
Right-click on it You should have a Properties in the settings Alternatively, set it for each individual file
Trif☼
Trif☼OP7mo ago
got it thanks it works
Buddy
Buddy7mo ago
$close
MODiX
MODiX7mo 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