question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Setting the design time datacontext making the designer stop responding

See original GitHub issue

I followed the Avalonia docs to set the datacontext but whenever I set it the designer suddenly stops responding to changes and hangs up until I remove the datacontext: I tried setting it using: d:DataContext="{x:Static dd:McalUiViewModelDesignData.ViewModel}" and
<Design.DataContext> <viewModels:ViewModel /> </Design.DataContext> and both doesn’t work

NOTES: I am using jetbrains rider IDE version “2022.1.1” and avaloniaRider version “1.0.0.2140933515”

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
hhyyrylainencommented, Aug 11, 2022

I just had a bug like this where my data context constructor was running into an exception. This unhandled exception doesn’t seem to be logged anywhere. After a lot of looking I realized what the problem was for me (I specifically removed the initialization of a component that is actually needed in design mode). I’m not 100% sure it was an exception, only just pretty sure based on the fact I was using a IServiceProvider that had a missing service and the preview started working once I added the service I realized was missing.

So it would be very nice if the rider avalonia output would show something more than:

System.IO.EndOfStreamException: Attempted to read past the end of the stream.
   at Avalonia.Remote.Protocol.BsonStreamTransportConnection.ReadExact(Byte[] buffer) in /_/src/Avalonia.Remote.Protocol/BsonStreamTransport.cs:line 59
   at Avalonia.Remote.Protocol.BsonStreamTransportConnection.Reader() in /_/src/Avalonia.Remote.Protocol/BsonStreamTransport.cs:line 71

when there are problems like this.

0reactions
WilbertOnGithubcommented, Aug 2, 2023

Just leaving this here in case someone else stumbles into this problem. I encountered the same issue as described by @hhyyrylainen where the logfile of the designer showed the following:

System.IO.EndOfStreamException: Attempted to read past the end of the stream.
   at Avalonia.Remote.Protocol.BsonStreamTransportConnection.ReadExact(Byte[] buffer) in /_/src/Avalonia.Remote.Protocol/BsonStreamTransport.cs:line 59
   at Avalonia.Remote.Protocol.BsonStreamTransportConnection.Reader() in /_/src/Avalonia.Remote.Protocol/BsonStreamTransport.cs:line 71

In my case, I’m using the MVVM toolkit and inject the viewmodel into the view using the following

public partial class ApartmentConfigurationView : UserControl
{
    public ApartmentConfigurationView()
    {
        InitializeComponent();
        DataContext = Ioc.Default.GetRequiredService<ApartmentConfigurationViewModel>();
    }

    private void InitializeComponent()
    {
        AvaloniaXamlLoader.Load(this);
    }
}

Then I added a design time reference to the view to preview my data:

   <Design.DataContext>
        <viewModels:ApartmentConfigurationViewModel/>
    </Design.DataContext>

Turns out that I forgot to register the viewmodel for usage with dependency injection. After registering it, the preview started working.

And I agree that the previewer should preferably give more helpful error message on what is actually happening 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting design time DataContext on a Window is giving a ...
Essentially I learned something new. The d: namespace prefix that Expression Blend/Visual Studio designer acknowledges is actually ignored/" ...
Read more >
WPF Design time binding not working
1.1 to 16.1.3 the WPF design time data isn't working. I get the name of Property I am binding to but not the...
Read more >
Use Design Time Data with the XAML Designer in Visual ...
The XAML Designer stopped working​​ Try closing and reopening the XAML file, and cleaning and rebuilding your project.
Read more >
Using Design-time Databinding While Developing a WPF ...
A trick that allows populating a user control with sample data while you are designing it in the Visual Studio designer.
Read more >
Usable WPF Design-Time Data for .NET 5.0 (and 6.0)
Shows design-time data consisting of values that are not what I specified in the Each WholeStatisticView instance in the designer is using the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found