Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ambiguous call services.AddOptions() in ConfigureServices(IServiceCollection services)

After adding services.AddOptions() in ConfigureServices(IServiceCollection services) the following error occurs:

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)'

Code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

...

public void ConfigureServices(IServiceCollection services)
{
    ...
    services.AddOptions();
    ...
}

This is particularly strange as the ambiguity is between the same 'methods or properites'

like image 925
Ovi Avatar asked May 23 '16 13:05

Ovi


1 Answers

Based on the feedback from this question I tracked down that I had a reference in project.lock.json to "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final" which on its own has a reference to "Microsoft.Extensions.OptionsModel": "1.0.0-rc1-final"

The whole point is to have only references to "Microsoft.Extensions.Options": "1.0.0-rc2-final" and remove all the ones to OptionsModel.

like image 102
Ovi Avatar answered Nov 08 '22 13:11

Ovi