Could not load assembly System.Runtime in Xamarin.Forms UWP Project with .NET Standard library

I'm in the process of setting up a Xamarin.Forms app using .NET Standard for the shared library instead of a PCL. I've followed the instructions for doing so laid out in the blog/video on the topic (on msdn)

This is with a brand new Xamarin.Forms app, created using Visual Studio 2017 with a PCL, which was replaced with a .NET Standard library as described in the video.

The UWP app compiles fine, but throws this exception when I try to start it (on the call to Xamarin.Forms.Forms.Init)

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

I've tried specifically adding the nuget package for System.Runtime, version 4.1.0 to the UWP project, but that doesn't seem to help. It runs fine in Android, but keeps giving me this exception running the UWP project. Can anyone tell me what might be causing this and how I can fix it?

Answers

  • KatieBrownKatieBrown USMember ✭✭

    there is a very similar error in the build log:

    Could not resolve this reference. Could not locate the assembly "System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
    

    Followed by an extremely long list of places it has checked.

    I also found this, which seems like it may be the problem:

    2>  There was a conflict between "System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
    2>      "System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
    

    There's also this in the build logs right after the above, which is even more perplexing, as it seems to indicate the only thing referencing version 4.0.20.0 of System.Runtime is... version 4.3.0 of System.Runtime???

    2>      References which depend on "System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Users\Katie\.nuget\packages\system.runtime\4.3.0\ref\netcore50\System.Runtime.dll].
    2>          C:\Users\Katie\.nuget\packages\system.runtime\4.3.0\ref\netcore50\System.Runtime.dll
    2>            Project file item includes which caused reference "C:\Users\Katie\.nuget\packages\system.runtime\4.3.0\ref\netcore50\System.Runtime.dll".
    2>              C:\Users\Katie\.nuget\packages\system.runtime\4.3.0\ref\netcore50\System.Runtime.dll
    

    Does anyone know how I can resolve this conflict?

  • TiesTies NLMember ✭✭

    Any update on this matter? I have almost the same error but on the files: "clrcompression", "clrjit,", "sqlite3," and "ucrtbased"

  • toto_____toto_____ FRMember

    Hi KatieBrown and Ties,

    I have exactly the same exception thrown when I run the UWP application. Did you find a workaround to solve this issue. I tried also installing the version 4.1.0 of System.Runtime.dll but it does not work at all.

    Thanks in advance for any help.

  • MarkZhukovskyMarkZhukovsky USMember ✭✭
    edited January 2018

    Update your Microsoft.NETCore.UniversalWindowsPlatform nuget package to 6.0.5 and this problem should go away @toto_____ @Ties @KatieBrown

  • YasarYucelYesilbagYasarYucelYesilbag USMember ✭✭

    @MarkZhukovsky, your suggestion worked for me, solved the problem. Thank you.

Sign In or Register to comment.