ASP.NET Core updates in .NET 6 Preview 7

Daniel Roth

.NET 6 Preview 7 is now available and includes many great new improvements to ASP.NET Core.

Here’s what’s new in this preview release:

  • Parity with existing experiences for minimal APIs
  • Added IResult implementations for producing common HTTP responses
  • Support Request, Response and User for minimal actions
  • Minimal host and template improvements
  • Supply Blazor component parameters from the query string
  • Replace the current URI in the browser history from Blazor
  • New DynamicComponent.Instance property
  • Blazor streaming interop from JavaScript to .NET
  • Large file upload & faster file uploads with Blazor
  • Modify HTML <head> content from Blazor components
  • Support for the multiple attribute on <select> elements in Blazor
  • Support for HTTP/3 in Kestrel
  • QUIC support moved to the shared framework
  • Allow control over Activity creation
  • Support for non-ASCII characters in Kestrel response headers
  • Add W3CLogger
  • Add authentication expiration option to SignalR

Get started

To get started with ASP.NET Core in .NET 6 Preview 7, install the .NET 6 SDK.

If you’re on Windows using Visual Studio, install the latest preview of Visual Studio 2022. .NET 6 will be supported in a future public release of Visual Studio 2022 for Mac.

To get setup with .NET MAUI & Blazor for cross-platform native apps, see the latest instructions in the .NET MAUI getting started guide. Be sure to also check out the Announcing .NET MAUI Preview 7 blog post for all the details on what’s new in .NET MAUI in this release.

To install the latest .NET WebAssembly tools for ahead-of-time (AOT) compilation and runtime relinking, uninstall the earlier microsoft-net-sdk-blazorwebassembly-aot workload and install the new wasm-tools workload by running the following commands from an elevated command prompt:

dotnet workload uninstall microsoft-net-sdk-blazorwebassembly-aot
dotnet workload install wasm-tools

Upgrade an existing project

To upgrade an existing ASP.NET Core app from .NET 6 Preview 6 to .NET 6 Preview 7:

  • Update all Microsoft.AspNetCore.* package references to 6.0.0-preview.7.*.
  • Update all Microsoft.Extensions.* package references to 6.0.0-preview.7.*.

To upgrade a .NET MAUI Blazor app from .NET 6 Preview 6 to .NET 6 Preview 7 we recommend starting from a new .NET MAUI Blazor project created with the .NET 6 Preview 7 SDK and then copying code over from your original project.

See the full list of breaking changes in ASP.NET Core for .NET 6.

What’s new with minimal APIs?

Since we announced minimal APIs in .NET 6 Preview 4 we’ve been focused on enabling a more robust set of features. For .NET 6 Preview 7 we’re happy to announce that we’re lighting up more of your favorite ASP.NET experiences with a minimal twist. Let’s take a look at what you can expect.

Parity with existing experiences

Minimal APIs fundamentally change how the app startup code is structured. This meant that some of the tools and libraries we ship that interact with the app needed to be updated to handle this new pattern. The following tools and libraries have now been updated accordingly:

Added IResult implementations for producing common HTTP responses

In earlier previews, we extended IActionResult implementations from MVC to support the new IResult type introduced for minimal APIs. In this release, we’ve removed the dependency between IActionResult and IResult and added a new static Results utility class for producing common HTTP responses. Here’s an example:

app.MapPut("/todos/{id}", async (TodoDbContext db, int id, Todo todo) =>
{
    if (id != todo.Id)
    {
        return Results.BadRequest();
    }

    if (!await db.Todos.AnyAsync(x => x.Id == id))
    {
        return Results.NotFound();
    }

    db.Update(todo);
    await db.SaveChangesAsync();

    return Results.Ok();
});

Thank you Juan Barahona for contributing these IResult implementations!

Support Request, Response and User for minimal actions

In this preview, we added support for binding HttpRequest, HttpResponse and ClaimsPrincipal parameters in minimal actions. These parameters come from the Request, Response and User properties on HttpContext respectively. This is in addition to the pre-existing support for binding the HttpContext directly and a CancellationToken from HttpContext.RequestAborted.

