Skip to main content
 首页 » 编程设计

c#之MonoTouch iOS应用程序无法在设备目录中找到文件-在模拟器上工作

2024年01月18日57myhome

如果我在设备上运行此代码,它将返回“get it”:

if (Directory.Exists (NSBundle.MainBundle.BundlePath + "/ARCSDev")) { 
                Console.WriteLine ("got it"); 
            } else { 
                Console.WriteLine ("can't find it"); 
            } 

这意味着该目录位于主捆绑包中。

我需要在此方法调用中使用该文件:
private void generateChart (int chartNumber, string palette) 
        { 
            string filePath = NSBundle.MainBundle.BundlePath + "/ARCSDev"; 
 
            Console.WriteLine("Filepath - " + filePath); 
 
            Loader loader = new Loader (filePath); 
            loader.LoadChart (Convert.ToString (chartNumber)); 

上面的代码可以在模拟器上正常运行,但不能在设备上运行。

当设备上发生错误时,我得到以下堆栈跟踪:
System.InvalidOperationException: Operation is not valid due to the current state of the object 
  at System.Linq.Enumerable.Max[TileIndexRecord] (IEnumerable`1 source, System.Func`2 selector) [0x00000] in <filename unknown>:0 
  at MyCompany.Data.Arcs.Loader.ExtractWriteableBitmap (MyCompany.Data.Arcs.Records.RGBPaletteRecord rgbPalette, Double dpi, MyCompany.Data.Arcs.Raschts.ChartIndexFile indexFile, MyCompany.Data.Arcs.Raschts.RasterChartFile chartFile) [0x00000] in /Users/me/Desktop/ARCSViewer/ARCSViewer/Loader.cs:571 
  at MyCompany.Data.Arcs.Loader.GetHiResImage (MyCompany.Data.Arcs.Records.RGBPaletteRecord rgbPalette) [0x00000] in /Users/me/Desktop/ARCSViewer/ARCSViewer/Loader.cs:362 
  at ARCSViewer.SecondViewController.generateChart (Int32 chartNumber, System.String palette) [0x0004e] in /Users/me/Desktop/ARCSViewer/ARCSViewer/SecondViewController.cs:118 
  at ARCSViewer.SecondViewController.ViewDidAppear (Boolean animated) [0x00007] in /Users/me/Desktop/ARCSViewer/ARCSViewer/SecondViewController.cs:84 
  at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 
  at ARCSViewer.Application.Main (System.String[] args) [0x00000] in /Users/me/Desktop/ARCSViewer/ARCSViewer/Main.cs:17 

该目录包含UNIX可执行文件和发光文件。

谁能解释发生了什么事?该文件肯定在正确的位置(捆绑包),因为我已经测试了检查是否与其他我知道也存在的文件一起存在的代码。

请您参考如下方法:

这可能是区分大小写的问题,模拟器不区分大小写,而设备区分大小写。检查您的文件,看看您是否以正确的大小写(即不仅是目录)访问所有文件。