1

Windows Phone アプリケーションに問題があると思います。私のアプリケーションには、特定のフォルダーにあるテクスチャのコレクションを返す静的メソッドがあります。WP 8 エミュレーターでアプリケーションを起動すると、非常にうまく機能しますが、WP 7 エミュレーターで起動すると、「ディレクトリが存在しません」というメッセージで例外が発生します。しかし、実際にはこのディレクトリは存在します。なぜこれが起こるのか誰か教えてもらえますか?

ここに私のコードを添付しました:

namespace Hornbook_v2
{
    public static class ContentLoader
    {
        public static Dictionary<String, T> LoadTextures<T>(this ContentManager contentManager, string contentFolder)
        {
            //Load directory info, abort if none
            DirectoryInfo dir = new DirectoryInfo(contentManager.RootDirectory + "\\" + contentFolder);

            //  The exception is happends HERE!!!
            if (!dir.Exists)
                throw new DirectoryNotFoundException();

            //Init the resulting list
            Dictionary<String, T> result = new Dictionary<String, T>();

            //Load all files that matches the file filter
            FileInfo[] files = dir.GetFiles("*.*");
            foreach (FileInfo file in files)
            {
                string key = Path.GetFileNameWithoutExtension(file.Name);

                //result[key] = contentManager.Load<T>(contentManager.RootDirectory + "/" + contentFolder + "/" + key);
                result[key] = contentManager.Load<T>(contentFolder + "/" + key);
            }

            //Return the result
            return result;
        }    

    }
}
4

1 に答える 1

1

その 1 つの DirectoryExists だけでこれを確認する場合でも、IsolatedStorage API を使用してみることができます。

編集

すべてを IsolatedStorage に移植する必要がある場合は、次の MSDN ページが役立つ場合があります。

于 2013-05-21T06:45:55.920 に答える