Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with xaml after upgrede to 0.9-rc1 #3340

Closed
OmidID opened this issue Dec 10, 2019 · 6 comments
Closed

Problem with xaml after upgrede to 0.9-rc1 #3340

OmidID opened this issue Dec 10, 2019 · 6 comments
Assignees
Labels

Comments

@OmidID
Copy link
Contributor

OmidID commented Dec 10, 2019

I get crash at Initialize method when I try to load Xaml file.

Avalonia.Markup.Xaml.XamlLoadException: 'No precompiled XAML found for ModulesSample.App, make sure to specify x:Class and include your XAML file as AvaloniaResource'

image

I added x:Class to be sure it's right target.

<Application xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Class="ModulesSample.App">
  <Application.Styles>
    <StyleInclude Source="resm:Avalonia.Themes.Default.DefaultTheme.xaml?assembly=Avalonia.Themes.Default"/>
    <StyleInclude Source="resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default"/>
  </Application.Styles>
</Application>

And this is what i have in .csproj file:

  <ItemGroup>
    <Compile Update="**\*.xaml.cs">
      <DependentUpon>%(Filename)</DependentUpon>
    </Compile>
    <AvaloniaResource Include="**\*.xaml">
      <SubType>Designer</SubType>
    </AvaloniaResource>
    <AvaloniaResource Include="Assets\*"/>
  </ItemGroup>
@donandren
Copy link
Contributor

@OmidID i think you need to ensure you reference the same and only Avalonia 0.9-* nuget
and may be use avares:// scheme for <StyleInclude Source="avares://...
like:

        <StyleInclude Source="avares://Avalonia.Themes.Default/DefaultTheme.xaml"/>
        <StyleInclude Source="avares://Avalonia.Themes.Default/Accents/BaseLight.xaml"/>

@OmidID
Copy link
Contributor Author

OmidID commented Dec 11, 2019

@donandren Actually I using build props files and I'm sure dependencies are OK.
You can get the source code from here and run the ModulesSample
https://github.com/OmidID/Prism.Avalonia
https://github.com/OmidID/Prism.Avalonia/blob/dev-7.2.0/build/AvaloniaDependency.props

avares:// didn't help

@donandren
Copy link
Contributor

donandren commented Dec 11, 2019

try add direct nuget reference in the project where app.xaml is defined:
<PackageReference Include="Avalonia" Version="0.9.0-rc.1" />
the avalonia build task responsible for generating resources might not be executing properly without direct reference to Avalonia nuget.
Some time ago i've made a pr #3151 to fix and diagnose similar issues, but it's still not reviewed :( and still it's harder to diagnose without it.

@OmidID
Copy link
Contributor Author

OmidID commented Dec 11, 2019

@donandren Great. that's the problem. Your changes are required.
After that I found out MainWindow needs the same approach with x:Class and I found out another problem that I have no idea for it. Because in Prism all the Views will prepare by Resolver then dependencies will be injected in the constructor and constructor parameterless is required by Xaml compiler

https://github.com/OmidID/Prism.Avalonia/blob/dev-7.2.0/samples/ModulesSample/MainWindow.xaml.cs#L22

1>D:\Projects\Prism.Avalonia\samples\ModulesSample\MainWindow.xaml(1,2,1,2): Avalonia error XAMLIL: Unable to find public constructor for type ModulesSample:ModulesSample.MainWindow() (line 1 position 2) Line 1, position 2.

So I have no idea what is the solution. In case if we have 2 constructor resolver will use the default constructor.

@Gillibald
Copy link
Contributor

Just use PropertyInjection or MethodInjection then

@OmidID
Copy link
Contributor Author

OmidID commented Dec 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants