从Unity到HoloLens的程序问题-无法从“字符串"转换为"System.IO.Stream" [英] Program Issues Going From Unity To HoloLens - Cannot convert from 'string' to 'System.IO.Stream'
问题描述
我有一个使用C#用Unity编写的程序,该程序初始化一个新的StreamReader并继续从我存储在Unity资源文件夹中的文本文件中读取文本数据.当我在Unity中单击播放时,一切正常,一切正常,文本被阅读并完美显示.但是,当我尝试构建它以便通过HoloLens模拟器运行它(平台:Windows Store,SDK:Universal 10,构建并在以下计算机上运行:本地计算机)时,出现错误:错误CS1503:参数1:无法转换从字符串"到"System.IO.Stream".
I have a program written in Unity using C# that initializes a new StreamReader and proceeds to read the text data from a text file I have stored in Unity's resources folder. Everything works fine when I click play in Unity -everything works and the text is read and displayed perfectly. However, when I try to build it in order to run it via the HoloLens emulator (Platform: Windows Store, SDK: Universal 10, Build and Run On: Local Machine), I get the error: error CS1503: Argument 1: cannot convert from 'string' to 'System.IO.Stream'.
我不明白为什么这个错误甚至会首先出现,因为StreamReader的构造函数有一个接受字符串参数的重载.
I don't understand why this error is even showing up in the first place as the constructor for a StreamReader has an overload that accepts a string parameter.
我的代码如下:
string metadata = String.Format("/Resources/.../metadata.txt", list);
if (File.Exists(Application.dataPath + metadata))
{
using (StreamReader sr = new StreamReader(Application.dataPath + metadata))
{
// ....
}
}
推荐答案
我同意其他观点,这可能是由于编辑器中的mono与要获取UWP应用程序而编译的.net之间的差异引起的.尝试以下方法:
I agree with the others, this is likely caused by a diffence between mono in the editor and the .net that you are compiling with to get a UWP application. Try this instead:
using(StreamReader sr = new StreamReader(new FileStream(Application.dataPath + metadata, FileMode.Open)))
这应该是合法的mono和.net代码.
This should be legal mono and .net code.
这篇关于从Unity到HoloLens的程序问题-无法从“字符串"转换为"System.IO.Stream"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!