我试图在C#中创建一个不和谐的bot,这里的代码生成了一个异常,其中包含以下消息:'ServiceCollection‘不包含接受0参数的构造函数
_services = new ServiceCollection()
.AddSingleton(_client)
.AddSingleton(_commands)
.BuildServiceProvider();如果这有帮助的话
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Services.Description;
using Discord;
using Discord.Commands;
using Discord.WebSocket;我是一个相当初学者编程,所以任何帮助都会非常感谢!
发布于 2020-04-26 10:14:34
应该将System.Web.Services.Description命名空间替换为Microsoft.Extensions.DependencyInjection。
首先,您需要安装Microsoft.Extensions.DependencyInjection nuget包,然后将它包含在命名空间引用中。
using Microsoft.Extensions.DependencyInjection;它提供了另一个ServiceCollection类,因此您的代码不再抛出编译错误。
new ServiceCollection();https://stackoverflow.com/questions/61437571
复制相似问题