[C#] System.IO

Hi, I have a scipt which acesses a file but why is this not working?

            System.IO.FileInfo finfo = new FileInfo(path);
            System.IO.StreamReader reader = finfo.OpenText();

The error is:

Type `System.IO.FileInfo' does not contain a definition for `OpenText' and no extension method `OpenText' of type `System.IO.FileInfo' could be found (are you missing a using directive or an assembly reference?)

But i have:

using UnityEngine;
using UnityEditor;
using System.IO;
using System;
using System.Collections.Generic;
using System.Xml;

try var reader = finfo.OpenText(); and let the compiler figure it out. I don’t think system.io.streamreader is correct.

Edit: Nvm, did some digging it is correct.

Restart Unity.

Works fine for me, why are you qualifying the types like that?

If it can’t find the FileInfo type when declaring finfo without putting System.IO in front then I’m not sure how new FileInfo(path) is working without also having a System.IO qualification.

2 Likes

It solved itself after a couple restarts. Thanks anyway.