C# 找不到类型或命名空间“TextFieldParser”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15419475/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 16:46:06  来源:igfitidea点击:

the type or namespace "TextFieldParser" could not be found

c#visual-studio-2010textfield

提问by user1158745

I am trying to use TextfieldParser that was found within Reading CSV files using C#. I am using VS 2010 and doing this in C#.

我正在尝试使用在Read CSV files using C# 中找到的 TextfieldParser 。我正在使用 VS 2010 并在 C# 中执行此操作。

I keep on getting "the type or namespace "TextFieldParser" could not be found.."

我不断收到“找不到类型或命名空间“TextFieldParser”的信息..”

When I try and add the using line, it will only go using Microsoft.VisualBasic; deep and not using Microsoft.VisualBasic.FileIO;

当我尝试添加 using 行时,它只会使用 Microsoft.VisualBasic;深入而不是使用 Microsoft.VisualBasic.FileIO;

Any help would be great.

任何帮助都会很棒。

采纳答案by user1158745

Added it as a reference and now it seems to work.

添加它作为参考,现在它似乎工作。

回答by Mark P.

In Visual Studio, right click on Referencesin the Solution Explorerside panel. Click "Add Reference".

在Visual Studio中,右键单击ReferencesSolution Explorer侧面板。单击“添加引用”。

In that list be sure to check Microsoft.VisualBasic. Hit OK.

在那个列表中一定要检查Microsoft.VisualBasic。点击确定。

Now in the namespace, add Using Microsoft.VisualBasic.FileIO.

现在在命名空间中,添加Using Microsoft.VisualBasic.FileIO.

That will allow you to use TextFieldParser. For a good, easy example on how to use it, look here: http://geekswithblogs.net/brians/archive/2010/07/07/whats-a-nice-class-like-textfieldparser-doing-in-a-namespace.aspx

这将允许您使用 TextFieldParser。有关如何使用它的一个简单的好例子,请看这里:http: //geekswithblogs.net/brians/archive/2010/07/07/whats-a-nice-class-like-textfieldparser-doing-in-a -namespace.aspx

回答by llessurt

For uncompiled files (aspx / ashx), you need to put an reference in the web.config. (They cannot use the project references.)

对于未编译的文件(aspx/ashx),需要在web.config中放一个引用。(他们不能使用项目引用。)

<system.web>
    <compilation debug="true" targetFramework="4.6.1">
      <assemblies>
        <add assembly="Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
      </assemblies>
    </compilation>
</system.web>

Alternatively for web applications, it would be preferred to put the code in a compiled file (cs/vb) and add a reference to the project.

或者,对于 Web 应用程序,最好将代码放在编译文件 (cs/vb) 中并添加对项目的引用。

See this question microsoft.visualbasic.fileio does not exist.

看到这个问题microsoft.visualbasic.fileio 不存在

回答by llessurt

Application references are not available to uncompiled files in your application (aspx, ashx). The reference would need added to the web.config or else the code would need moved to a compiled file (cs/vb).

应用程序引用不可用于应用程序中的未编译文件(aspx、ashx)。需要将引用添加到 web.config,否则代码需要移动到编译文件 (cs/vb)。