© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•15mo ago•
2 replies
LiquidPlazmid

Conflicting File Paths when trying to Read in a JSON file

I have a project that reads in a JSON file that is stored in that project. I am trying to write unit tests for this project, but when the project tries to read the JSON file it looks in the wrong directory.

For the file path I used Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) combined with the JSON file name appended at the end.

However while this should result in project/file.json, when the unit test runs it results in
Test project/bin/Debug/..../file.json.

How can I fix the file path so that it properly accesses the file when other C# projects call the file?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Trying to read from a binary file
C#CC# / help
3y ago
✅ how do I read a json file, edit it and save the edit in the json file?
C#CC# / help
3y ago
❔ ✅ System.Text.Json paths
C#CC# / help
3y ago
❔ Read a .pdb file in C#
C#CC# / help
3y ago