Error thrown when building XAML derived from non-XAML base
I have a derived class set up like so:
WindowBase.cs
GenericWindow.cs
The GenericWindow XAML file:
Note that WindowBase has no XAML associated with it. It is pure C#, as required by WPF. When I build my Noesis assets, I get the following error:
[error] [DX9] Assets/UI/GenericWindow.xaml
Parsing GameUI.WindowBase (@1,1).
'GameUI.GenericWindow' doesn't inherit from 'GameUI.WindowBase'
-Void OnLog(Int32, System.String) (NoesisBuildToolKernel.cs:194)
-Void Build() (NoesisBuildToolKernel.cs:140)
-Void Build(System.String) (NoesisSettings.cs:276)
Any suggestions for why I am getting this error?
Thanks,
Mark
WindowBase.cs
Code: Select all
[Noesis.Extended]
public class WindowBase : ContentControl
Code: Select all
[Noesis.Extended]
[Noesis.UserControlSource("Assets/UI/GenericWindow.xaml")]
public class GenericWindow : WindowBase
Code: Select all
<local:WindowBase
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:GameUI"
mc:Ignorable="d"
x:Class="GameUI.GenericWindow"
x:Name="WindowBase"
d:DesignWidth="350" d:DesignHeight="296" FontFamily="/GameUI;component/Fonts/#Arial" Content="WindowBase">
<local:WindowBase.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="GameControls.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</local:WindowBase.Resources>
</local:WindowBase>
[error] [DX9] Assets/UI/GenericWindow.xaml
Parsing GameUI.WindowBase (@1,1).
'GameUI.GenericWindow' doesn't inherit from 'GameUI.WindowBase'
-Void OnLog(Int32, System.String) (NoesisBuildToolKernel.cs:194)
-Void Build() (NoesisBuildToolKernel.cs:140)
-Void Build(System.String) (NoesisSettings.cs:276)
Any suggestions for why I am getting this error?
Thanks,
Mark
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: Error thrown when building XAML derived from non-XAML ba
I tried your sample and after scripts are compiled by Unity, the xaml is built without problems.
Just for your information, you don't have to specify the [Noesis.UserControlSource] attribute if you are not deriving from UserControl. This attribute is necessary to automatically load the specified xaml file when creating your UserControl. For example:
In this code, when new MyUserControl() is called, the associated MyUserControl.xaml gets automatically loaded, and then it is set as the content of the supplied container.
If you are inheriting from ContentControl, no xaml is associated with the user class. You have to manually load the xaml, that will create your user class (the one specified in x:Class) when xaml gets loaded.
Just for your information, you don't have to specify the [Noesis.UserControlSource] attribute if you are not deriving from UserControl. This attribute is necessary to automatically load the specified xaml file when creating your UserControl. For example:
Code: Select all
[Noesis.Extended]
[Noesis.UserControlSource("Assets/UI/MyUserControl.xaml")
public class MyUserControl : UserControl
{
}
void SomeFunction(Noesis.ContentControl container)
{
container.SetContent(new MyUserControl());
}
If you are inheriting from ContentControl, no xaml is associated with the user class. You have to manually load the xaml, that will create your user class (the one specified in x:Class) when xaml gets loaded.
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: Error thrown when building XAML derived from non-XAML ba
Hi Mark,
I found a situation where the error you commented can be reproduced.
If you have a class like this:
And a xaml like this:
Already builded and playable in Unity. And then you modify it at once to this:
When you come back to Unity, Unity triggers our AssetPostProcessor first and then compiles the script. Because of this order, we are building the xaml against the old compiled script, where GenericWindow derives from ContentControl, and that's why you get the 'GameUI.GenericWindow' doesn't inherit from 'GameUI.WindowBase' error message.
We are working on a solution to avoid this undesired behavior. It will be fixed for the next release.
Thanks for reporting.
I found a situation where the error you commented can be reproduced.
If you have a class like this:
Code: Select all
public class GenericWindow : Noesis.ContentControl { }
Code: Select all
<ContentControl x:Class="GenericWindow" ... />
Code: Select all
public class WindowBase : Noesis.ContentControl { }
public class GenericWindow : WindowBase { }
Code: Select all
<local:WindowBase x:Class="GenericWindow" ... />
We are working on a solution to avoid this undesired behavior. It will be fixed for the next release.
Thanks for reporting.
Re: Error thrown when building XAML derived from non-XAML ba
Thanks for the replies. I was able to fix the error by moving the derived file GenericWindow.xaml.cs to a folder that would be built after the folder that contained WindowBase.xaml.cs. So it appears the build order of scripts matters.
-
sfernandez
Site Admin
- Posts: 3184
- Joined:
Re: Error thrown when building XAML derived from non-XAML ba
In 1.1.9 we improved the post-process mechanism. Now xaml resources are built after Unity ends to compile, if there was any modified, the scripts. This way, xaml resource will be built against the last version of your custom classes.
Who is online
Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 2 guests