The example below accepts the current user directly into the request handler method.

app.MapGet("/api/items", async (ITodoService service, ClaimsPrincipal user) =>
{
    return await service.GetListAsync(user.GetUserId());
})
.RequireAuthorization();

Thank you Martin Costello for contributing this feature!

Minimal host and template improvements

Minimal APIs introduced new hosting APIs and, combined with new C# features like global usings and top-level statements, enabled us to streamline the app startup experience. In this preview, we’re extending these changes to the other ASP.NET Core project templates.

For example, when you create a new ASP.NET Core Web API using the template you’ll now notice the following:

  • No Startup.cs
  • Leveraging implicit usings
  • New hosting model using WebApplication.CreateBuilder
  • Top-level statements in Program.cs (no namespace, class, or method declarations)
  • Nullable reference types

These changes reduce the amount of boilerplate code required to configure and start a new app. Note that the existing hosting model and Startup pattern will continue to be supported for existing apps.

ASP.NET Core Web API in .NET 5

image

ASP.NET Core Web API in .NET 6

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new() { Title = "WebApplication22", Version = "v1" });
});

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "WebApplication22 v1"));
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

Check out the the .NET blog for more details on how we’re modernizing the project templates that ship with the .NET SDK.

Note about implicit using statements: Based on early feedback during implementation, changes to the implicit usings feature are being made as part of the next release, including the requirement to opt-in to implicit usings in the project file, rather than them being included by default based on the project targeting .NET 6. This will ensure they don’t impact existing projects being migrated to .NET 6 until the author is ready to enable the feature.

Supply Blazor component parameters from the query string

Blazor components can now receive parameters from the query string. To specify that a component parameter of a routable component can come from the query string, apply the [SupplyParameterFromQuery] attribute in addition to the normal [Parameter] attribute:

@page "/search"

<h1>Search</h1>

<p>Filter: @Filter</p>

<p>Page: @Page</p>

<p>Assignees:</p>
<ul>
    @foreach (var assignee in Assignees)
    {
        <li>@assignee</li>
    }
</ul>

@code {
    // Handles URL patterns like /search?filter=some+stuff&page=3&assignee=Monica&assignee=Chandler

    [Parameter]
    [SupplyParameterFromQuery]
    public string Filter { get; set; }

    [Parameter]
    [SupplyParameterFromQuery]
    public int? Page { get; set; }

    [Parameter]
    [SupplyParameterFromQuery(Name = "assignee")]
    public string[] Assignees { get; set; }
}

Blazor search query

Component parameters supplied from the query string may be of the following types:

  • String, bool, DateTime, decimal, double, float, Guid, int, long.
  • Nullable variants of the above types (except string – not applicable).
  • Arrays of the above types, nullable or not.

Replace the current URI in the browser history from Blazor

When calling NavigationManager.NavigateTo in a Blazor app, you can now specify that you want to replace the current URI in the browser history instead of pushing a new URI onto the history stack. To replace the current URI in the browser history, specify true for the new replace parameter:

@NavigationManager.NavigateTo("Other", replace: true)

New DynamicComponent.Instance property

DynamicComponent now has an Instance property that provides a convenient way to get access to the dynamically created component instance:

<DynamicComponent Type="typeof(MyComponent)" @ref="dc" />

<button @onclick="Refresh">Refresh</button>

@code {
    DynamicComponent dc;
    Task Refresh()
    {
        return (dc.Instance as IRefreshable)?.Refresh();
    }
}

Blazor streaming interop from JavaScript to .NET

Blazor now supports streaming data directly from JavaScript to .NET. Streams are requested using the new IJSStreamReference interface:

JavaScript

function jsToDotNetStreamReturnValue() {
    return new Uint8Array(10000000);
}

C#

  var dataReference = await JSRuntime.InvokeAsync<IJSStreamReference>("jsToDotNetStreamReturnValue");
  using var dataReferenceStream = await dataReference.OpenReadStreamAsync(maxAllowedSize: 10_000_000);

  // Write JS Stream to disk
  var outputPath = Path.Combine(Path.GetTempPath(), "file.txt");
  using var outputFileStream = File.OpenWrite(outputPath);
  await dataReferenceStream.CopyToAsync(outputFileStream); 

