Dapper ambiguous extension methods

…衆ロ難τιáo~ 提交于 2019-12-01 16:01:57

I bumped into the same problem after I added the package MiniProfiler.Providers.SqlServer, which depends on the Dapper.StrongName package, which depends on Dapper.

Obviously I didn't want to use the already referenced package of MiniProfiler, since it is always better to have control, like updating it when a new version is released.

The solution to resolving ambiguous code between assemblies is to assign an extern alias name/s to at least one of the assembly packages, so when you then want to refer to one of them, you can then specify which one you want to reference by using the alias name.

Here is the solution that worked for me:

To give an alias name to assembly Dapper.StrongName, I added the following to my .csproj file:

<Target Name="StrongNameAlias" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
  <ItemGroup>
    <ReferencePath Condition="'%(FileName)' == 'Dapper.StrongName'">
      <Aliases>MP_DapperStrongNameAlias</Aliases>
    </ReferencePath>
 </ItemGroup>
</Target>

And then, if you'd want to refer to that, you can reference the assembly namespace by its newly added alies in .cs file, with the :: operator:

using MP_DapperStrongNameAlias::Dapper;

So now you can freely add using Dapper;, and it won't conflict anymore.

This Article might be helpful: C# 2.0: Using different versions of the same dll in one application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!