aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Eventhandlers not binding as expected: The call is ambiguous between BindMethods.GetEventHandlerValue...

Open Psvensso opened this issue 8 years ago • 6 comments

Trying to update the blazor-realworld-example-app on a local fork but having problems updating to the new onclick="@x" binder syntax.

Example: <a class="nav-link" onclick="@clicktest"> Click test</a>

void clicktest(UIMouseEventArgs e) { Console.WriteLine("Click testing "); }

Result: The call is ambiguous between the following methods or properties: 'BindMethods.GetEventHandlerValue(Action)' and 'BindMethods.GetEventHandlerValue(Func<T, Task>)' BlazorRealworld (Same result with or without the UIMouseEventArgs n the handler)

Note: A lambda works fine <a class="nav-link" onclick="@((e)=>clicktest(e))"> Click test </a>

Refs:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <RunCommand>dotnet</RunCommand>
    <RunArguments>blazor serve</RunArguments>
  </PropertyGroup>

  <ItemGroup>
    
    <PackageReference Include="CommonMark.NET" Version="0.15.1" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.0-preview2-final" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.Blazor.Browser" Version="0.3.0" PrivateAssets="all" />
    <PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="0.3.0" />
    <PackageReference Include="Microsoft.NET.Sdk.Razor" Version="2.1.0-preview2-final" PrivateAssets="All" />
    <DotNetCliToolReference Include="Microsoft.AspNetCore.Blazor.Cli" Version="0.3.0" />
  </ItemGroup>
</Project>

Core SDK: 2.1.300-preview2-008533 Test repo: https://github.com/Psvensso/blazor-realworld-example-app/tree/onclick-snapshot

Psvensso avatar May 06 '18 07:05 Psvensso

It works in release version 0.3.0

dlr1 avatar May 06 '18 07:05 dlr1

Upgrading to 0.3.0 on available packages does not resolve it. (Edited issue description)

Psvensso avatar May 06 '18 08:05 Psvensso

@Psvensso Your test repo has global.json which refers dotnet core SDK 2.1.300-preview1-008174. 0.3.0 requires 2.1.300-preview2-008533 or later.

SIkebe avatar May 06 '18 08:05 SIkebe

@Psvensso you need to configure the project for C# 7.3, add <LangVersion>7.3</LangVersion> to your <PropertyGroup> of your .csproj

Suchiman avatar May 06 '18 10:05 Suchiman

@Psvensso See this "Upgrade an existing project to Blazor 0.3.0" section for more detail. https://blogs.msdn.microsoft.com/webdev/2018/05/02/blazor-0-3-0-experimental-release-now-available/

SIkebe avatar May 06 '18 10:05 SIkebe

Ah! Almost made it without the blogpost, just need the final refs and BS4 upgrades. Thank you for your time :)

Psvensso avatar May 07 '18 04:05 Psvensso