WCF RIA Exception on Invoke operation interrupts Caliburn.Micro coroutine execution?

Topics: Actions & Coroutines
Mar 3, 2011 at 3:52 AM

I am executing a series of Caliburn.Micro IResults by yield returning them from an IEnumerable method called by a Caliburn.Micro action message. The first IResult calls a WCF RIA service Invoke operation. Sometimes this operation fails and throws an exception. This is handled in the IResult where the InvokeOperation object is checked for error, I mark the error as handled and set the IResult's error message field to the error so I can recover it from the client.

The problem is that for some reason this interrupts the co-routine executing. I can't think of any good reason why, but when I'm in debug mode VS skips to the server code and bring up the unhandled exception helper telling me there was an uncaught exception (duh), and the co-routine never continues executing the other members of the IEnumerable.

Here is some of the code.

Called from the Action Message:

public IEnumerable<IResult> Submit()
        var register = new RegisterUserResult(Username, Password, Email, _userModel);
        yield return register;

        if (register.Success)
            if (RegisterAsTrainer) 
                yield return new ApplyRoleToUserResult(Username, "Trainer", _userModel);
            yield return new NavigateResult(new Uri("/MainPageViewModel", UriKind.Relative));
        else ErrorMessage = register.ErrorMessage;

The code in the DomainService (which sometimes throws an exception)

    public void CreateUser(string username, string password, string email)
        Membership.CreateUser(username, password, email);

...where Membership is the ASP.NET class, which I am using for membership management.

The IResult that calls the above service (some details elided for clarity):

    public void Execute(ActionExecutionContext context)
        ErrorMessage = null;
        Success = false;

        var ctx = new TrainingContext();
        ctx.CreateUser(_username, _password, _email, CreateUserCallback, null);

    private void CreateUserCallback(InvokeOperation invokeOp)
        if (invokeOp.HasError)

        Completed(this, new ResultCompletionEventArgs
                Error = invokeOp.Error,WasCancelled = invokeOp.IsCanceled

The IResult.Completed DOES fire, but the rest of the method never executes. I'm literally tearing my hair out with this, please please help me.

Mar 3, 2011 at 4:07 AM

Ugh I figured this out, stupid me. I was setting the IResult Error field, thinking I'd need to use that information later. I didn't know that having a non-null Error field would cause co-routine execution to halt (I thought only the Canceled field would do that). I'll leave this here in case anyone else runs into this issue.

May 12, 2011 at 3:59 PM
Edited May 12, 2011 at 3:59 PM


can you please share you code that is used to connect with RIASERVICE and EDMX i dont know how to do that. I am struck with that...