w0051977
w0051977

Reputation: 15807

Where is the app.config

I have created a new project in Visual Studio 2013 (class library). There is no app.config. When I select add new item, there is no app.config in the list. Were is the app.config?

I have a ClassLibrary, which contains a number of NUnit Test classes. The problem is that there is lot of code like this throughout the application:

_ConString = ConfigurationManager.ConnectionStrings("GeniedbConnection").ConnectionString

Therefore when I run the tests I get a Null Pointer Exception. Is it possible to do this in the test classes:

ConfigurationManager.ConnectionStrings("GeniedbConnection").ConnectionString = "Connection String"

I get a Null Pointer Exception when I put the code on the above line into the test class. I believe it is because I am trying to set the variable before declaring it. Is that correct?

Upvotes: 1

Views: 160

Answers (2)

Max
Max

Reputation: 13338

A class library doesn't contain an app config, since it isn't an app on it's own, but it can be an addition to an app. You will see an app config if you would create a winform application for example.

Class libraries are dll files that are frequently exchanged between different applications, these are often frequently used classes, that can speed up development, since you don't have to write code that you wrote once before.

MSDN Class Library

Edit:

You should use a UnitTest project and not a class library. Following question + answer will help you out, about using the .config file of your application: Use appliction config file from unittest project

UnitTest Project

Upvotes: 3

AGB
AGB

Reputation: 2448

If you add a reference to System.Configuration in your class library then you can use the following namespace to access the app.config of any applications which use it:

Imports System.Configuration.ConfigurationManager
...
Dim x As String = AppSettings("MySettingName")

Upvotes: 1

Related Questions