Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2010 > Visual Basic 2010 General Discussion
|
Visual Basic 2010 General Discussion For any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 26th, 2011, 01:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default Where is app.config supposed to reside?

I'm having trouble getting a Windows vb program to read app.config and have been unable to locate any useful information. This code, located in the form_load curently, runs as expected in the debugger:

Dim strProgramID AsString = ConfigurationManager.AppSettings("ProgramID")
MsgBox(
"strProgramID='" & strProgramID & "'")

But it returns NOTHING when running the compiled version. It appears to give no reason for failure and I can only assume the problem is that it can't find the app.config file. I copied the file named "app.config" to the same folder as the executable because it was not there, but that did not appear to have resolved this.

I usually code web programs and this has never been a problem for me in that environment, and can find nothing online to explain why this should not work outside the debugger, so I am stumped! Can somebody please explain what I've overlooked before I start coding my own INI file class?
 
Old July 26th, 2011, 03:18 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

The app.config file should indeed be in the same folder as your executable, but it should also be named after the execuable.

To see how this works, try this:

1. Create a new Win Forms application.

2. Right-click the project, choose Add | New Item and add an Application Configuration File.

3. Compile

4. Take a look in the Bin\Debug folder. There you find the config file with a name such as WindowsFormsApplication1.exe.config.

Hope this helps,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old July 26th, 2011, 03:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 428
Thanks: 57
Thanked 2 Times in 2 Posts
Default

Hi Imar! Thanks for your response. While I would agree it SHOULD have created the file using the proper name, it appears to have called it simply app.config.

I finally found a helpful post about 15 minutes ago on some obscure site pointing this out but hadn't had time to update my post before you replied. I renamed the file and it now works as expected. So, I apparently didn't sacrifice the chicken properly or wasn't holding my mouth right when I first created the config file or something?

For more app.config fun, try creating a multiple project solution containing DLL and Windows application projects, where each project has its own app.config. The DLL reads its own app.config in the debugger, but reads the CALLING PROGRAM's app.config when running the EXE. That was so much fun figuring out! Wheeeeee!!!!!
 
Old July 26th, 2011, 06:01 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It must have been the chicken... ;-)

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
App.Config and Web.Config conflict John.Burke ASP.NET 2.0 Professional 5 March 9th, 2010 11:51 AM
web.config vs. app.config darlo Visual Studio 2005 11 August 20th, 2008 07:23 AM
How to get the directory of app.config cczhangjm C# 2 May 28th, 2007 02:55 AM
How to access app.config in C# ? cczhangjm XML 2 May 16th, 2007 07:43 PM
Chapter 8 - app.config jotto BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 March 21st, 2006 05:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.