C# System.Windows.Forms.DataVisualization 命名空间在一个类中很好,但在另一个类中不行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/570274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
System.Windows.Forms.DataVisualization Namespace Fine in One Class but Not in Another
提问by jxpx777
I'm getting this error
我收到这个错误
The type or namespace name 'DataVisualization' does not exist in the namespace 'System.Windows.Forms' (are you missing an assembly reference?)
The type or namespace name 'DataVisualization' does not exist in the namespace 'System.Windows.Forms' (are you missing an assembly reference?)
Here is my using
section of the class:
这是我using
的课程部分:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Forms.DataVisualization.Charting;
using System.Windows.Forms.DataVisualization.Charting.Borders3D;
using System.Windows.Forms.DataVisualization.Charting.ChartTypes;
using System.Windows.Forms.DataVisualization.Charting.Data;
using System.Windows.Forms.DataVisualization.Charting.Formulas;
using System.Windows.Forms.DataVisualization.Charting.Utilities;
namespace myNamespace {
public class myClass {
// Usual class stuff
}
}
The thing is that I am using the same DataVisualization includes in another class. The only thing that I can think that is different is that the classes that are giving this missing namespace error are Solution Items rather than specific to a project. The projects reference them by link. Anyone have thoughts on what the problem is? I've installed the chart component, .Net 3.5 SP1, and the Chart Add-in for Visual Studio 2008.
问题是我在另一个类中使用了相同的 DataVisualization 。我认为唯一不同的是,导致此缺少命名空间错误的类是解决方案项,而不是特定于项目。项目通过链接引用它们。任何人都对问题是什么有想法?我已经安装了图表组件、.Net 3.5 SP1 和 Visual Studio 2008 的图表加载项。
UPDATE: I moved the items from Solution Items to be regular members of my project and I'm still seeing the same behavior.
更新:我将解决方案项目中的项目移动到我的项目的常规成员中,但我仍然看到相同的行为。
UPDATE 2: Removing the items from the Solution Items and placing them under my project worked. Another project was still referencing the files which is why I didn't think it worked previously. I'm still curious, though, why I couldn't use the namespace when the classes were Solution Items but moving them underneath a project (with no modifications, mind you) instantly made them recognizable. :\
更新 2:从解决方案项目中删除项目并将它们放在我的项目下工作。另一个项目仍在引用文件,这就是为什么我认为它以前不起作用的原因。不过,我仍然很好奇,为什么当类是解决方案项时我不能使用命名空间,但将它们移到项目下(请注意,没有修改)立即使它们易于识别。:\
采纳答案by JeremyWeir
Solution items aren't used by compiled assemblies.
已编译的程序集不使用解决方案项。
http://msdn.microsoft.com/en-us/library/1ee8zw5t.aspx"They can be referenced by projects, but are never included in solution or project builds"
http://msdn.microsoft.com/en-us/library/1ee8zw5t.aspx“它们可以被项目引用,但永远不会包含在解决方案或项目构建中”
As far as I know, solution folders/items are really just meant for organizing things.
据我所知,解决方案文件夹/项目实际上只是用于组织事物。
回答by JaredPar
Are you getting actual build errors or just squiggles? Try building and look at the output window, does it succeed or fail?
你得到实际的构建错误还是只是曲线?尝试构建并查看输出窗口,它是成功还是失败?
In VS 2008 SP1 C# introduced a top level error squiggling feature. It's possible that if you open the solution item version of the file it will squiggle because of a lack of default references. The solution should still build correctly though.
在 VS 2008 SP1 C# 中引入了顶级错误曲线功能。如果您打开文件的解决方案项版本,它可能会因为缺少默认引用而呈波浪形。尽管如此,该解决方案仍应正确构建。
If this is not the case try adding the file directly to the project (no link). See if that eliminates the error. If so then we know it has to due with a linked file and it can help track down the problem.
如果不是这种情况,请尝试将文件直接添加到项目中(无链接)。看看这是否消除了错误。如果是这样,那么我们知道它必须通过链接文件到期,它可以帮助追踪问题。
回答by Adam Houldsworth
You are very likely missing a reference to the DataVisualization DLL. Note that although they share the namespace of System.Windows.Forms.dll, they aren't actually contained within it.
您很可能缺少对 DataVisualization DLL 的引用。请注意,尽管它们共享 System.Windows.Forms.dll 的命名空间,但它们实际上并未包含在其中。