3

I'm trying to create a Discord bot in C#, and the code I have here produces an exception with following message: 'ServiceCollection' Does not contain a constructor that takes 0 arguments

_services = new ServiceCollection() .AddSingleton(_client) .AddSingleton(_commands) .BuildServiceProvider(); 

The references if that helps

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; 

I am quite a beginner in programming, So any help would be greatly appreciated!

2
  • The error code says something about a ServiceCollector but your code only mentions a ServiceCollection, is this correct and if so where is that code?. Also can you add the usings of this file? In general try to ask a question as complete as possible Commented Apr 26, 2020 at 8:58
  • Oh sorry, I made a typo, meant to say Collection there. Also added the references. Commented Apr 26, 2020 at 10:05

1 Answer 1

5

You should replace System.Web.Services.Description namespace with Microsoft.Extensions.DependencyInjection

Firstly, you need to install Microsoft.Extensions.DependencyInjection nuget package, and then include it in namespace references

using Microsoft.Extensions.DependencyInjection; 

It provides another ServiceCollection class, so your code does not throw a compilation error anymore

new ServiceCollection(); 
Sign up to request clarification or add additional context in comments.

1 Comment

my suggestion is based on assumption that you are using some version of .net core, and not .net framework

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.