C# Assembly.GetManifestResourceStream在iOS上不与Xamarin一起工作

C# Assembly.GetManifestResourceStream在iOS上不与Xamarin一起工作,c#,ios,cross-platform,xamarin,embedded-resource,C#,Ios,Cross Platform,Xamarin,Embedded Resource,下面的代码在Windows中运行良好,但是,当使用Xamarin并以iOS为目标时,GetManifestResourceStream()返回null Assembly assembly = Assembly.GetExecutingAssembly(); Stream stream = assembly.GetManifestResourceStream("CommunicationModel.XmlSchemas.DeviceCommon.xsd"); 我已将文件“DeviceCommon

下面的代码在Windows中运行良好,但是,当使用Xamarin并以iOS为目标时,GetManifestResourceStream()返回null

Assembly assembly = Assembly.GetExecutingAssembly();
Stream stream = assembly.GetManifestResourceStream("CommunicationModel.XmlSchemas.DeviceCommon.xsd");
我已将文件“DeviceCommon.xsd”设置为嵌入式资源。不确定它为什么不返回有效流

有人知道为什么在使用Xamarin的iOS中不起作用吗

更新:

好的,所以我按照注释中的建议将文件设置为内容

我现在可以检测到该文件,但无法打开它:

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.
有人知道我该怎么解决这个问题吗

谢谢,
柯蒂斯

好的,我终于让它开始工作了。在我的例子中,我对windows.dll和Xamarin.iOS.dll使用了相同的文件。虽然名称空间是相同的,但我对.dll项目的命名不同。不幸的是,microsoft文档说他们使用名称空间作为文件名的一部分。那不是真的。。它们使用.dll名称作为命名空间的一部分。这只是一个小小的差别,但却带来了所有的差别

所以,说到点子上。。我将文件属性设置为:“嵌入式资源”和“不复制”。我需要处理的资源都是扩展名为.xsd的文件,所以我只是循环遍历所有资源名,并使用以.xsd结尾的资源名。这样,无论它们在哪个操作系统上,名称都是正确的,因为我是通过编程方式检索它的,并且没有硬编码:

        Assembly assembly = Assembly.GetExecutingAssembly();
        string[] resources = assembly.GetManifestResourceNames();
        foreach (string resource in resources)
        {
            if(resource.EndsWith(".xsd"))
            {
                Stream stream = assembly.GetManifestResourceStream(resource);
                if (stream != null)
                {
                    XmlSchema schema = XmlSchema.Read(stream, null);
                    _schemas.Add(schema);
                }
            }
        }

至于我,我要做的就是正确地给它加前缀。不要查找“fooBar.baz”,而要查找“The.Name.of.The.Assembly.The.Folder.Inside.fooBar.baz”。

我不希望这样做,TBH。我通常只将文件作为内容包含在我的项目中。因为所有东西都打包到一个包中,并且有嵌入的资源文件,这对我来说不是什么大问题。这应该是可行的-我猜由于某种原因,文件没有正确嵌入到程序集中。您可以在最终部件上使用Reflector来检查资源是否存在(以及名称)。