Large file upload & faster file uploads with Blazor

Using the new Blazor streaming interop support mentioned above, we now support uploading files larger than 2GB using the InputFile component. The updated InputFile component is also much more efficient at uploading files thanks to native byte[] streaming, which avoids expensive Base64 encoding.

Modify HTML <head> content from Blazor components

Blazor now has built-in support for modifying HTML <head> element content from components, including setting the <title> and adding <meta> elements.

To specify the page’s title from a component, use the new PageTitle component. The HeadContent component can be used to render other content to the <head>.

<PageTitle>@title</PageTitle>

<HeadContent>
    <meta name="description" content="@description">
</HeadContent>

@code {
    private string description = "Description set by component";
    private string title = "Title set by component";
}

To enable the functionality provided by PageTitle and HeadContent, you need to add a HeadOutlet root component to your application. In Blazor WebAssembly, this can be done by adding the following line in Program.Main:

builder.RootComponents.Add<HeadOutlet>("head::after");

In Blazor Server, the setup is slightly more involved. In order to support prerendering, the App root component needs to be rendered before the HeadOutlet. A convenient way to achieve this is to move most of the content in _Host.cshtml to _Layout.cshtml, as shown below.

_Layout.cshtml

@using Microsoft.AspNetCore.Components.Web
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <title>Blazor Server App</title>
    <base href="~/" />
    <component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" />
</head>
<body>
    @RenderBody()
    <script src="_framework/blazor.server.js"></script>
</body>
</html>

_Host.cshtml

@page "/"
@namespace BlazorServerWeb_CSharp.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
    Layout = "_Layout";
}

<component type="typeof(App)" render-mode="ServerPrerendered" />

A future release will include updated Blazor project templates, so performing these changes to enable <head> modification won’t be necessary for new projects.

Support for the multiple attribute on <select> elements in Blazor

If you specify the multiple attribute in a <select> elements from a Blazor component, the onchange event will now supply an array of the selected elements via ChangeEventArgs. Likewise, array values can be bound to the value attribute when multiple is specified.

<p>
    Select one or more cars: 
    <select @onchange="SelectedCarsChanged" multiple>
        <option value="audi">Audi</option>
        <option value="jeep">Jeep</option>
        <option value="opel">Opel</option>
        <option value="saab">Saab</option>
        <option value="volvo">Volvo</option>
    </select>
</p>

<p>
    Select one or more cities: 
    <select @bind="SelectedCities" multiple>
        <option value="bal">Baltimore</option>
        <option value="la">Los Angeles</option>
        <option value="pdx">Portland</option>
        <option value="sf">San Francisco</option>
        <option value="sea">Seattle</option>
    </select>
</p>

@code {
    public string[] SelectedCars { get; set; } = new string[] { };
    public string[] SelectedCities { get; set; } = new[] { "bal", "sea" };

    void SelectedCarsChanged(ChangeEventArgs e)
    {
        SelectedCars = (string[])e.Value;
    }
}

When using <InputSelect>, the multiple attribute is inferred if the bound value has an array type.

<EditForm EditContext="@editContext">
    Select one or more classifications (Minimum: 2, Maximum: 3):
    <InputSelect @bind-Value="starship.SelectedClassification">
        <option value="@Classification.Exploration">Exploration</option>
        <option value="@Classification.Diplomacy">Diplomacy</option>
        <option value="@Classification.Defense">Defense</option>
        <option value="@Classification.Research">Research</option>
    </InputSelect>
</EditForm>

@code {
    private EditContext editContext;
    private Starship starship = new();

    protected override void OnInitialized()
    {
        editContext = new(starship);
    }

    private class Starship
    {
        [Required, MinLength(2), MaxLength(3)]
        public Classification[] SelectedClassification { get; set; } =
            new[] { Classification.Diplomacy };
    }

    private enum Classification { Exploration, Diplomacy, Defense, Research }
}

Preview support for HTTP/3 in Kestrel

Preview 7 introduces early support for HTTP/3 and QUIC in Kestrel to try out and give feedback on.

