ASPNET Core pre-RC2 dependency ambiguity

别来无恙 提交于 2019-12-11 01:05:19

问题


I am using:

.NET Command Line Tools (1.0.0-rc2-002439)

Product Information:
Version:     1.0.0-rc2-002439
Commit Sha:  ef0c3b2cee

Runtime Environment:
OS Name:     Windows
OS Version:  10.0.10586
OS Platform: Windows
RID:         win10-x64

and getting:

error CS0121: The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action)' and 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.Configure(Microsoft.Extensions.DependencyInjection.IServiceCollection, System.Action)'

I suspect there are multiple OptionsModel assemblies (different versions) included on "dotnet restore".

The proof may be here:

The second suggestion with different parameter name:

Project.lock.json file has few interesting lines ("Infrastructure" is a referenced assembly):

"Infrastructure/1.0.0": {
    "type": "project",
    "framework": ".NETFramework,Version=v4.6.1",
    "dependencies": {
      "Domain": "1.0.0",
      "Microsoft.Extensions.Caching.Abstractions": "1.0.0",
      "Microsoft.Extensions.OptionsModel": "1.0.0",
      "Newtonsoft.Json": "8.0.3",
      "WindowsAzure.Storage": "6.2.1"
    },
    "compile": {
      "net461/Infrastructure.dll": {}
    },
    "runtime": {
      "net461/Infrastructure.dll": {}
    }
  }

while the web application uses Microsoft.Extensions.OptionsModel/1.0.0-rc2-15914

Here is the configuration section of Infrastructure assembly:

"dependencies": {
    "Domain": "1.0.0-*",
    "Microsoft.Extensions.Caching.Abstractions": "1.0.0-*",
    "Microsoft.Extensions.OptionsModel": "1.0.0-*",
    "Newtonsoft.Json": "8.0.3",
    "WindowsAzure.Storage": "6.2.1-*"
}

The question is: why different versions (1.0.0 and 1.0.0-rc2-15914) are chosen while executing "dotnet restore"?

UPDATE: I tried changing project.json of Infrastructure project to "Microsoft.Extensions.OptionsModel": "1.0.0-rc2-15914" but I am still can't compile because of ambiguity displayed in screenshots. Are any assemblies cached somewhere on my computer?


回答1:


The solution is:

Microsoft.Extensions.Options instead of Microsoft.Extensions.OptionsModel package had to be used in a referenced project.



来源:https://stackoverflow.com/questions/36769984/aspnet-core-pre-rc2-dependency-ambiguity

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