Solved : 'WebApplication' does not contain a definition for 'UseKestrel' and the best extension method overload 'WebHostBuilder Kestrel Extensions.UseKestrel(IWebHostBuilder, Action)' requires a receiver of type 'IWebHostBuilder'

I had a requirement to upload files to .NET Core controller using Ajax call. Everything works well when the file size is < 30 Mb.

When we try to upload larger files, the controller doesn't receive any files in the POST. Its always null.


IList<IFormFile> files
var file = Request.Form.Files[0];

All the values were null, I tried using Files as parameter to the post and also tried using "Request.Form".


After some research, I found that the upload limit of the Kestrel server need to be increased as it limits it by default set to 30 or 50 Mb(not very sure).

When trying to add Kestrel to the builder configuration, I was getting following error:

"'WebApplication' does not contain a definition for 'UseKestrel' and the best extension method overload 'WebHostBuilder Kestrel Extensions.UseKestrel(IWebHostBuilder, Action<KestrelServerOptions>)' requires a receiver of type 'IWebHostBuilder'"


SOLUTION:

My .Net SDK version is 7.0.100

In your program.cs, add the following code


var builder = WebApplication.CreateBuilder(args);

The above code shall already be there.

Add the following with the desired limit, I have used 100Mb.

builder.WebHost.ConfigureKestrel(options =>
{
    options.Limits.MaxRequestBodySize = 104857600; // 100 MB in bytes
});



Keep Coding.....


Comments

Popular posts from this blog

SharePoint log error "Cannot find site lookup info for request Uri http://"

Visual Studio Build Issue : Build: 0 succeeded or up-to-date, 0 failed, 1 skipped

Reset your SharePoint Farm PassPhrase