引用程序集后无法使用命名空间 [英] Unable to use namespace after referencing assemblys

查看:38
本文介绍了引用程序集后无法使用命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位,

我在使用 Visual Studio 2010 SP1 中的 c# 多项目解决方案时遇到问题.

I am having a problem with a c#, multi-project solution in Visual Studio 2010 SP1.

这是解决方案结构:BNLib - 艾米个人实用程序库WidgetClientApp - asp.net 应用程序前端WidgetConsoleUtilities - 控制台应用程序WidgetCore - 包含共享接口、类和枚举WidgetMiddleTier - 业务逻辑WidgetDataLayer - 通过 linq to SQL 访问数据库.

Here is the Solution Structure: BNLib - amy personal library of utilities WidgetClientApp - The asp.net application front end WidgetConsoleUtilities - A console application WidgetCore - contains shared interfaces, classes and enums WidgetMiddleTier - Bussiness logic WidgetDataLayer - DB access via linq to SQL.

问题在向控制台应用程序 (WidgetConsoleUtilities) 添加对中间层程序集(WidgetMiddleTier,包含命名空间 Widget.MT)的引用后,我向我的 program.cs 页面添加了一条 using 指令:

The problem After adding a reference to the middle tier assembly (WidgetMiddleTier, which contains namespace Widget.MT) to the console application (WidgetConsoleUtilities), I added a using directive to my program.cs page:

使用 Widget.MT;

using Widget.MT;

然后我收到一个关于 using 指令的编译器错误:

I then receive a compiler error on the using directive:

命名空间Widget"中不存在类型或命名空间名称MT"(您是否缺少程序集引用?)

The type or namespace name 'MT' does not exist in the namespace 'Widget' (are you missing an assembly reference?)

我在同一个解决方案的其他几个项目中使用了这个程序集,没有问题.我在控制台应用程序中毫无困难地使用了另一个程序集(WidgetCore,它包含命名空间 Widget.Core).

I use this assembly in several other projects in the same solution without a problem. I use another assembly (WidgetCore, which contains namespace Widget.Core) in the console application without difficulty.

Web 应用程序(小部件)使用这两个程序集没有问题.

A web application (Widget) uses both these assemblies without issue.

我尝试删除和读取命名空间、关闭并重新打开 Visual Studio 2010、清理构建、直接包含程序集而不是项目,但没有奏效.

I have tried removeing and readding the namespaces, closing and reopening Visual studio 2010, cleaning the builds, directly including assemblies instead of projects, and nothng has worked.

有什么想法吗?

您的帮助将不胜感激!

最好,

布雷特

推荐答案

是使用 的控制台应用程序.NET 4 客户端配置文件?如果是这样,您将无法引用不在 .NET Framework 4 Client Profile 中的程序集.相反,您必须以 .NET Framework 4 为目标 - 要执行此操作,请转到您的项目属性并将目标框架"更改为.NET Framework 4".

Is the console application using the .NET 4 client profile by chance? If so you cannot reference an assembly that is not in the .NET Framework 4 Client Profile. Instead you must target the .NET Framework 4 - to do this go to your project properties and change the "Target Framework" to ".NET Framework 4".

这篇关于引用程序集后无法使用命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