HTTP/3 is the third and upcoming major version of HTTP. HTTP/3 uses the same semantics as HTTP/1.1 and HTTP/2: the same request methods, status codes, and message fields apply to all versions. The differences are in the underlying transport. Both HTTP/1.1 and HTTP/2 use TCP as their transport. HTTP/3 uses a new transport technology developed alongside HTTP/3 called QUIC.

HTTP/3 and QUIC have a number of benefits compared to older HTTP versions:

  • Faster response time of the first request. QUIC and HTTP/3 negotiates the connection in fewer round-trips between the client and the server. The first request reaches the server faster.
  • Improved experience when there is connection packet loss. HTTP/2 multiplexes multiple requests via one TCP connection. Packet loss on the connection would affect all requests. This problem is called “head-of-line blocking”. Because QUIC provides native multiplexing, lost packets only impact the requests where data has been lost.
  • Supports transitioning between networks. This feature is useful for mobile devices where it is common to switch between Wi-Fi and cellular networks as a mobile device changes location. Today HTTP/1.1 and HTTP/2 connections will fail with an error and force an app or web browser to retry. HTTP/3 allows the app or web browser to seamlessly continue when a network changes. Kestrel doesn’t support network transitions in .NET 6, but we’ll explore adding it in a future .NET release.

To start using HTTP/3, configure the QUIC transport, and modify ListenOptions to add an HTTP/3 binding. For use with browser-based clients, you’ll also need to enable sending the alt-svc header.

    var builder = WebApplication.CreateBuilder(args);
    builder.WebHost.UseKestrel()
    // Set up Quic options
    .UseQuic(options =>
    {
        options.Alpn = "h3-29";
        options.IdleTimeout = TimeSpan.FromMinutes(1);
    })
    .ConfigureKestrel((context, options) =>
    {
        options.EnableAltSvc = true;
        options.Listen(IPAddress.Any, 5001, listenOptions =>
        {
            // Use Http3
            listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
            listenOptions.UseHttps();
        });
    });

HTTP/3 is not supported everywhere. See use HTTP/3 with the ASP.NET Core Kestrel web server for information on getting started with HTTP/3 in Kestrel.

QUIC support moved to the shared framework

We’re no longer shipping the Microsoft.AspNetCore.Server.Kestrel.Transport.Quic package, and are instead including the assembly in the ASP.NET Core shared framework. Customers with a PackageReference to Microsoft.AspNetCore.Server.Kestrel.Transport.Quic should remove the PackageReference from their project.

Allow control over Activity creation

We’ve added support for DistributedContextPropagators in ASP.NET Core. Prior to this change, ASP.NET Core had knowledge of the W3C TraceContext and W3C Baggage specifications and we created an Activity only if the tracestate and traceparent HTTP headers were present on the incoming HTTP request. This made it impossible to support other tracing specifications. It’s now possible to support other distributed tracing specifications by implementing a custom DistributedContextPropagator and registering it in the DI container.

Support for non-ASCII characters in Kestrel response headers

Kestrel now has support for sending non-ASCII characters in HTTP response headers. To opt-in custom encoding on per-header basis, you can provide a ResponseHeaderEncodingSelector:

builder.WebHost.ConfigureKestrel(options =>
{
    options.ResponseHeaderEncodingSelector = (_) => Encoding.ASCII;
});

Note: While use of custom response header encoding may be needed in some cases, we discourage the use of non-ASCII encodings to avoid compatibility issues with other HTTP clients.

Add W3CLogger

ASP.NET Core is now capable of generating server access logs in the W3C Extended Log File Format. To start emitting server access logs, you need to add the logger to DI and add the W3C logging middleware to your middleware pipeline:

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddW3CLogging(options =>
{
    options.LogDirectory = @"C:\logs";
    options.LoggingFields = W3CLoggingFields.Request | W3CLoggingFields.ConnectionInfoFields;
});

var app = builder.Build();

app.UseW3CLogging();
if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}

app.MapGet("/", () => "Hello World!");
app.Run();

This will produce a log file that resembles this output:

