Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I've been trying to follow this tutorial for a multiple image uploader:

https://youtu.be/sLYL_IZYnjw?t=244

It seems that at some point the template for a Blazor project combined Startup.cs and Program.cs into Program.cs.

The tutorial wants me to add this code to Program.cs:

<pre lang="C#"><pre>public IConfiguration Configuration { get; }

var cs = Configuration.GetConnectionString("FileUploadDbContext");

AsyncServiceScope.AddDbContext<FileUploadDbContext>(option => option.UseSqlServer(cs));


However I get the following errors:

Error	CS0116	A namespace cannot directly contain members such as fields, methods or statements	MultipleFileUpload	C:\Users\will.sewell\source\repos\MultipleFileUpload\MultipleFileUpload\Program.cs	15	Active


Error	CS0103	The name 'Configuration' does not exist in the current context	MultipleFileUpload	C:\Users\will.sewell\source\repos\MultipleFileUpload\MultipleFileUpload\Program.cs	17	Active


Error	CS0117	'AsyncServiceScope' does not contain a definition for 'AddDbContext'	MultipleFileUpload	C:\Users\will.sewell\source\repos\MultipleFileUpload\MultipleFileUpload\Program.cs	19	Active


What I have tried:

I've tried adding a namespace to Program.cs but don't think that's what I should be doing.

I've tried IConfiguration.GetConnectionString instead of Configuration.GetConnectionString and i've also tried it as System.Configuration.

Also I can't seem to add links correctly. If you copy the link out it works but if you just click on it, it comes back to this question.

Any help/ advice would be appreciated.
Posted
Updated 24-Aug-22 1:52am

1 solution

Yep, YT video is pretty straight forward to follow. You have timestamped the code to be added to the Startup.cs file. The ConnectionString is for connecting to a database.

If you follow the video exactly, it should work fine.

Also, check out Blazor University – Learn the .NET SPA framework from Microsoft[^] - it is great for those starting out and a reference for those who are already working with Blazor.
 
Share this answer
 
Comments
Will Sewell 24-Aug-22 9:01am    
Thank you Graeme. I'll definitely be using Blazor University.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900