开发者

Loading app.config file in Release

开发者 https://www.devze.com 2023-01-25 13:02 出处:网络
In my Visual studio 2008 project, I\'ve added app.config file where I store some app-data in xml format.

In my Visual studio 2008 project, I've added app.config file where I store some app-data in xml format.

I read this data in code like this:

string somedata =    ConfigurationSettings.AppSettings["somedatakey"].ToString();

when I start application in Visual studio, it works. But if I try to run the exe file (release or debug) I get error开发者_C百科 (if i debuf it it breaks on the line above):

Object reference not set to an instance of an object.

The file app.config is not inside folder.


Is the app.config file in the same folder as your exe? If not, copy it there.

Starting debugging in visual studio builds everything, and copies the output (including app.config) to the output folder, starting it from there.


@Jullin: When you run project from visual studio editor by pressing F5 then CLR pick app.config file to read data but when you want to run project from .exe (bin/debug or bin/release) then clr read applicationName.exe.config, which you must have within your debug or release or any folder from where you access you applicationName.exe.

Like i have a window application named "WindowsFormApplication", when i build it successfully in release folder i have WindowsFormApplication.exe and WindowsFormApplication.exe.config and some other files. so make sure you release project successfully and your release folder must contain files.


While Running in from the Exe make sure that u have added app.config should be in the same directory

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号