【发布时间】:2013-08-08 14:28:34
【问题描述】:
以下代码在 Windows 中运行良好,但是,当使用 Xamarin 并以 iOS 为目标时,GetManifestResourceStream() 返回 null。
Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("CommunicationModel.XmlSchemas.DeviceCommon.xsd");
我已将文件“DeviceCommon.xsd”设置为嵌入式资源。不知道为什么它没有返回有效的流。
有人知道为什么这在使用 Xamarin 的 iOS 中不起作用吗?
更新:
好的,所以我按照 cmets 中的建议将文件设置为 Content。
我现在可以检测到文件,但无法打开它:
if (File.Exists("DeviceCommon.xsd"))
{
try
{
myStream = new FileStream("DeviceCommon.xsd", FileMode.Open);
}
....
}
当我运行上面的代码时,'File.Exists()' 调用有效,但是当我尝试打开它时,我得到以下异常:
Access to the path "/private/var/mobile/Applications/8BD48D1F-F8E8-4A80-A446-F807C6728805/UpnpUI_iOS.app/DeviceCommon.xsd" is denied.
任何人都知道我该如何解决这个问题???
谢谢, 柯蒂斯
【问题讨论】:
-
我不希望这会起作用,TBH。
-
我通常只是将文件作为内容包含在我的项目中。由于所有内容都打包成一个包含嵌入式资源文件的包,这对我来说不是什么大问题。
-
这应该可以 - 我猜该文件由于某种原因没有正确嵌入到程序集中。您可以在最终程序集上使用 Reflector 来检查资源是否存在(以及名称是什么)。
标签: c# ios cross-platform xamarin embedded-resource