all groups > dotnet xml > july 2007 >
You're in the

dotnet xml

group:

DirectoryNotFoundException: app is looking in bin\x86\Debug for my xml file


DirectoryNotFoundException: app is looking in bin\x86\Debug for my xml file Reece
7/31/2007 11:22:40 PM
dotnet xml:
Is there a way, during development, to make it so that you can have the XML
file in the same folder in which the bin folder is found? It seems crazy to
me that during Debug that it is looking in the bin folder if it isn't
putting it in that bin folder.

Line that expects it to be in the bin\x86\Debug folder : XPathDocument doc
= new XPathDocument(@"myfilename.xml");

During debugging, I get a DirectoryNotFoundException unless the file is in
bin\x86\Debug

How do I do what I want? Is there some setting I don't know about?

Thanks,

Reese

Re: DirectoryNotFoundException: app is looking in bin\x86\Debug for my xml file Reece
8/1/2007 1:14:11 PM
Well I found
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=65821&SiteID=1 which
gives the answer for VB (thanks to jkiley who posted there):

sXML = "bcodes.xml"

sXML = Replace(Replace(Application.StartupPath, "\bin\Debug", Space(0)),
"\bin\Release", Space(0)) & "\xml\" & sXML

Kiley appears to be putting the file into an \sml\ directory.
Application.StartupPath seems to be the VB equivalent of C#'s
Environment.CurrentDirectory.

An alternative which I am using is to do a conditional compile:

string xmlFilePath = @"XML\filename.xml";
#if DEBUG
xmlFilePath = @"..\..\..\XML\filename.xml";
#endif

It is just wrong that this is the way it has to be, creating kludges for a
VS shortcoming. I was hoping someone would say that isn't the way it is,
but apparently a kludge is needed. If I am mistaken, please post the
information I was seeking.

R




[quoted text, click to view]

Re: DirectoryNotFoundException: app is looking in bin\x86\Debug for my xml file Reece
8/1/2007 2:14:46 PM
[quoted text, click to view]


Current directory would be Environment.CurrentDirectory. The xml file would
be located relative to that directory. I have already listed two working
solutions for pointing to it both during debugging and runtime. But the
fact that MSFT doesn't handle this transparently is seems like terrible
design to me, and I was hoping that I was missing something. It doesn't do
this nonsense when it comes to Content in XNA games, it does the obvious
thing and copies over the relevant audio and image content files to the
appropriate bin folder so that a kludge is not necessary.

R



[quoted text, click to view]

Re: DirectoryNotFoundException: app is looking in bin\x86\Debug for my xml file G.Doten
8/1/2007 2:49:01 PM
[quoted text, click to view]

When this code goes live (put into production, or whatever) what will
the current directory be that the code executes "from?" In other words,
how will the code find this file in production?

Once that is known then ideas for pointing to the file while debugging
will probably be easier to suggest.

--
Re: DirectoryNotFoundException: app is looking in bin\x86\Debug for my xml file G.Doten
8/1/2007 4:26:25 PM
[quoted text, click to view]

What I've seen done (and what I do) in this case is to have a post-build
event in Visual Studio that copies the file from wherever it lives
during development to the directory it needs to be in when the code runs
under the debugger.

Just FYI: If you have the test capabilities in VS, and if you create a
unit test for your code, then you can use the DeploymentItem attribute
(I think that's it name) on the test case's method and VS' test engine
will copy the file for you.

--
Re: DirectoryNotFoundException: app is looking in bin\x86\Debug for my xml file Reece
8/1/2007 8:42:21 PM
Thanks, Glenn. At this point I think I will just keep my kludge, unless as
my app grows it becomes a problem that would make it more of a hassle than
what you have offered here. But thanks for the ideas, which I will keep in
mind.

R

[quoted text, click to view]

Re: DirectoryNotFoundException: app is looking in bin\x86\Debug for my xml file Reece
8/23/2007 5:03:00 PM
I discovered that the answer is to view the properties of the xml file in
question in the VS environment and select an appropriate option for the
"Copy to output directory" property. The default seems to be "Do not copy".
The output directory is the appropriate bin folder.

Reece


[quoted text, click to view]

AddThis Social Bookmark Button