gpt4 book ai didi

c# - 在 ConfigureServices(IServiceCollection services) 中调用 services.AddOptions() 不明确

转载 作者:太空狗 更新时间:2023-10-29 22:21:37 24 4
gpt4 key购买 nike

ConfigureServices(IServiceCollection services) 中添加 services.AddOptions() 后出现以下错误:

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

代码:

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 question 的反馈我追踪到我在 project.lock.json 中有一个对 "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final" 的引用,它本身有一个引用 "Microsoft.Extensions.OptionsModel": "1.0.0-rc1-final"

重点是只引用 "Microsoft.Extensions.Options": "1.0.0-rc2-final" 并删除所有对 OptionsModel 的引用.

关于c# - 在 ConfigureServices(IServiceCollection services) 中调用 services.AddOptions() 不明确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37392683/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com