System.Windows.Forms。DataVisualization命名空间可以在一个类中使用,但不能在另一个类中使用

时间:2022-10-27 07:34:18

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?)

在名称空间的System.Windows中不存在类型或名称空间名称“DataVisualization”。“表格”(您是否缺少汇编引用?)

Here is my using section of the class:

以下是我的课堂使用部分:

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 include。我能想到的唯一不同之处是,给出这个缺失名称空间错误的类是解决方案项,而不是特定于项目的。项目通过链接引用它们。有人知道问题出在哪里吗?我已经为Visual Studio 2008安装了图表组件。net 3.5 SP1和图表插件。

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:从解决方案项目中删除项目,并将它们放在我的项目下。另一个项目仍然在引用文件,这就是为什么我以前认为它不工作的原因。不过,我仍然很好奇,为什么当类是解决方案项时,我不能使用名称空间,而是将它们移动到项目之下(请注意,没有修改),使它们可以立即识别。:\

3 个解决方案

#1


1  

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.

据我所知,解决方案文件夹/项目只是用来组织事情的。

#2


1  

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,它们实际上并不包含在其中。

#3


0  

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.

如果不是这样,请尝试直接将文件添加到项目中(没有链接)。看看这是否消除了错误。如果这样,我们就知道它必须与一个链接文件一起,它可以帮助跟踪问题。

#1


1  

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.

据我所知,解决方案文件夹/项目只是用来组织事情的。

#2


1  

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,它们实际上并不包含在其中。

#3


0  

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.

如果不是这样,请尝试直接将文件添加到项目中(没有链接)。看看这是否消除了错误。如果这样,我们就知道它必须与一个链接文件一起,它可以帮助跟踪问题。