简体   繁体   English

事件回调<dynamic>抛出 RuntimeBinderException</dynamic>

[英]EventCallback<dynamic> throws RuntimeBinderException

Using the default template I modified the Counter:使用默认模板我修改了计数器:

@code {
    private int currentCount = 0;

    private async void IncrementCount()
    {
        currentCount++;

        await UpdateCallback.InvokeAsync(new { Counter = currentCount });
    }

    [Parameter] public EventCallback<dynamic> UpdateCallback { get; set; }
}

And I am using it like this:我正在这样使用它:

<Counter UpdateCallback="(d)=>MyCallback(d,42)"></Counter>

@code {

    public void MyCallback(dynamic val, int number)
    {

    }
}

This leads to这将导致

Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot implicitly convert type 'void' to 'object'' Microsoft.CSharp.RuntimeBinder.RuntimeBinderException:'无法将类型'void'隐式转换为'object''

If I pass around a Tuple<dynamic> it works.如果我传递一个Tuple<dynamic>它可以工作。

Why is that?这是为什么?

You invoked using InvokeAsync so it is expecting a method which will return task not void.您使用 InvokeAsync 进行了调用,因此它需要一个返回任务不无效的方法。 Use this where you used your Counter component, i think that will solve your problem.在您使用 Counter 组件的地方使用它,我认为这将解决您的问题。

<Counter UpdateCallback="async (d)=> await MyCallback(d,42)"></Counter>

@code {

    public async Task MyCallback(dynamic val, int number)
    {

    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 动态转换为ObjectHandle会引发RuntimeBinderException - Casting dynamic to ObjectHandle throws RuntimeBinderException 动态属性分配引发RuntimeBinderException - Dynamic Property Assignment Throws RuntimeBinderException 为什么“((dynamic)dictionary).MyKey”抛出RuntimeBinderException? - Why “((dynamic) dictionary).MyKey” throws a RuntimeBinderException? 在嵌套在子文件夹中的Partial中使用@model dynamic会引发RuntimeBinderException - Using @model dynamic in a Partial nested in a subfolder throws RuntimeBinderException 为什么“动态”ExpandoObject 即使包含属性定义也会抛出 RuntimeBinderException? - Why 'dynamic' ExpandoObject throws RuntimeBinderException even if it contains the definition for a property? 具有动态变化的事件回调 class? - Eventcallback with dynamic change class? C#动态-“ RuntimeBinderException” - C# Dynamic - “RuntimeBinderException” 将C#动态与COM对象一起使用会引发RuntimeBinderException,以记录已实现接口的方法 - Using C# dynamic with COM object throws RuntimeBinderException for documented method of implemented interface 从继承的接口调用Method时传递动态参数会引发RuntimeBinderException - Passing a dynamic parameter throws RuntimeBinderException when calling Method from Inherited interface 拦截动态调用以避免RuntimeBinderException - Intercept a dynamic call to avoid RuntimeBinderException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM