Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / August 2007

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Reece - 01 Aug 2007 00:22 GMT
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
Reece - 01 Aug 2007 19:14 GMT
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

> 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
[quoted text clipped - 12 lines]
>
> Reese
G.Doten - 01 Aug 2007 19:49 GMT
> Well I found
> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=65821&SiteID=1 which
[quoted text clipped - 39 lines]
>>
>> Reese

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.

Signature

-glenn-

Reece - 01 Aug 2007 20:14 GMT
> 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.

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

>> Well I found
>> http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=65821&SiteID=1 
[quoted text clipped - 39 lines]
>>>
>>> Reese
G.Doten - 01 Aug 2007 21:26 GMT
>> 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
[quoted text clipped - 57 lines]
>>>>
>>>> Reese

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.

Signature

-glenn-

Reece - 01 Aug 2007 21:42 GMT
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

> 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
[quoted text clipped - 5 lines]
> think that's it name) on the test case's method and VS' test engine will
> copy the file for you.
Reece - 23 Aug 2007 18:03 GMT
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

> 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
[quoted text clipped - 12 lines]
>
> Reece

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.