Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Services.AddOptions() ambiguous

Tags:

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"
    ]
  }
}
like image 439
Dave New Avatar asked Jun 18 '16 10:06

Dave New


2 Answers

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.

like image 50
Tseng Avatar answered Sep 28 '22 04:09

Tseng


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

like image 32
Sock Avatar answered Sep 28 '22 05:09

Sock