dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.38k stars 10k forks source link

Upgrade from .NET 6.0.0-preview.3.21201.13 to 6.0.0-preview.4.21253.5, app.UseBlazorFrameworkFiles(); cause error #33074

Closed donhuvy closed 3 years ago

donhuvy commented 3 years ago

I am using Microsoft Visual Studio Community 2019 Preview - Version 16.11.0 Preview 1.0 . My web-app work very well with .NET 6.0.0-preview.3.21201.13 . This is my upgrade process demonstrate by git diff

donhuvy@DESKTOP-23PIH3M MINGW64 /d/github/acc (main)
$ git diff
diff --git a/Client/acc.Client.csproj b/Client/acc.Client.csproj
index dfa936b..b07ab26 100644
--- a/Client/acc.Client.csproj
+++ b/Client/acc.Client.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
+<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

   <PropertyGroup>
     <TargetFramework>net6.0</TargetFramework>
@@ -9,11 +9,11 @@

   <ItemGroup>
-    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0-preview.3.21201.13" />
-    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0-preview.3.21201.13" PrivateAssets="all" />
-    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.0-preview.3.21201.13" />
-    <PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0-preview.3.21201.4" />
-    <PackageReference Include="System.Net.Http.Json" Version="6.0.0-preview.3.21201.4" />
+    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.0-preview.4.21253.5" />
+    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.0-preview.4.21253.5" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="6.0.0-preview.4.21253.5" />
+    <PackageReference Include="Microsoft.Extensions.Http" Version="6.0.0-preview.4.21253.7" />
+    <PackageReference Include="System.Net.Http.Json" Version="6.0.0-preview.4.21253.7" />
   </ItemGroup>

   <ItemGroup>
diff --git a/Server/acc.Server.csproj b/Server/acc.Server.csproj
index 4361cae..d87d0a4 100644
--- a/Server/acc.Server.csproj
+++ b/Server/acc.Server.csproj
@@ -6,8 +6,8 @@
   </PropertyGroup>

   <ItemGroup>
-    <PackageReference Include="DevExpress.Document.Processor" Version="21.1.2-beta" />
-    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.0-preview.3.21201.13" />
+    <PackageReference Include="DevExpress.Document.Processor" Version="21.1.3" />
+    <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="6.0.0-preview.4.21253.5" />
   </ItemGroup>

   <ItemGroup>
@@ -16,12 +16,12 @@
   </ItemGroup>

   <ItemGroup>
-    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.0-preview.3.21201.13" />
-    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0-preview.3.21201.13" />
-    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.0-preview.3.21201.13" />
-    <PackageReference Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer" Version="6.0.0-preview.3.21201.13" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0-preview.3.21201.2" />
-    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0-preview.3.21201.2">
+    <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="6.0.0-preview.4.21253.5" />
+    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.0-preview.4.21253.5" />
+    <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="6.0.0-preview.4.21253.5" />
+    <PackageReference Include="Microsoft.AspNetCore.ApiAuthorization.IdentityServer" Version="6.0.0-preview.4.21253.5" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0-preview.4.21253.1" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0-preview.4.21253.1">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
diff --git a/Shared/acc.Shared.csproj b/Shared/acc.Shared.csproj
index 70fad51..53ceae6 100644
--- a/Shared/acc.Shared.csproj
+++ b/Shared/acc.Shared.csproj
@@ -5,8 +5,8 @@
   </PropertyGroup>

   <ItemGroup>
-    <PackageReference Include="DevExpress.Blazor" Version="21.1.2-beta" />
-    <PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.0-preview.3.21201.13" />
+    <PackageReference Include="DevExpress.Blazor" Version="21.1.3" />
+    <PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.0-preview.4.21253.5" />
     <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
   </ItemGroup>

(END)

enter image description here

Error

