5

I am busy migrating our ASP.NET Core API from RC1 to RC2.

RC2 requires that we configure the following when using IOptions<T>:

services.AddOptions();

But I get the following compilation error:

Error CS0121 The call is ambiguous between the following methods or properties: 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.AddOptions(Microsoft.Extensions.DependencyInjection.IServiceCollection)' and 'Microsoft.Extensions.DependencyInjection.OptionsServiceCollectionExtensions.AddOptions(Microsoft.Extensions.DependencyInjection.IServiceCollection)' TransitApi.Api..NET Framework 4.5.2

These are the exact same extension methods! I have tried deleting all packages and deleting the lock files, but to no avail.

The project.json:

{
  "title": "MyProject.Api",
  "webroot": "wwwroot",
  "version": "1.0.0-*",
  "dependencies": {

    "Microsoft.ApplicationInsights.AspNetCore": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Authorization": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.Core": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Mvc.Abstractions": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Authentication.JwtBearer": "1.0.0-rc2-final",
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Abstractions": "1.0.0-rc2-final",
    "Microsoft.Extensions.Logging.Console": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Http": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Http.Abstractions": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.Json": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0-rc2-final",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0-rc2-final",
    "Newtonsoft.Json": "8.0.3",
    "WindowsAzure.Storage": "7.0.0",
    "Microsoft.AspNetCore.Mvc.Formatters.Json": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0-rc2-final",
    "Microsoft.AspNetCore.Cors": "1.0.0-rc2-final"
  },
  "frameworks": {
    "net452": { }
  },
  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    }
  },
  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },
  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },
  "publishOptions": {
    "include": [
      "wwwroot",
      "appsettings.json",
      "web.config"
    ]
  }
}
svick
  • 236,525
  • 50
  • 385
  • 514
Dave New
  • 38,496
  • 59
  • 215
  • 394
  • Please don't put **tags** into Question Title. We spend much time fixing this all the day and have less time for answering questions. http://stackoverflow.com/help/tagging And don't use wrong tags neither. ASP.NET is for the legacy ASP.NET 4.5, **not** for ASP.NET Core – Tseng Jun 18 '16 at 11:05
  • I can't replicate this, running `dotnet restore` and then `dotnet build` on what you showed works fine for me. – svick Jun 18 '16 at 12:59

3 Answers3

2

Check out your dependencies under "References" within the project.

One of your dependencies is fetching old libraries, I suspect it's "WindowsAzure.Storage": "7.0.0" as it seems the only candidate for it. I think the 7.0.2 preview version is ready for rc2-final according to GitHub project page, try this please.

Tseng
  • 61,549
  • 15
  • 193
  • 205
2

While this doesn't directly your issue (I suspect @Tseng has correctly identified the dependency issue), you can probably safely omit the call to AddOptions().

The WebHostBuilder class implicitly calls AddOptions within the call to Build(), as can be seen in GitHub. Assuming you are building your web app in the usual way, AddOptions will already be registered on the service collection

Sock
  • 5,323
  • 1
  • 21
  • 32
0

Please see this link for additional information on how a reference to the older version for RC1 is most likely the issue.

aaronR
  • 1,557
  • 2
  • 16
  • 26