Dataportal error not sent to Silverlight client

Dataportal error not sent to Silverlight client

Old forum URL: forums.lhotka.net/forums/t/10346.aspx


wilfreds posted on Thursday, May 05, 2011

Hi have a Sliverlight mvvm project. And everything seems to be working. I can retrieve and update so the dataportal must be working.

But when I insert this line in the fetch method, just for testing purposes, the program stops in the debugger with the message: "Exception was unhandled by user code".

        private void DataPortal_Fetch()
        {
            throw new Exception("My error");

The error does not get to the OnError. Any suggestions?

 

This is the class:

    public class ButOrderHeadListViewModel : ViewModel<Library.ButOrderHeadList>
    {
        public ButOrderHeadListViewModel()
        {
          Shell.Instance.ShowStatus(new Status { Text = "Loading list", IsBusy = true });
          BeginRefresh("GetButOrderHeadList");
        }
 

        ButOrderHeadInfo _SelectedItem;
        public ButOrderHeadInfo SelectedItem
        {
            get { return _SelectedItem; }
            set { _SelectedItem = value; }
        }
 
        protected override void OnError(Exception error)
        {
          Shell.Instance.ShowError(error.Message, "Error");
          base.OnError(error);
        }
 
        protected override void OnRefreshed()
        {
          Shell.Instance.ShowStatus(new Status());
          base.OnRefreshed();
        }
 
        public override void Save(object sender, Csla.Xaml.ExecuteEventArgs e)
        {
          Shell.Instance.ShowStatus(new Status { Text = "Saving", IsBusy = true });
          base.Save(sender, e);
        }
 
        protected override void OnSaved()
        {
          Shell.Instance.ShowStatus(new Status { Text = "Saved" });
          base.OnSaved();
        }
 
    }

RockfordLhotka replied on Thursday, May 05, 2011

You may need a try..catch around the BeginRefresh call. There are some WCF exceptions that can occur before the call is handed off to the async processing, and those can't be returned via OnError because they happen before any of that plumbing is wired up.

wilfreds replied on Thursday, May 05, 2011

Tried that. But didn't help.

I tried to set a beakpoint on:

BeginRefresh("GetButOrderHeadList");

But the debugger did not stop there even if the line is executed. Must be something wrong with my project configuration/settings.

RockfordLhotka replied on Thursday, May 05, 2011

Then it sounds like the issue has nothing to do with the throwing of an exception on the server - it probably isn't even getting there.

wilfreds replied on Friday, May 06, 2011

On my WebServer project properties, at the web tab sheet. Checking debuggers->Silverlight took care of the problem not hitting my breakpoints. And now everything is working. OnError is executing.

Strangely I am now unable to get back to the state where it was not working. So if you have this problem, fiddeling around in the web properties may solve it Wink

RockfordLhotka replied on Friday, May 06, 2011

That is strange, but it happens to me all the time...

A true unhandled exception like that almost always indicates a very basic problem with the network communications - such that the call never actually makes it to the server. But they are really hard to debug, and (like you) I find that random messing around with the server config/properties often solves the issue.

Otherwise you have to fall back to fiddler, or enabling diagnostic trace logging in web.config, etc.

Copyright (c) Marimer LLC