question

SmilingMoon avatar image
0 Votes"
SmilingMoon asked SmilingMoon answered

Windows Application Package Project throws Could not load file or assembly for UWP project.

141808-image.png




When running uwp app by itself, it runs perfect. When I add the uwp app to Windows Application Package Project (WAPP), it throws "Could not load file or assembly.." exception on the spot meeting the first "await".

Where can I specify the version of the library in WAPP? I cannot find any place for version specification.

UWP runs good by itself, but when run WAPP, the exception occurs. I think this is caused by mismatch of the referencing .NET library version between WAPP and UWP app itself. Where should I start from?

windows-uwpdotnet-package-management
image.png (27.3 KiB)
· 6
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Can you share more code about writelog method?

0 Votes 0 ·

Here is the code:

         private static SemaphoreSlim log_Semaphore = new SemaphoreSlim(1, 1);
         public async static Task WriteLog(string msg)
         {
             if (SysFolders.LogFile == null)
             {
                 return;
             }
             await log_Semaphore.WaitAsync();
             try
             {
                 string log = $"Logged at {DateTime.Now.ToLocalTime().ToString()} -----------" + Environment.NewLine + msg + Environment.NewLine;
                 await Windows.Storage.FileIO.AppendTextAsync(SysFolders.LogFile, log);
             }
             catch (Exception ex)
             {
                 // If another option is available to the app to log error(i.e. Azure Mobile Service, etc...) then try that here
                 string s = ex.Message;
             }
             finally
             {
                 log_Semaphore.Release();
             }
         }


0 Votes 0 ·

I don't think it's related WriteLog code because it still happens when I change the code like below;

141919-image.png




Code hits "Console.WriteLine(msg);" code in the method and it throws when it is out of the method.

0 Votes 0 ·
image.png (48.9 KiB)

Yep, you code looks current, and the problem looks the project has not loaded System.Threading assembly. Unfortunately, we can't reproduce your problem with blank uwp. we suggest your edit your app's target version to restore the assemblies. or update the project's Microsoft.NETCore,UniversalWindowsPlatform nuget to latest version.

0 Votes 0 ·
Show more comments

1 Answer

SmilingMoon avatar image
0 Votes"
SmilingMoon answered

After long struggle, here is the solution: create branch new projects from scratch.

Nuget package issue is one thing.
Also, there must be a bug in Package project. When I use the existing UWP project which has been submitted to Store many times, package project cannot find the dependencies.

So, I created new UWP project and added to Package project and rebuild entire project little by little carefully: copying codes and adding the Nuget packages.
It worked.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.