UWP 应用程序从商店下载时崩溃,但在旁加载时不会崩溃

UWP App crashes when downloaded from store, but not when sideloaded

如果我通过 Visual Studio 部署我的应用程序 (UWP、C#/xaml),或者如果我在我的 phone 上侧载应用程序,我的应用程序 (UWP、C#/xaml) 在发布模式下工作正常。

但是如果我从商店下载并 运行 它,它会崩溃并出现以下异常

System.IO.FileLoadException : Could not load file or assembly 'System.Threading, Version=4.0.10.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

此外,PC 上的相同应用程序 运行 不会在 sideloading/loading 上通过 VS 甚至从商店下载时崩溃。 任何帮助将不胜感激。

编辑:代码片段 > private static Dictionary lockDictionary = new Dictionary();

    private static SemaphoreSlim getLockElement(string fileName)
    {
        if (lockDictionary.ContainsKey(fileName))
            return lockDictionary[fileName];
        else
        {
            SemaphoreSlim objectToReturn = new SemaphoreSlim(1);
            lockDictionary.Add(fileName, objectToReturn);
            return objectToReturn;
        }
    }

    private async static Task<StorageFile> getFile(string key)
    {
        try
        {
            return await storageFolder.GetFileAsync(key);
        }
        catch (FileNotFoundException ex)
        {
            return null;
        }
    }

    public static async Task<string> readFileDataIndependentOfUserId(string key)
    {
        AccountFunctions.logMsg("Awaiting " + key);
        await getLockElement(key).WaitAsync();
        AccountFunctions.logMsg("Got into " + key);

        try
        {
            StorageFile File = await getFile(key);
            if (File == null)
                return null;
            string text = await FileIO.ReadTextAsync(File);

            return text;
        }
        finally
        {
            AccountFunctions.logMsg("Released " + key);
            getLockElement(key).Release();
        }
    }

    public static async Task saveDataInFileIndependentOfUserId(string key, string data)
    {
        AccountFunctions.logMsg("Awaiting " + key);
        await getLockElement(key).WaitAsync();
        AccountFunctions.logMsg("Got into " + key);

        try
        {
            var FileName = key;
            var Fileoption = CreationCollisionOption.ReplaceExisting;
            var File = await storageFolder.CreateFileAsync(FileName, Fileoption);
            await FileIO.WriteTextAsync(File, data);
            AccountFunctions.logMsg("Saving : " + key + " : " + data);
        }
        finally
        {
            AccountFunctions.logMsg("Released " + key);
            getLockElement(key).Release();
        }
    }

    public static async Task removeFileDataIndependentOfUserId(string key)
    {
        AccountFunctions.logMsg("Awaiting " + key);
        await getLockElement(key).WaitAsync();
        AccountFunctions.logMsg("Got into " + key);

        try
        {
            StorageFile File = await getFile(key);
            if (File == null)
            {
                getLockElement(key).Release();
                return;
            }
            await File.DeleteAsync();
        }
        finally
        {
            AccountFunctions.logMsg("Released " + key);
            getLockElement(key).Release();
        }
    }

崩溃发生在包含这些静态函数的 class 的构造函数中。 AccountFunctions.logMsg 是一个仅在附加时写入调试器的函数。

您似乎没有在本地构建中启用 .NET Native。如果您查看项目属性 > 构建,您将看到启用 .NET Native 工具链的复选框。确保选中发布框,因为这是您在商店中构建的配置。

UWP 模板为 RELEASE 配置添加了这个属性:true。如果您已将一个旧项目迁移到 UWP,那么将您的项目文件与空白 UWP 模板进行比较可能会很有用,以查看是否有任何其他可能会给您带来麻烦的异常情况。