#Version: 1.0
#Start-Date: 2021-08-10 01:07:40
#Fields: c-ip s-ip s-port cs-method cs-uri-stem cs-uri-query cs-version cs-host cs(User-Agent) cs(Referer)
::1 ::1 5001 GET / - HTTP/2 localhost:5001 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/92.0.4515.131+Safari/537.36+Edg/92.0.902.67 -
::1 ::1 5001 GET /favicon.ico - HTTP/2 localhost:5001 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/92.0.4515.131+Safari/537.36+Edg/92.0.902.67 https://localhost:5001/
::1 ::1 5001 GET / - HTTP/2 localhost:5001 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/92.0.4515.131+Safari/537.36+Edg/92.0.902.67 -
::1 ::1 5001 GET / - HTTP/2 localhost:5001 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/92.0.4515.131+Safari/537.36+Edg/92.0.902.67 -
::1 ::1 5001 GET / - HTTP/2 localhost:5001 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/92.0.4515.131+Safari/537.36+Edg/92.0.902.67 -

Add authentication expiration option to SignalR

There is a new option that will enable SignalR to track the expiration of an authentication token and close the connection if the token expires. This option can be enabled with CloseOnAuthenticationExpiration on HttpConnectionDispatcherOptions as shown below.

app.UseEndpoints(endpoints =>
{
    endpoints.MapHub<MyHub>("/hub", options =>
    {
        options.CloseOnAuthenticationExpiration = true;
    });
});

Give feedback

We hope you enjoy this preview release of ASP.NET Core in .NET 6. We’re eager to hear about your experiences with this release. Let us know what you think by filing issues on GitHub.

Thanks for trying out ASP.NET Core!

83 comments

