Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET the following 2 lines give a compile error, why?

Tags:

.net

vb.net

I have the following 2 lines in ASP.NET in VB.NET (For C# just replace the world 'Dim' with 'var') that I got from an example.

 Dim tmpFile = Path.GetTempFileName()
 Dim tmpFileStream = File.OpenWrite(tmpFile)

I get an error on File.OpenWrite(tmpFile) that says 'Overload resolution failed because no accessible 'File' accepts this number of arguments'. Can anyone explain why this error is happening? I tried looking at documentation and can't seem to figure it out. Thank you.

like image 272
Art F Avatar asked Feb 19 '23 12:02

Art F


1 Answers

Notice that the error message is specifying File and not OpenWrite. It looks like there is another File in context which has a higher precedence than System.IO.File. This is likely the source of the error. Try using a fully qualified name here

Dim tmpFileStream = System.IO.File.OpenWrite(tmpFile)
like image 133
JaredPar Avatar answered Feb 21 '23 18:02

JaredPar