本文介绍了暧昧通话services.AddOptions()在ConfigureServices(IServiceCollection服务)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

后加入 services.AddOptions() ConfigureServices(IServiceCollection服务)出现以下错误:

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'

推荐答案

根据从的追查,我曾在 project.lock.json A参考EntityFramework.MicrosoftSqlServer 7.0.0-RC1决赛其自身具有Microsoft.Extensions.OptionsModel的引用:1.0.0-RC1决赛

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"

整点是不得不Microsoft.Extensions.Options只引用:1.0.0-RC2-最后的并删除所有那些为 OptionsModel

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

这篇关于暧昧通话services.AddOptions()在ConfigureServices(IServiceCollection服务)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-25 21:37