My application (UWP,C#/xaml) works fine in release mode if I deploy it through Visual Studio, or if I sideload the appx on my phone.
But if I download it from store and run it, it crashes with the following exception
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)
Also, the same app runs on PC without crashing on sideloading/loading through VS or even when downloaded from store. Any help would be appreciated.
Edit: Code Snippet > 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();
}
}
The crash occurs in constructor of my class containing these static functions. AccountFunctions.logMsg is a function that just writes to the debugger if attached.
It seems as though you may not have .NET Native enabled in your local builds. If you look at project properties > Build you'll see a checkbox for Enable .NET Native tool chain. Make sure that box is checked for Release because that's the configuration you get built with in the Store.
The UWP template has this attribute added for RELEASE configurations: true. If you've migrated an old project to UWP it may be useful to diff your project file with the blank UWP template to see if there's any other oddities that may cause you trouble.