Search code examples
asp.net-coreasp.net-core-mvcdotnet-cli

ASPNET Core pre-RC2 dependency ambiguity


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:

enter image description here The second suggestion with different parameter name:

enter image description here

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?


Solution

  • The solution is:

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