Skip to main content
 首页 » 编程设计

c#之命名空间 'File' 中不存在类型或命名空间名称 'System.IO'

2024年02月05日14oomusou

我正在尝试创建一个脚本,该脚本将使用 C# 在 Visual Studio 上打开 CSV 文件,但是当我引用 File 类时,将弹出错误:

The type or namespace name 'File' does not exist in the namespace 'System.IO'  

我确定我正在使用 System 以及 使用 System.IO 并去添加对 System.dll 的引用> 和 System.IO.dll 但是当我尝试添加它们时出现错误:

A reference to 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6\System.dll' could not be added. This component is already automatically referenced by the build system. 

System.IO.dll 出现同样的错误。

我正在使用 .NETFramework v4.6 和 Visual Studio 2015。

请您参考如下方法:

This component is already automatically referenced by the build system

此消息特定于不支持 File 类的项目模板。 Windows 商店、电话或通用。当你以它们为目标时,你必须跳过更多的环节,操作文件系统由运行时代理审查,确保你在允许查看的地方四处寻找。而且必须始终使用异步代码来完成,理论上它可能会很慢。

Windows.Storage.StorageFile class大致相似。