UWP at design-time: "Could not load file or assembly" for various NuGet packages

0

I'm using Visual Studio 2017 v15.3.3. My UWP project is targeting Windows Creators Update 15063, and my Nuget packages are as follows:

enter image description here

My solution builds without errors, and runs fine, however I am encountering errors at design-time in my UWP app project, due to the fact that my code-behind and/or ViewModel code is referencing NuGet packages. This is what I'm seeing:

enter image description here

This problem is not unique to System.Reactive. I encounter a different (but seemingly related) error with the Newtonsoft.Json v10.0.3 package:

Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The bound assembly has a version that is lower than that of the request. (Exception from HRESULT: 0x80132000)

Interestingly, downgrading System.Reactive to v3.0.0 doesn't fix the issue: the error claims that the system can't find the v3.0.0 assembly.

Similar issue with the latest AutoMapper package (v6.1.1)

To reproduce the problem:

  1. Create a new UWP project (target whatever, it doesn't seem to matter)
  2. Create a new UserControl
  3. In the constructor of this UserControl, add some code referencing any of those packages, for example, var s = new Subject<int>(); and add using System.Reactive.Subjects;
  4. Add that user control as a XAML element in MainPage.xaml
  5. Compile and note the error

... or check out this sample here

The frustrating thing is that those big 3 packages (System.Reactive, Newtonsoft.Json, AutoMapper) all worked fine in my UWP project when it was in Visual Studio 2015 a few weeks ago before switching to VS 2017.

The only thing that has worked so far is downgrading Newtonsoft.Json from the latest v10.0.3 to v9.0.1 (downgrading to v10.0.2 or 10.0.1 did not work). Unfortunately I cannot downgrade System.Reactive as they have unlisted versions lower than 3.0

I have also tried performing a repair of my VS installation, as well as installing the mobile/xamarin components.

Any workarounds or insights would be much appreciated, since this is a blocking issue for me, thanks!

uwp
json.net
nuget
system.reactive
xaml-designer
asked on Stack Overflow Sep 8, 2017 by BCA • edited Sep 12, 2017 by Nico Zhu - MSFT

1 Answer

2

The problem is that the 3.0.0 version of System.Reactivecan not be very compatible with UWP. And I solve this via update to System.Reactive 4.0.0-preview with the following command in Package Manager Console.

Install-Package System.Reactive -Version 4.0.0-preview00001

And you could also Disable project code in the xaml designer to solve this. For more, you could refer to Debugging or Disabling Project Code in XAML Designer.

In many cases, unhandled exceptions in the XAML designer can be caused by project code attempting to access properties or methods which return different values or work in different ways when your application is running in the designer. You can resolve these exceptions by debugging the project code in another instance of Visual Studio, or temporarily prevent them by disabling project code in the designer.

enter image description here

Update

For Newtonsoft.Json, it seems that WinRT component failed to find the correct assembly of Newton.Json. Temporarily the workaround is to manually add the Newtonsoft.json.dll file. You can achieve this by following steps:

Right click References-> Add Reference->Browse...-> Find C:\Users.nuget\packages\Newtonsoft.Json\10.0.3\lib\portable-net45+wp80+win8+wpa81\Newtonsoft.json.dll->Click Add button. Rebuild your project and run. This error should be gone.\

And you could also use the above way to solve the AutoMapper issue .

answered on Stack Overflow Sep 12, 2017 by Nico Zhu - MSFT • edited Sep 13, 2017 by Nico Zhu - MSFT

User contributions licensed under CC BY-SA 3.0