如何解决这个错误'文件'是'Scripting.File'和'System.IO.File'之间的模糊参考 [英] How to solve this error 'File' is an ambiguous reference between 'Scripting.File' and 'System.IO.File'

查看:55
本文介绍了如何解决这个错误'文件'是'Scripting.File'和'System.IO.File'之间的模糊参考的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何解决此错误'文件'是Windows应用程序中'Scripting.File'和'System.IO.File'之间的模糊参考c#编码



SHOUTING已删除 - OriginalGriff [/ edit]

解决方案

如果您遇到此错误,则表示您有两个使用语句都包含一个名为File的类。其中一个是System.IO,另一个可能是Scripting。您可以:

1)使用语句删除您不感兴趣的语句的

2)完全通过在文件前加上脚本,在引用它时限定对象。或System.IO。


使用 System.IO.File Scriptin.File 而不仅仅是文件,在任何给定的错误发生时都是正确的。



你也可以删除其中一个 #using 。但我想,他们是有原因的。所以我会去选项#1。


如果您使用文件并且您得到该错误尝试使用全名(也使用名称空间)



而不是(例如)



文件文件= 文件()





使用



 System.IO.File file =  new  System.IO.File()





这是更好的方式。



否则你可以使用命名空间的别名,



 使用 siof = System.IO.File; 
使用 sf = Scripting.File

....

siof.File file = < span class =code-keyword> new siof.File()

//

sf.File file = new sf.File()


How to solve this error 'File' is an ambiguous reference between 'Scripting.File' and 'System.IO.File' in windows applications c# coding

[edit]SHOUTING removed - OriginalGriff[/edit]

解决方案

If you are gettign this error, it means that you have two using statements which both include a class called "File". One of these will be "System.IO", the other is probably "Scripting". You can:
1) Remove the using statement for the one you are not interested in.
2) Fully qualify the object when you reference it, by prefixing "File" with either "Scripting." or "System.IO."


Use System.IO.File or Scriptin.File instead of just File, whichever is the correct one at any given occurance of the error.

You could as well remove one of the #usings. But I suppose, they're there for a reason. So I would go for option #1.


if you'r using the File and you get that error try using the full name (with namespaces too)

so instead of (for example)

File file = new File()



use

System.IO.File file = new System.IO.File()



that's the better way.

otherwise you can use alias for namespaces,

using siof= System.IO.File;
using sf= Scripting.File

....

siof.File file = new siof.File()

// or

sf.File file = new sf.File()


这篇关于如何解决这个错误'文件'是'Scripting.File'和'System.IO.File'之间的模糊参考的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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