Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]
Posted
Updated 12-Sep-20 2:04am
v2
Comments
OriginalGriff 20-Jan-12 2:55am    
DON'T SHOUT. Using all capitals is considered shouting on the internet, and rude (using all lower case is considered childish). Use proper capitalisation if you want to be taken seriously.

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."
 
Share this answer
 
Comments
lukeer 20-Jan-12 3:02am    
Too fast for me, +5.
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.
 
Share this answer
 
if you'r using the File and you get that error try using the full name (with namespaces too)

so instead of (for example)

C#
File file = new File()


use

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


that's the better way.

otherwise you can use alias for namespaces,

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

....

siof.File file = new siof.File()

// or

sf.File file = new sf.File()
 
Share this answer
 
Comments
supernorb 10-Apr-13 6:01am    
I know this is too outdated but I just want to give my vote of 5 to you for the suggestion of using alias. Thanks.
Hi, use IO.File.Exists(Ruta_Exist)
 
Share this answer
 
After doing all of that be sure to recompile as that was the only way I stopped the false error messages.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900