Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do Callbacks with Dynamic?

I keep getting this error and not sure how to correct it

Error 1 Cannot use 'Callback' as an argument to a dynamically dispatched operation because it is a method group. Did you intend to invoke the method?

    //...
    if (e.Status == LiveConnectSessionStatus.Connected)
    {              
        client = new LiveConnectClient(e.Session);
        LiveOperationResult operationResult = await client.GetAsync("me");
        try
        {

            dynamic meResult = operationResult.Result;

            var openId = meResult.id;
            var email = meResult.emails.preferred;
            //MessageBox.Show(openId);
            //MessageBox.Show(email);
           userService.SignIn(openId, email, Callback);


        }
        catch (LiveConnectException exception)
        {
            MessageBox.Show("Error calling API: " + exception.Message);
        }
    }
}

private void Callback(ErrorModel error)
{
    if (error != null)
    {
        MessageBox.Show(error.FriendlyErrorMsg, error.Caption, MessageBoxButton.OK);
    }
    else
    {

    }
}

public void SignIn(string id, string email, Action<ErrorModel> callBack)
{

}
like image 229
chobo2 Avatar asked Mar 17 '14 21:03

chobo2


People also ask

What is a dynamic callback?

This feature allows you to specify a custom redirect URL. This URL will be sent to the server as the redirect_uri parameter. This feature can be used to redirect the user to your application where you will use the code/access_token as required.

What is the correct way of adding callback decorator?

The @app. callback decorator needs to be directly above the callback function declaration. If there is a blank line between the decorator and the function definition, the callback registration will not be successful.

Can we have multiple callbacks in dash?

As of dash v1. 19.0 , you can create circular updates within the same callback. Circular callback chains that involve multiple callbacks are not supported.

What is app callback in Python?

Callbacks are python decorators that control the interactivity of your dash app. A decorator is a function that wraps around another function, executing code before and/or after the function they decorate.


1 Answers

The problem is that this call is dynamic:

userService.SignIn(openId, email, Callback);

It has to be, because openId and email are inferred to be of type dynamic:

var openId = meResult.id;
var email = meResult.emails.preferred;

You can't use a method group conversion like this in a dynamic call - it's just one of the restrictions of using dynamic.

So, options:

  • Give openId and email explicit types, which (if userService isn't dynamic) will make the call non-dynamic, at which the method group conversion will work. This just means specifying the types explicitly, as there's an implicit conversion available from dynamic:

    string openId = meResult.id;
    string email = meResult.emails.preferred;
    userService.SignIn(openId, email, Callback);
    
  • Create a specific delegate type instance from the Callback method, if you want to keep the SignIn call dynamic:

    var openId = meResult.id;
    var email = meResult.emails.preferred;
    // Or use whichever delegate type is actually appropriate for SignIn
    userService.SignIn(openId, email, new Action<ErrorModel>(Callback));
    
like image 175
Jon Skeet Avatar answered Oct 11 '22 16:10

Jon Skeet