Skip to content

Static resources declared in App.xaml are not applied #47

Closed

Description

@zbigniew-gajewski

Steps to reproduce:

  1. Clone this repository, restore nuget packages, rebuild.
  2. Run UnoTest.Web project (right click, start new instance) - clicking the button will increase the counter - OK.
  3. Change MainPage.xaml by adding DataContext attribute to the header:
<Page x:Class="UnoTest.MainPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      xmlns:local="using:UnoTest"
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
      mc:Ignorable="d"
      DataContext="{Binding MainPageViewModelInstance, Source={StaticResource Locator}}">
    
        <Grid  Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
...
</Page>

image

  1. In MainPage.xaml.cs remove (or comment) line creating a new instance of the MainPageViewModel class:
public sealed partial class MainPage : Page
{
        public MainPage()
        {
            InitializeComponent();
//            DataContext = new MainPageViewModel();
        }
  } 

image

  1. Rebuild the whole solution.

Result:
6. Run UnoTest.UWP project (right click, start new instance) - clicking the button will increase the counter - correct behavior after change.
7. Run UnoTest.Web project (right click, start new instance) - clicking the button will not increase the counter - bad behavior after change.

Expected result:
After running UnoTest.Web app, clicking the button should increase the counter.

Activity

  1. jeromelaban commented on Jun 16, 2018

    @jeromelaban
    Member

    This is a known issue for WASM, this works for iOS and Android.

    The best workaround for now is to declare it in a merged resource dictionary.

  2. added
    platform/wasm 🌐
    kind/bug
    on Jun 16, 2018
  3. removed
    platform/wasm 🌐
    on Jul 11, 2018
  4. changed the title [-]Wasm - static resources declared in App.xaml doesn't work.[/-] [+]Static resources declared in App.xaml are not applied[/+] on Jul 11, 2018
  5. self-assigned this
    on Jun 19, 2019
  6. carldebilly commented on Jun 19, 2019

    @carldebilly
    Member

    I reproduced the problem and I found the cause... it's very far from the reported bug.

    The actual cause

    The Wasm version of MvvmLight will use the netstandard1.0 version of the package and the IoC in this version won't implement the IServiceLocator.

    See those lines: https://github.com/nventive/uno.mvvmlight/blob/3408287579ace291c9519edefc8017df6a151aac/GalaSoft.MvvmLight/GalaSoft.MvvmLight.Extras%20(PCL)/Ioc/ISimpleIoc.cs#L38-L40

    Since the project Uno.Core is compiled in netstandard2.0, it will include his own version of CommonServiceLocator (v1.3) as defined in this bug I just opened: unoplatform/Uno.Core#53

    What is happening in the app

    1. The initial navigation to MainPage.xaml will be initiated

    2. In the MainPage.xaml InitializeComponent(), Uno will successfully resolve the Locator resource

    3. Uno will call the MainPageViewModelInstance property of ViewModelLocator

    4. This one will cast SimpleIoc.Default as IServiceLocator, which is not implemented this way

      Code here: https://github.com/zbigniew-gajewski/uno-wasm-aspnet-core/blob/78e9491427166d4a4242ddbec85e7080c38f51e9/UnoTest/UnoTest.Shared/ViewModels/ViewModelLocator.cs#L24

    5. A null-reference exception will terminate the initial navigation, leading to the false interpretation there's a problem with resources.

    I will close this bug as not related to Uno directly (the real issue has been created in Uno.Core project). Feel free to reopen it or ask more details.

  7. carldebilly commented on Jun 19, 2019

    @carldebilly
    Member

    Ooohhh... by the way, to find this problem I found those 2 assemblies must be removed from linker in the LinkerConfig.xml:

    <assembly fullname="UnoTest.Wasm" />
    <assembly fullname="GalaSoft.MvvmLight.Platform" />
  8. zbigniew-gajewski commented on Jun 19, 2019

    @zbigniew-gajewski
    Author
    1. Thanks for diagnosing the bug.
    2. Unfortunately without <assembly fullname="UnoTest.Wasm" /> accessing data with BreezeSharp doesn't work, I mean, the list with received data is not displayed.
  9. carldebilly commented on Jun 19, 2019

    @carldebilly
    Member

    When I said removed from linker, it means those lines must be added to the config file ;-)

    Sorry for the confusion.

  10. zbigniew-gajewski commented on Jun 19, 2019

    @zbigniew-gajewski
    Author

    Aaa, OK :) Thanks.

  11. added a commit that references this issue on Nov 18, 2021
  12. added a commit that references this issue on Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions