extnet / Ext.NET

35 stars 41 forks source link

.NET 6 + ASP.NET 6 support for Ext.NET 7 #1873

Closed fabriciomurta closed 2 years ago

fabriciomurta commented 2 years ago

Ext.NET forums' thread: .NET 6

It looks like Ext.NET 7 cannot be targetted to ASP.NET 6 website projects, at least as far as the default project provided by Ext.NET templates is set up.

We should either create a new ASP.NET 6 compatible template for Ext.NET 7 or completely upgrade Ext.NET 7 to support ASP.NET 6.

The issue raised when the project is targetted to ASP.NET 6. Build succeeds but upon the first request to an Ext.NET powered website, the following exception is triggered:

fail: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      System.NullReferenceException: Object reference not set to an instance of an object.
         at Ext.Net.Core.Direct.ExtDirectProxyContent.GetDirectMethodInfos()
         at Ext.Net.Core.Direct.ExtDirectProxyContent.HasContent()
         at Ext.Net.TagHelpers.Core.ExtScriptableContent.WriteTo(TextWriter writer, HtmlEncoder encoder)
         at A.A.WriteTo(TextWriter writer, HtmlEncoder encoder)
         at Microsoft.AspNetCore.Mvc.ViewFeatures.Buffers.ViewBuffer.WriteToAsync(TextWriter writer, HtmlEncoder encoder)

The exception is not displayed at the page because of how Ext.NET intercepts and handles page output, so only a blank page is returned and the following warning is also logged to the dotnet run command output:

warn: Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[2]
      The response has already started, the error page middleware will not be executed.

One possible solution is review startup.cs to properly initialize Ext.NET for this version. Removing the Westwind.AspNetCore.LiveReload didn't improve the situation.

fabriciomurta commented 2 years ago

Trying to convert Startup.cs + Program.cs into ASP.NET 6 new hosting model resulted in the exact same exception above.

The following Program.cs file, based on the dotnet new extnet template, tries to use the new, simplified hosting model and should be mostly compatible with the previous model:

using Ext.Net;
using Ext.Net.Core;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace _20220208_en7an6
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.
            builder.Services.AddRazorPages();

            builder.Services.AddExtNet();
            builder.Services.AddExtCharts();

            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (!app.Environment.IsDevelopment())
            {
                app.UseExceptionHandler("/Error");
                // 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.UseExtNetResources(config =>
            {
                if (app.Environment.IsDevelopment())
                {
                    config.UseDebug(true);
                }

                config.UseEmbedded();
                config.UseCharts();
                config.UseThemeSpotless();
            });

            app.UseExtNetLocalization();

            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseExtNet(config =>
            {
                config.Theme = ThemeKind.Spotless;
            });

            app.MapRazorPages();

            app.Run();
        }
    }
}
harvca commented 2 years ago

Is there any updates on this? .NET 5 is EOL on May 8th 2022

geoffreymcgill commented 2 years ago

@harvca We are working on .NET 6 support right now. With some luck, a v7.3.0 release that adds .NET 6 support will be available soon.

fabriciomurta commented 2 years ago

We have just published Ext.NET 7.3.0-preview to NuGet. Please let us know if you run into any problem using it!

fabriciomurta commented 2 years ago

And 7.3.0 final is released. This issue should be deemed as fixed. ASP.NET 6 support is implemented.