简体   繁体   中英

'IServiceCollection' does not contain a definition for 'AddAWSService' and no accessible extension method 'AddAWSService' error in asp.net core 2.2?

I am setting up Aws SQS in asp.net core 2.22 project. I am adding aws configuration lines in my Program.cs file. Here is my Program.cs file.

 using Amazon.SQS; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; namespace analytics { public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; set;} // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddCors(c => { c.AddPolicy("AllowOrigin", options => { options.AllowAnyOrigin(); }); }); // AWS Configuration var awsoptions = Configuration.GetAWSOptions(); services.AddDefaultAWSOptions(awsoptions); services.AddAWSService<IAmazonSQS>(); // Worker Service // services.AddHostedService<Worker>(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts. app.UseHsts(); } // app.UseHttpsRedirection(); app.UseMvc(); app.UseCors(options => { options.AllowAnyOrigin(); }); } } }

So i am receiving these errors on console

Startup.cs(40,52): error CS1061: 'IConfiguration' does not contain a definition for 'GetAWSOptions' 
and no accessible extension method 'GetAWSOptions' accepting a first argument of type 
'IConfiguration' could be found (are you missing a using directive or an assembly reference?) 
[D:\OfficeProjects\beelinksanalytics\analytics.csproj]

Startup.cs(41,30): error CS1061: 'IServiceCollection' does not contain a definition for 
'AddDefaultAWSOptions' and no accessible extension method 'AddDefaultAWSOptions' accepting a first 
argument of type 'IServiceCollection' could be found (are you missing a using directive or an 
assembly reference?) [D:\OfficeProjects\beelinksanalytics\analytics.csproj]

Startup.cs(42,30): error CS1061: 'IServiceCollection' does not contain a definition for 
'AddAWSService' and no accessible extension method 'AddAWSService' accepting a first argument of 
type 'IServiceCollection' could be found (are you missing a using directive or an assembly 
reference?) [D:\OfficeProjects\beelinksanalytics\analytics.csproj]

Basically i want to implement Aws SQS service to listen queue messages and want to perform some actions based on those messages. So i am struggling to configure Aws Sdk and aws sqs in asp.net core 2.2 project

I didn't find any relevant documentation of how to configure aws sqs in asp.net core 2.2. Please tell me what's wrong with this?

just run this in your command line as mentioned @panagiotis-kanavos (select version that you wanthere )

dotnet add package AWSSDK.Extensions.NETCore.Setup --version 3.3.101

verify that the reference was added in your .csproj

在此处输入图片说明

this worked for me, I hope as well for you

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM