2

I know it's a relatively frequent asked question, but none of the solutions that had been offered works for me, so as a last resort, I am raising it again:

suddenly, when trying to run my project at debug mode, I'm getting errors:

"Can not load NameOfFIleHere.xml file - Could not find file 'c:\Users\FullLocationHere\bin\Debug\NameOfFIleHere.xml'" and "Can not load 'c:\Users\FullLocationHere\bin\Debug\NameOfFIleHere.xml' - Configuration system failed to initialize"

I'm working on this project for a while now and never had any similar problem. In addition, I haven't changed any of my xml files lately, nor have I made any significant code/settings modification since the last time it ran successfully. I'm working on Visual Studio 2013 with TFS. Can anyone please offer me some ideas as to why it keeps happening?

Thanks a lot!

Some of the solutions I've tried:

Unable to copy file - access to the path is denied

Could not find file ..\bin\Debug\content.dat

Unable to copy a file from obj\Debug to bin\Debug

MSH
  • 163
  • 1
  • 1
  • 17

2 Answers2

2

When working with content-files (xml, images, etc..) that come from another project than the GUI/Starting-Project it can sometimes happen, that the file cannot be written in the GUI/Starting-Project's bin\debug even if it's set to "copy always". I observed that it happens during the rebuild process, when Visual Studio cleans up the old compile. Fairly randomly, it seems that a file-handle gets stuck and prevents the files to be created.

Personally I solved the problem by copying needed application files to

Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
"CompanyName", "AppName")

which resolves to:

C:\ProgramData\CompanyName\AppName
KarmaEDV
  • 1,631
  • 16
  • 27
  • I saw that many users did say this solution worked for them, but unfortunately it didn't solve my problem. – MSH Aug 24 '15 at 09:44
  • How can this not solve your problem? If you write the file to a neutral place in one project and then read it from another project from that neutral place, skipping the clean/rebuilding mechanism of Visual studio, how can it not work? I could only imagine that you have permission issues at that point. – KarmaEDV Aug 24 '15 at 09:47
  • That's a good question, I run out of options, that's just pure frustration now. – MSH Aug 24 '15 at 10:06
  • Try to copy the files by hand and run the .exe, not the .vhost.exe, catch the error in a message box so that you don't need the debugger to see where it crashes. As a last resort, copy your content file into the GUI/Starter-Project directly. Restart your PC, etc... Try to minimize the variables. – KarmaEDV Aug 24 '15 at 10:42
  • Are the files physically there? Make sure all the file handles/StreamWriters/Readers in your App are closed/Flushed before you try to access them. You can check this with Task Manager/Performance/Ressource Monitor or with the 3rd party app Process Explorer. As a general rule, try to handle your file operations in a non-blocking way. (Use File.WriteX instead of streams or use streams when needed in using statements) – KarmaEDV Aug 24 '15 at 10:50
  • 1
    Another thought: As far as I can see you have your project in your user profile. This could bring the weird permission problems you are facing. Move your project away to a folder that you created yourself on the harddrive, i.e. C:\DEV (also set this setting in Visual Studio under Tools/Options/Projects and Solutions for the future) – KarmaEDV Aug 24 '15 at 11:22
  • I've deleted the project from tfs and uploaded an older copy of it from another folder (which isn't located in my user folder), and it works! not the most elegant solution, but in this point I frankly don't care about correctness... thanks a lot for your help! – MSH Aug 24 '15 at 11:32
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/87777/discussion-between-karmaedv-and-maayan). – KarmaEDV Aug 24 '15 at 11:34
0

Just an update as to how it was solved: I've ended up deleting the project from tfs and uploaded an older copy of it from another folder (which is located directly under C:, as was recommended to me above). not the most elegant solution, but it worked for me.

MSH
  • 163
  • 1
  • 1
  • 17