无法使用 C# ConfigurationManager
我有以下代码:
using System.Configuration;
namespace test
{
public partial class MyService : ServiceBase
{
public static ReadConnectionStrings()
{
ConnectionStringSettingsCollection connections =
ConfigurationManager.ConnectionStrings;
但是,它无法识别 ConfigurationManager。我直接从 此处获取此代码
所以我显然错过了一些东西,但无法确定是什么。
I have the following code:
using System.Configuration;
namespace test
{
public partial class MyService : ServiceBase
{
public static ReadConnectionStrings()
{
ConnectionStringSettingsCollection connections =
ConfigurationManager.ConnectionStrings;
However, it doesn’t recognise ConfigurationManager. I took this code directly from here
So I’m clearly missing something, but can’t identify what.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您有对 System.Configuration 的引用吗?默认情况下,它不会添加到 .NET 项目中。
Do you have a reference to
System.Configuration
? It's not added to .NET projects by default.我也有同样的问题。
我花了一些时间才弄清楚添加引用并不是添加使用。我必须右键单击该项目并选择“添加引用”,然后在 .NET 选项卡中选择“System.Configuration”。
效果非常好!
I was having the same issue.
It took me a little while to figure out that adding the reference is not adding the using. I had to right-click the project and select Add Reference, then pick System.Configuration in the .NET tab.
Worked like a charm!
确保您正在使用的实际
项目
引用了System.Configuration
。我正在从事数据访问项目,而不是表示层项目。所以我有点困惑,因为我以为我有一个参考,但实际上数据项目
缺少参考。Ensure that the actual
project
you're working in has a reference toSystem.Configuration
. I was working in a data access project, not the presentation layer's project. So I was getting a bit confused because I had thought I had a reference, but in reality thedata project
was missing the reference.我必须下载程序集参考,然后添加到项目中,不确定其他人是否有这个问题
I had to download the assembly refernce then add to project not sure if others had this problem