sgjsakura / AspNetCore

ASP.NET Core Extension Library
Apache License 2.0
162 stars 26 forks source link

VS2017, .NetCore.App 1.1.1 and Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata error #25

Closed sylvaincaillot closed 7 years ago

sylvaincaillot commented 7 years ago

Hello, Using VS2015 with the latest tools, i was having the same error as #23 .

Considering that I was using VS2015 and it is now strongly advised to move to VS2017 with the recent stable releases, I migrated everything to VS2017, upgraded to the most recent SDK (1.0.3 corresponding to 1.0.4 LTS version and 1.1.1 current version of .NetCore App). I have also checked that my Microsoft.AspNetCore.Mvc Nuget package was updated to 1.1.2.

Summary of my new csproj configuration file:

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

  <PropertyGroup>
    <AssemblyTitle>Test</AssemblyTitle>
    <Authors>...</Authors>
    <TargetFramework>netcoreapp1.1</TargetFramework>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>test.Web</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>test.Web</PackageId>
    <RuntimeIdentifiers>win7-x64</RuntimeIdentifiers>
    <RuntimeFrameworkVersion>1.1.1</RuntimeFrameworkVersion>
    <PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <None Update="wwwroot\**\*">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\test.BLL\test.BLL.csproj" />
    <ProjectReference Include="..\test.DAL\test.DAL.csproj" />
    <ProjectReference Include="..\test.Services\test.Services.csproj" />
    <ProjectReference Include="..\test.Identity\test.Identity.csproj" />
    <ProjectReference Include="..\test.Validation\test.Validation.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
    <PackageReference Include="Sakura.AspNetCore.PagedList" Version="2.0.1" />
    <PackageReference Include="BundlerMinifier.Core" Version="2.4.337" />
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="1.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.1" />
    <PackageReference Include="FluentValidation.AspNetCore" Version="6.4.0" />
    <PackageReference Include="LinqKit.Microsoft.EntityFrameworkCore" Version="1.1.10" />
    <PackageReference Include="Sakura.AspNetCore.Mvc.PagedList" Version="2.0.12" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
  </ItemGroup>

  <Target Name="PrepublishScript" BeforeTargets="PrepareForPublish">
    <Exec Command="bower install" />
    <Exec Command="dotnet bundle" />
  </Target>

</Project>

All my packages are up-to-date, I am using the latest stable releases but I am still having this "An item with the same key has already been added. Key: Microsoft.AspNetCore.Mvc.ModelBinding.Metadata.DefaultModelMetadata" issue which appears for all my pages using IPagedList.

Am i doing something wrong?

Thank you

S.

sgjsakura commented 7 years ago

@sylvaincaillot Hi, thank you for your feedback, in order to reproduce the problem, could you share a minimal project for this issue?

Thank you again and waiting for your kind reply :-)

sylvaincaillot commented 7 years ago

Thank you for your quick reply. This is short example in VS2017 which shows letters of the alphabet in a normal IList and then in a IPagedList with the error mentioned above.

Sakura_VS2017.gz

S.

sgjsakura commented 7 years ago

@sylvaincaillot Hi, this problem is confirmed and fixed. It is caused by incorrect handling for interface types with multiple base interfaces with same member names.

You may update Sakura.AspNetCore.PagedList to the lastest version of 2.0.2 or manually isntall the dependent internal package Sakura.AspNetCore.PagedList.Abstractions with version 2.0.1 to fix this problem.

Thank you again for your feedback and please fill free to reply if you have any new question.

sylvaincaillot commented 7 years ago

Thank you @sgjsakura. It works beautifully now.