microsoft / TemplateStudio

Template Studio accelerates the creation of new WinUI 3, WPF, and UWP apps using a wizard-based experience.
Other
2.72k stars 462 forks source link

"Cannot deserialize XBF metadata type list as 'ViewModelLocator' was not found in namespace 'App1.ViewModels'. [Line: 0 Position: 0]" #1181

Closed IngoBleile closed 6 years ago

IngoBleile commented 7 years ago

As soon as I add a reference to a very simple .NET Standard 2.0 class library, I am getting this error.

mrlacey commented 7 years ago

@IngoBleile what's the library you're adding? What options did you choose when creating the project? Have you changed anything else since creating the project?

IngoBleile commented 7 years ago

(I am using VS 2017 15.5 Preview 1.)

crutkas commented 7 years ago

can you provide a repro? Does this same behavior happen with a file-> new?

crutkas commented 7 years ago

We treat stuff like this very serious but we need a way to hook a debugger into it / reproduce it. If you can provide step by step or a WTS project with the issue, we can start poking into it

ravindUwU commented 7 years ago

Hiya! I'm facing a problem very similar to this one. I've written a question about it on Stack Overflow here: https://stackoverflow.com/q/46501682/2466716

IngoBleile commented 7 years ago

Even with the most current Win 10 preview (1709 Build 16299.15), VS 2017 15.5 Preview 1 and the most current Windows Template Studio (1.3.17255.1), I am having the same issues. It seems related to MVVM Light as I am getting another error in a "MVVM basic" project (stack overflow in a navigation helper, as soon as I add my library).

  1. The generated app >> works fine
  2. I add a new project (.NET standard 2.0 class lib) with a cs file with some public enums >> I am getting the runtime error "Cannot deserialize XBF metadata type list as 'ViewModelLocator' was not found in namespace 'App1.ViewModels'. [Line: 0 Position: 0]" as soon as the app is starting

The error occurs as soon as I change this:

namespace MyApp
{
    public static class Enums
    {
        public enum MessageType
        {
            Info,
            Warning,
            Error
        }

to this:

namespace MyApp
{
    public enum MessageType
    {
        Info,
        Warning,
        Error
    }
ralarcon commented 7 years ago

The latest version published version from Windows Template Studio is 1.3. I'm going to try to make a repro with that version and with the current pre-release (1.4 will be published soon)

crutkas commented 7 years ago

Can someone provide a repro so we can throw a debugger against it and see diffs between generated code and modifications made

IngoBleile commented 7 years ago

It's quite easy, takes just one minute.

  1. Create a new app with "Pivot and Tabs" & MVVM Light & all the features from the "Select pages and features" page.
  2. Change the project properties to Target a current Win 10 Fall Creator's Update's prerelease (e. g. Build 16299), Target Version & Min Version. (Referencing .NET standard 2.0 libraries doesn't work with the current Win 10 release but it does with the current prereleases.) Start the app >> works perfectly.
  3. Create a new .NET standard 2.0 class library project.
  4. Change the created class like that:
using System;

namespace ClassLibrary1
{
    public enum MessageType
    {
        Info,
        Warning,
        Error
    }
}
  1. Reference the class library from the UWP app.

The error occurs when the execution leaves the App() constructor.

ralarcon commented 7 years ago

Hi,

I been able to reproduce this behavior using the v1.3 of Windows Template Studio.

I've verified that the issue is not constrained to MVVM Light. If you chose the combination Blank + Code Behind you'll have the same behavior. I've found a couple of references related to this, one which explictly mention that this is not a bug.

The root cause is related to a version inconsistence with NET Standard libraries used by the UWP app (created with WTS) and the NET Standard class library.

If you are using the v1.3 of WTS and the latest win SDK (16299), you can get rid of this issue by changing the Microsoft.NETCore.UniversalWindowsPlatform reference from 5.2.3 to 6.0.1 in the .csproj file Before: image

After: image

Or you can take advantage of the recently launched pre-release version of Windows Template Studio recently released and now targeting the latest 16299 sdk and 6.0.1. (v0.9.17286.1 or higher).

Hope this helps.

IngoBleile commented 7 years ago

@ralarcon: You made my day, thanks a lot! :)

BTW: After trying the same with a MVVM Basic (not MVVM Light) project template, I got a stack overflow exception at a navigation helper's Frame.Navigate() method. But my problem is solved now, thanks again.

crutkas commented 6 years ago

can this be closed out?

ralarcon commented 6 years ago

I think so!