My platform is Deepin Linux.
I follow the document but get the following errors after I run it:
Unhandled Exception: Portable.Xaml.XamlObjectWriterException: The value for 'Content' property is null
at Portable.Xaml.XamlObjectWriterInternal.OnWriteGetObject() in D:\a\1\s\src\Markup\Avalonia.Markup.Xaml\PortableXaml\portable.xaml.github\src\Portable.Xaml\Portable.Xaml\XamlObjectWriter.cs:line 375
at Portable.Xaml.XamlWriterInternalBase.WriteGetObject() in D:\a\1\s\src\Markup\Avalonia.Markup.Xaml\PortableXaml\portable.xaml.github\src\Portable.Xaml\Portable.Xaml\XamlWriterInternalBase.cs:line 202
at Portable.Xaml.XamlServices.Transform(XamlReader xamlReader, XamlWriter xamlWriter, Boolean closeWriter) in D:\a\1\s\src\Markup\Avalonia.Markup.Xaml\PortableXaml\portable.xaml.github\src\Portable.Xaml\Portable.Xaml\XamlServices.cs:line 136
at Avalonia.Markup.Xaml.AvaloniaXamlLoader.LoadFromReader(XamlReader reader, AvaloniaXamlContext context, IAmbientProvider parentAmbientProvider) in D:\a\1\s\src\Markup\Avalonia.Markup.Xaml\AvaloniaXamlLoader.cs:line 193
at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Stream stream, Assembly localAssembly, Object rootInstance, Uri uri) in D:\a\1\s\src\Markup\Avalonia.Markup.Xaml\AvaloniaXamlLoader.cs:line 169
at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Type type, Object rootInstance) in D:\a\1\s\src\Markup\Avalonia.Markup.Xaml\AvaloniaXamlLoader.cs:line 77
at Avalonia.Markup.Xaml.AvaloniaXamlLoader.Load(Object obj) in D:\a\1\s\src\Markup\Avalonia.Markup.Xaml\AvaloniaXamlLoader.cs:line 45
at Todo.Views.MainWindow.InitializeComponent() in /home/frank/dotnet_playground/Test/Todo/Views/MainWindow.xaml.cs:line 16
at Todo.Views.MainWindow..ctor() in /home/frank/dotnet_playground/Test/Todo/Views/MainWindow.xaml.cs:line 11
at Todo.Program.AppMain(Application app, String[] args) in /home/frank/dotnet_playground/Test/Todo/Program.cs:line 27
at Todo.Program.Main(String[] args) in /home/frank/dotnet_playground/Test/Todo/Program.cs:line 14
@factormystic @ForNeVeR @mterwoord
The value for 'Content' property is null
Unfortunately, Portable.Xaml doesn't know about the concept of human readable errors.
"The value for 'Content' property is null" basically means that it couldn't resolve some type in your XAML file. Most common cause of this exception is something like this:
<UserControl xmlns="https://github.com/avaloniaui">
<MyClassWithTypoInName/>
</UserContol>
There is no way to know where the typo is. We are currently working on replacing Portable.Xaml with something better.
So, is there any solution now to resolve this problem?
Sharing your code could help to identify the cause
So, for what it's worth: I got here from a web search for this exception after trying to follow the tutorial, trying to build after the second page of it ( http://avaloniaui.net/docs/tutorial/creating-a-view ). Since it was a pretty minimal amount of code added by that point, and @kekekeks comment did put me on the right track for figuring out what went wrong, at least in my particular case:
When running dotnet new avalonia.usercontrol -o Views -n TodoListView, the codebehind for TodoListView did not get the correct namespace for the template. Instead of Todo.Views, the template just left AvaloniaAppTemplate.Namespace. It might be that this is why @hexiangdong2017 also came across this exception?
I faced a similar problem, to solve it helped me to add a line
xmlns:views="clr-namespace:AvaloniaAppTemplate.Namespace"
In MainWindow.xaml and specify in view the same namespace, any other namespace will trigger this error
The problem with the tutorial seems to be bound to the command (I only tried .net core)
dotnet new avalonia.usercontrol -o Views -n TodoListView
It generates both the TodoListView.xaml and TodoListView.xaml.cs with namespace AvaloniaAppTemplate.Namespace, while MainWindow.xaml and MainWindows.xaml.cs have namespace Configurator.Views . This discrepancy leads to the error.
The code in the tutorial is correct, but if you do not copy and paste the whole content of the files you'll end up with the error.
In general .to fix, replace AvaloniaAppTemplate.Namespace with the correct namespace.
Just merged a PR to fix the tutorial https://github.com/AvaloniaUI/avaloniaui.net/pull/71 and the unhelpful error message should be fixed on master thanks to #2322, so going to close this!
Most helpful comment
Unfortunately, Portable.Xaml doesn't know about the concept of human readable errors.
"The value for 'Content' property is null" basically means that it couldn't resolve some type in your XAML file. Most common cause of this exception is something like this:
There is no way to know where the typo is. We are currently working on replacing Portable.Xaml with something better.