Problem:
There is a StreamReader in the project to read a file, using the OpenText () method.
But unity suggests that the StreamReader class does not contain the OpenText () method, and that no extension methods are found.
Reason:
This is very strange, StreamReader is the System.IO under the class, inside is indeed there is this method, but why unity is prompted to find a method?
After a variety of Baidu, eventually found the cause of the problem, because the current unity platform using the Webplayer platform, and the Webplayer platform is unable to operate these,
That is, the file IO is limited and cannot be used, so unity will make an error.
Workaround:
The workaround is also simple, just need to switch to another platform.
Attached error code: error is the 10th line of code.
1 PublicXcplist (stringFpath)2 {3FilePath = Path.Combine (Fpath,"Info.plist" );4 if( !System.IO.File.Exists (FilePath)) {5Debug.logerror (FilePath +"file does not exist under path" );6 return;7 }8 9FileInfo Projectfileinfo =NewFileInfo (filePath);TenStreamReader sr =Projectfileinfo.opentext (); One while(Sr.) Peek () >=0) A { - contents. Add (Sr. ReadLine ()); - } the Sr. Close (); - -}
Unity Pit-Compile error