tek
tek

Reputation: 353

Blend crash with ObservableAsPropertyHelper

Microsoft Blend 2013 crashes immediately when I try to load a WPF solution developed in Visual Studio 2013. The (abbreviated) error message I receive is: System.Exception: An OnError occurred on an object (usually ObservableAsPropertyHelper) that would break a binding or command. To prevent this, Subscribe to the ThrownExceptions property of your objects ---> System.InvalidOperationException: No connection string named 'RecipeModelContainer' could be found in the application config file.

The application builds fine and executes when I run it. Before this particular issue started, Blend consistently showed the missing connection string message; this message originated when I set the DataContext in my code-behind, and has persisted ever since I transferred the DataContext reference to my XAML. In any case, the connection string is most definitely there.

I am experimenting with ReactiveUI to develop a user control, and am using an ObservableAsPropertyHelper property. Here is the property:

private ObservableAsPropertyHelper<IList<string>> _matches;
public IList<string> Matches
{
    get
    {
        return _matches.Value;
    }
}

... And here is the related content in my ViewModel constructor:

var searchTerms = this.ObservableForProperty(x => x.IngredientFilter)
                   .Value()
                   .Throttle(TimeSpan.FromSeconds(0.2));
var searchResults = searchTerms.SelectMany(st => SearchIngredients(st));
_matches = searchResults.ToProperty(this, x => x.Matches);

Being relatively unfamiliar with Reactive Extensions and confused why Blend cares what is in my app.config file, I'm at a loss how to implement the recommended error handling or otherwise manage this problem. I have tried cleaning my solution as well as deleting the .suo files. Any suggestions?

Upvotes: 1

Views: 470

Answers (1)

tek
tek

Reputation: 353

I have identified two solutions for this problem. The first implements the ThrownException handling per the Blend error message recommendation:

_matches.ThrownExceptions.Subscribe(e => MessageBox.Show(e.Message));

This launches two MessageBox windows on Blend startup that read "No connection string named RecipeModelContainer could be found in the application config file", but at least Blend doesn't crash.

Second, it turns out that the issue resulted from a zero delay in my async SearchIngredients method, which basically queries an Entity Framework DbContext object for matches. I had added await Task.Delay(0) simply to fake an async method for searchTerms.SelectMany (the application hangs if the method is not async). It's still not clear to me what this has to do with the app.config file, but the issue disappears altogether when I change to a non-zero delay.

Upvotes: 1

Related Questions