AvaloniaUI / AvaloniaVS

Visual Studio Extension for Avalonia
MIT License
412 stars 77 forks source link

Previewer breaks and shows debug error message if project doesn't reference a theme package. #431

Closed rabbitism closed 6 months ago

rabbitism commented 7 months ago

Describe the bug

Please see issue in https://github.com/irihitech/Semi.Avalonia/issues/252. Originally I thought it's Semi.Avalonia's bug, but I tried and it reports the same error if I remove all theme packages.

To Reproduce

Create a new Avalonia project. Remove FluentTheme from App.xaml Build and check previewer of MainWindow.

AvaloniaVS plugin version

11.5

Avalonia version

11.0.6

Visual Studio version

17.8.0

Relevant log output

System.Xaml.XamlException: 'Internal compiler error while transforming node XamlX.Ast.XamlAstNamePropertyReference:
XamlX.XamlTypeSystemException: Unable to resolve type Avalonia.Data.RelativeSource
at XamlX.TypeSystem.XamlTypeSystemExtensions.GetType(IXamlTypeSystem sys, String type) in //src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github/src/XamlX/TypeSystem/TypeSystem.cs:line 312
at Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers.AvaloniaXamlIlWellKnownTypes..ctor(TransformerConfiguration cfg) in //src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs:line 195
at Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers.AvaloniaXamlIlWellKnownTypesExtensions.GetAvaloniaTypes(AstTransformationContext ctx) in //src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlWellKnownTypes.cs:line 276
at Avalonia.Markup.Xaml.XamlIl.CompilerExtensions.Transformers.AvaloniaXamlIlResolveClassesPropertiesTransformer.Transform(AstTransformationContext context, IXamlAstNode node) in //src/Markup/Avalonia.Markup.Xaml.Loader/CompilerExtensions/Transformers/AvaloniaXamlIlClassesPropertyResolver.cs:line 18
at XamlX.Transform.AstTransformationContext.Visitor.Visit(IXamlAstNode node) in /_/src/Markup/Avalonia.Markup.Xaml.Loader/xamlil.github/src/XamlX/Transform/AstTransformationContext.cs:line 62 Line 1, position 2.' Line number '1' and line position '2'.

Additional context

No response

maxkatz6 commented 7 months ago

It’s not related to themes. But likely .net trimmer removes RelativeSource struct as it’s not used in the rest of the precompiled project. Keep in mind, that previewer compiles previewing XAML file on top of already compiled project. In this case we want to avoid trimming as much as possible.

maxkatz6 commented 7 months ago

This PR should have technically make it work better. At least for a typical runtime loader. But I suppose there something else that makes these trimming attributes useless https://github.com/AvaloniaUI/Avalonia/pull/12937

rabbitism commented 5 months ago

Unfortunately, this issue is still not resolved. With 11.0.7, it reports the same error when only referencing Semi theme. Is there anything I should do to fix from my side?

ZecosMAX commented 4 months ago

@rabbitism At least for me, as i use Material.Avalonia theme, putting <FluentTheme /> above desired to be used theme in App.axaml solves the issue, previewer is working, and theme is being overwritten by a theme declared after. Only pain in the need to delete this line every-time and recompile when i want to deploy

rabbitism commented 4 months ago

@rabbitism At least for me, as i use Material.Avalonia theme, putting <FluentTheme /> above desired to be used theme in App.axaml solves the issue, previewer is working, and theme is being overwritten by a theme declared after. Only pain in the need to delete this line every-time and recompile when i want to deploy

This issue magically disappeared after 11.0.9

maxkatz6 commented 4 months ago

Yes, it was fixed