开发者

ConfigurationManager not declared - Have dll

Quick background: I have a VB.NET application in which I was previously using ConfigurationSettings.AppSettings to read from app.config, and got an error message to change it to System.Configuration.ConfigurationManager.AppSettings (as the first way is now obsolete)

I did so, and I even have a reference to System.Configuration.dll AND the Imports statement at the top, but I am getting a "Name ConfigurationManager not declared" error me开发者_运维知识库ssage. Any suggestions?

CODE: It's pretty straightforward - I'm just checking if something exists, and if it does, I read from it:

If Not Exists(ConfigurationManager.AppSettings.Get(rep & "Email")) Then
        Return False
End If

message = ReadAllText(ConfigurationManager.AppSettings.Get(rep & "Email"))


The project template doesn't have the reference you need. Project + Add Reference, select "System.Configuration".

For more insight, click the "Show All Files" icon at the top of the Solution Explorer window and open the References node.


Another issue that causes this is the reference being the wrong case.

System.configuration was in the .vbproj, instead of System.Configuration.

For me, compiling with the above mistake worked on Windows but not on Linux, but fixing it to the latter made it work on both.


If you are using visual studio 2015 and Visual Basic language. Go to Project + Add Reference > Select Assemblies > Framework. Search for System.configuration. Add the DLL file. After it. On your form, add this in the first line without quotations "Imports System.Configuration" go to your connection string declaration then put this value without quotation "ConfigurationManager.ConnectionStrings("'string configuration name'").ConnectionString" like this.

Public constr As String = ConfigurationManager.ConnectionStrings("string configuration name").ConnectionString

This one works for me. Just now. Hope this one helps others. ^_^

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