Discussion is closed. Login to edit/delete existing comments.

  • Michael Argentini 0

    I still can get my project to work properly in a release build. It runs in debug mode, but when I publish for AOT the build issues warnings like:

    “Unable to compile method ‘string Microsoft.Net.Http.Headers.DateTimeFormatter:ToRfc1123String… expected class ‘Microsoft.Extensions.Primitives.InplaceStringBuilder’ in assembly ‘Microsoft.Extensions.Primitives, Version=2.2.0.0”

    The app does build, but it has some kind of issue with my sign in process. I assume the build warnings are the culprit.

    This primitives namespace reference has thrown the same kind of exception with every preview release. Is this a known issue by any chance?

    • Daniel RothMicrosoft employee 0

      Hi Michael. If you have a consistent way to reproduce this error, we’d be happy to take a look. Have you already created a GitHub issue for this?

      Does the app publish and run correctly when AOT is not enabled and when the wasm-tools workload is not installed?

      From the error, it sounds like there may be a version mismatch somewhere in the app. Double check your package references and make sure they are all using the correct .NET 6 Preview 7 versions.

      • Michael Argentini 0

        Hey Daniel, thanks for your response. Interesting result… I uninstalled the preview 7 workload, but had to install an older one via “dotnet workload install macOS” (did I mention I’m using macOS?). I disabled the AOT build and published for release. Obviously it published pretty fast, and the warnings were not there. Also, when I ran the app I had the same login issue. So now I’m wondering if the warnings are unrelated. Also tried in debug. Same result. So it doesn’t work when it’s published (debug or release), but does work when debugging in VS (even as an IIS site).

        But those warnings for a release AOT build are concerning. I can’t provide my project code because it’s proprietary. But I’m open to providing any other data (e.g. logs) if that would help you figure this out (if you’re interested in trying).

        • Daniel RothMicrosoft employee 0

          OK, it sounds like the login issue may just be an app configuration issue. Maybe you’ve got the app URL hard coded somewhere and things break when published because the app URL is different?/

          For the AOT build warnings the easiest way for us to investigate is for you to open up a GitHub issue with the full text of the warnings you’re seeing: https://github.com/dotnet/aspnetcore/issues/new. We can then loop in the right folks to collect the necessary diagnostics.

  • Rod Macdonald 0

    Aside from the usual HTML controls, I’m getting the impression that Fluent UI for Web is the way to go for controls and control styling in Blazor. Is seems odd given Fluent UI for Web appears to be a dialect of the javascript based ‘React’. I wonder if anyone knows if a C# equivalent will ship for web?

    • Daniel RothMicrosoft employee 0

      Hi Rod. In addition to the Fluent UI React components there are also Fluent UI web components that can be used with any framework. The Fluent UI team has even build some Blazor component wrappers around the Fluent UI web components to make them convenient to use from Blazor: https://github.com/microsoft/fast-blazor.

  • Mark O. Fluehr 0

    Will [SupplyParameterFromQuery] also update the URL query if a control in the page changes the value? One use case would be a pagination control that changes the page number.

    • Daniel RothMicrosoft employee 0

      Hi Mark. No, the [SupplyParameterFromQuery] attribute will only handle populating the component parameter from the query string. In the next .NET 6 preview we’re adding APIs to make it easier to update the query string: https://github.com/dotnet/aspnetcore/pull/34813.

  • Renè Riedinger 0

    @Daniel is it still possible to use an explicit Startup.cs?
    Because we derive from a BaseStartup class which are distributed via a NuGet package.

    And in the Startup.cs exits a special method to access a custom IOC container like unity or autofac?

    If a Startup.cs is no longer supported, can you tell me how to archive what I described above?
    Br

    • Daniel RothMicrosoft employee 0

      Hi Rene. Yup, the Startup class pattern is still supported and there are no plans to remove it.

      • David FowlerMicrosoft employee 0

        You can do custom IOC without a startup class. You can still use a startup class like Dan said though, your existing code still works as well so if you’re updating, you don’t need to change it.

  • Hamed Zare 0

    Hi Daniel Roth.I wish you all success
    I set the BlazorWebAssemblyLoadAllGlobalizationData property to true but not working after publish in .net 6 preview 7
    plz help 😉

        • Hamed Zare 0

          Hi Daniel Roth 🙂 Thanks for replying. my problem is solved. i set _BlazorWebAssemblyLoadAllGlobalizationData to true in .csproj then i published project. Now it working correctly

  • Issac Vale 0

    Hi Daniel,

    I need some help here…
    I’ve updated my VS preview version to use net6 preview 7 (6.0.0-preview.7.21378.6) , and get the following error:
    Error CS0006 Metadata file ‘C:\Users\tal\source\repos\SelectSamples\select_multiple_attribute\select_multiple_attribute\Client\bin\Debug\net6.0\ref\select_multiple_attribute.Client.dll’ could not be found select_multiple_attribute.Server C:\Users\tal\source\repos\SelectSamples\select_multiple_attribute\select_multiple_attribute\Server\CSC 1 Active

    I also get the following warnings:

    Warning CS8032 An instance of analyzer Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator cannot be created from C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll : Could not load file or assembly ‘Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.. select_multiple_attribute.Client C:\Users\tal\source\repos\SelectSamples\select_multiple_attribute\select_multiple_attribute\Client\CSC 1 Active

    Warning CS0105 The using directive for ‘System’ appeared previously in this namespace select_multiple_attribute.Client C:\Users\tal\source\repos\SelectSamples\select_multiple_attribute\select_multiple_attribute\Client\obj\Debug\net6.0.NETCoreApp,Version=v6.0.AssemblyAttributes.cs 2 Active

    Warning CS0105 The using directive for ‘System’ appeared previously in this namespace select_multiple_attribute.Client C:\Users\tal\source\repos\SelectSamples\select_multiple_attribute\select_multiple_attribute\Client\obj\Debug\net6.0\select_multiple_attribute.Client.AssemblyInfo.cs 11 Active

    Warning CS8032 An instance of analyzer Microsoft.NET.Sdk.Razor.SourceGenerators.RazorSourceGenerator cannot be created from C:\Program Files\dotnet\sdk\6.0.100-preview.7.21379.14\Sdks\Microsoft.NET.Sdk.Razor\source-generators\Microsoft.NET.Sdk.Razor.SourceGenerators.dll: Could not load file or assembly ‘Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35’ or one of its dependencies. The system cannot find the file specified.. select_multiple_attribute.Client 1 Active

    Do you happen to know what is the issue ?

    Thanks…

    • Daniel RothMicrosoft employee 0

      Hi Issac. Can you confirm that you are using Visual Studio 2022 Preview 3 or later? Also, does the project build correctly from the command line using dotnet build?

  • Jordan Grignon 0

    Decided to try the latest preview, and I don’t understand the reason for a preview sdk only being able to be used by a preview IDE version. I tried porting a complex application, with Grcp service and multiple client applications. Unfortunately due to a known bug (which took me days to find out) in VS 2022 the data service did not work correctly.
    After the quick reply from the aspnetcore team I had a workaround, adding the following line to the top of program.cs in the Grpc service,
    Environment.SetEnvironmentVariable(“ASPNETCORE_PREVENTHOSTINGSTARTUP”, “true”);
    and tried it with a simple project and it works. Tried it with my ported net 5 application and it crashes on start.
    So then I started altering the code so that program.cs in the ported version contains the code from startup.cs, I was able to move most of startup.cs to be top level statements in program.cs, unfortunately I could not determine how to load the configuration file. and I notice that in your example comparing Net 5 to Net 6 while the startup.cs file in the image loads a configuration file, the sample code for Net 6 does not. How does one load a configuration file now?

    • Daniel RothMicrosoft employee 0

      Hi Jordan. Thank you for trying out the .NET 6 and Visual Studio 2022 previews! .NET 6 requires the latest Visual Studio 2022 preview because it depends on functionality that is only available with Visual Studio 2022 for the tooling experience to function properly. Since these are still previews, there may of course be bugs. Please keep reporting any issues you hit as this helps us improve the quality of the release.

      With the new min hosting model, you can get access to the ConfigurationManager to add additional configuration sources from the WebApplicationBuilder.Configuration property.

      var builder = WebApplication.CreateBuilder(args);
      builder.Configuration.AddJsonFile("myconfig.json");
      var app = builder.Build();
      

      Note that the default WebApplicationBuilder already sets up a bunch of configuration sources for you, like for appsettings.json.

  • Stefan Ossendorf 0

    Hi. Is there a working example on how to use the new upload “size” improvements?
    I’m using this as an example within our Blazor app Blazor WASM File Upload Documentation but I’m still getting an out of memory exception. I tried a 2GB and 1GB dummy file. Both produce an exception.

    • Daniel RothMicrosoft employee 0

      Hi Stefan. The sample in the docs should be correct. What sort of device you’re hitting the out of memory exception on? Could you please open a GitHub issue with these details so that we can investigate?: https://github.com/dotnet/aspnetcore/issues/new.

  • Greg Zapp 0

    Late question about Blazor AOT and plugins in general.. Does Blazor WASM AOT still support lazy loading assemblies? Is there a more complete plugin story shaping up for this release(even if it’s just “here are the integration points but you have to build your own system on top”)?

    Cheers!

    • Daniel RothMicrosoft employee 0

      Hi Greg. Lazy loading of different parts of a Blazor WebAssembly app isn’t supported when using AOT compilation. Using AOT compilation with a Blazor WebAssembly app will create a single WebAssembly bundle. We don’t have planned a broader plugin story for Blazor WebAssembly in .NET 6. If that’s something you have ideas on how to achieve, please let us know on GitHub

  • Erik Vallgren 0

    Hi Dan!
    Awesome work!
    I have a problem with

    dotnet watch run

    when running my Blazor WASM project with preview 7.
    I does not detect changes when pressing CTRL + S.
    It does detect changes when I do a change and then revert it using VS Git “Undo changes” button.
    Do you know anything about this?
    It does also detect changes when using .NET 5 (latest supported)

    • Daniel RothMicrosoft employee 0

      Hi Erik. In .NET 6 running dotnet watch run will attempt to hot reload change by default instead of rebuilding and restarting the app. You may be hitting an issue with .NET Hot Reload and Blazor WebAssembly apps. Could you please open a GitHub issue with details on how to reproduce the behavior you are seeing?: https://github.com/dotnet/aspnetcore/issues/new. Thanks!

Feedback usabilla icon