System.MissingMethodException
  HResult=0x80131513
  Message=Method not found: 'Microsoft.AspNetCore.Builder.IApplicationBuilder Microsoft.AspNetCore.Builder.UseExtensions.Use(Microsoft.AspNetCore.Builder.IApplicationBuilder, System.Func`3<Microsoft.AspNetCore.Http.HttpContext,Microsoft.AspNetCore.Http.RequestDelegate,System.Threading.Tasks.Task>)'.
  Source=Microsoft.AspNetCore.Components.WebAssembly.Server
  StackTrace:
   at Microsoft.AspNetCore.Builder.ComponentsWebAssemblyApplicationBuilderExtensions.<>c__DisplayClass0_0.<UseBlazorFrameworkFiles>b__1(IApplicationBuilder subBuilder)
   at Microsoft.AspNetCore.Builder.MapWhenExtensions.MapWhen(IApplicationBuilder app, Func`2 predicate, Action`1 configuration)
   at Microsoft.AspNetCore.Builder.ComponentsWebAssemblyApplicationBuilderExtensions.UseBlazorFrameworkFiles(IApplicationBuilder builder, PathString pathPrefix)
   at Microsoft.AspNetCore.Builder.ComponentsWebAssemblyApplicationBuilderExtensions.UseBlazorFrameworkFiles(IApplicationBuilder applicationBuilder)
   at acc.Server.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env) in D:\github\acc\Server\Startup.cs:line 62
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass15_0.<UseStartup>b__1(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.<StartAsync>d__31.MoveNext()

enter image description here

image

If I try comment this line,

// app.UseBlazorFrameworkFiles();

enter image description here

File Startup.cs

using acc.Server.Data;
using acc.Server.Models;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Hosting;
using System.IO;

namespace acc.Server
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
            services.AddDatabaseDeveloperPageExceptionFilter();
            services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true).AddEntityFrameworkStores<ApplicationDbContext>();
            services.AddIdentityServer().AddApiAuthorization<ApplicationUser, ApplicationDbContext>();
            services.AddAuthentication().AddIdentityServerJwt();
            services.AddControllersWithViews();
            services.AddRazorPages();
            services.AddSingleton<IFileProvider>(new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "FilesHere")));
            // services.AddDevExpressBlazor();
            // https://docs.devexpress.com/Blazor/401608/common-concepts/troubleshooting#an-unhandled-exception-on-the-current-circuit
            services.AddServerSideBlazor().AddCircuitOptions(options => { options.DetailedErrors = true; });
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            var supportedCultures = new[] { "vi-VN" };
            var localizationOptions = new RequestLocalizationOptions().SetDefaultCulture(supportedCultures[0])
                .AddSupportedCultures(supportedCultures)
                .AddSupportedUICultures(supportedCultures);
            app.UseRequestLocalization(localizationOptions);
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseMigrationsEndPoint();
                app.UseWebAssemblyDebugging();
            }
            else
            {
                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.UseHttpsRedirection();
            app.UseBlazorFrameworkFiles();
            app.UseStaticFiles();
            app.UseRouting();
            app.UseIdentityServer();
            app.UseAuthentication();
            app.UseAuthorization();
            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
                endpoints.MapControllers();
                endpoints.MapFallbackToFile("index.html");
            });
        }
    }
}

How to fix it?

( You can see more at https://stackoverflow.com/questions/67723043/update-from-net-6-0-0-preview-3-21201-13-to-6-0-0-preview-4-21253-5-app-usebla )

javiercn commented 3 years ago

@donhuvy thanks for contacting us.

It's not clear what's going on in your case, however we haven't made any changes in this area. I would suggest you look for a global.json in your solution or try to add one with the preview4 sdk version. In addition to that, clean all the bin and obj folders from your solution (I recommend deleting the files via the command line or with git clean)

pranavkm commented 3 years ago

@BrennanConroy looks related to https://github.com/dotnet/aspnetcore/pull/31784.

donhuvy commented 3 years ago

Thank @javiercn , @pranavkm for quick reply. I search in all solutions, I don't see file global.json . I delete all bin and obj by Windows Explorer and in Recycle bin, but error is the same. I also clean solution, clean projects, build per project, build all solutions, the error is the same.

I read document, then I did

dotnet new globaljson --sdk-version 6.0.100-preview.4.21255.9

It works now with .NET 6.0.100-preview.4.21255.9 . Thank you very much!