dotnet/aspnetcore

Support for MAUI runtimes in ASP.NET Core?

JustArchi opened this issue Β· 166 comments

Hey,

I apologize in advance if this is not the correct place to ask this, but I didn't find any better one. Feel free to move this issue if appropriate.

For testing purposes, in MAUI net6.0-android project I've tried to reference other project of mine targetting net6.0 which is a library. I didn't have any issues doing so, but during compilation I've stumbled upon following error:

Error NETSDK1082 There is no Microsoft.AspNetCore.App runtime package available for the specified RuntimeIdentifier "android-x86"

If I understand this right, I can reference standard net6.0 projects because Microsoft.NETCore.App.Runtime.Mono.android-x86 exists and is usable, at least I successfully did that with example net6.0 library. However, I'd like to reference a library that has actual ASP.NET Core elements (Kestrel web server, API with MVC etc), which according to the error is impossible because it can't find a required android-x86 runtime, which seems to be correct as of today.

Now I apologize if I'm trying to do some extreme stupidity, or I don't understand something, but I wanted to verify whether it'd be possible to "convert" existing CLI project of mine which uses Kestrel and API controllers into an Android MAUI app that could start the "backend" part on the target machine, with some nice frontend utilizing those API endpoints over HTTP. I'm testing this in .NET 6.0 preview 6 if it matters.

Is this possible/planned? Or perhaps I'm doing something horribly wrong?

In any case, thank you in advance for answering, I appreciate it.

Eilon commented

(Transferring back to aspnetcore repo...)

Hi @JustArchi , code that is specific to ASP.NET Core scenarios, such as hosting Kestrel, requires platform support, which as you discovered, it not available on some platforms, such as Android.

I think this might really be a question for the ASP.NET folks as to whether there is a desire to support certain features, such as Kestrel, on "arbitrary" platforms, or whether to specifically add support to particular platforms (e.g. android-x86).

Hosting a local web server in a cross-platform app is something reasonable (though perhaps not super common), so it's worth considering.

For right now I'm not aware of any plan to support this.

Eilon commented

Tagging @danroth27 because I think you mentioned something about this the other day.

Thanks for your answer @Eilon, I appreciate it.

Hosting a local web server in a cross-platform app is something reasonable (though perhaps not super common), so it's worth considering.

Yeah I definitely don't see everybody jumping on this idea right away and bundling every Android/iOS/etc app with a local web server, but I also came to conclusion that it's something reasonable enough to at least suggest/evaluate on. I have no idea how much work would be required to bring ASP.NET Core runtime to those new .NET 6.0 platforms, but if it helps in any way then I'd be definitely interested in making use of such functionality, at least for that one use case I have in mind.

It could also be a decent alternative if somebody wanted to build an app that looks more like a typical website to you. To give you some idea, I have a CLI app realizing its functionality with bundled Kestrel web server and MVC APIs, which is not really any different from a typical ASP.NET Core website, but it's more of the CLI app and APIs are just an extra. Anyway, I bundle that app with frontend written in html/css/js (static files that Kestrel serves), which results in user navigating to his localhost app address, where he can control the app through a website interface (that calls appropriate API endpoints).

As an experiment I tried to convert this "idea" into Android app, where the app could create a very simple Webview with that localhost address (where the frontend is already mobile-aware), while launching the backend part the same as on all other OSes I build this for. This in result failed as of today, since there is no ASP.NET Core runtime for Android (which is just an example platform I tried to test it on).

I'm describing that just to give you some insight into what this whole "feature request" could be useful for, while MAUI is great on its own and building new apps is definitely going to be interesting, there might be more of such CLI apps with some kind of web interface that could easily be converted into Android apps without much hassle if just the ASP.NET Core runtime was available to make use of. It's not like my app requires something more than a web server with static files and MVC APIs anyway.

In any case thank you in advance for evaluation of this idea, perhaps it could be something to think of for the future.

@davidfowl feel free to update the label. This seems to be the closest match.

@JustArchi to second your "reasonable scenario" statement.

We are actually started using local GRPC (client and server) in our current Xamarin app as an IPC technology to communicate between two apps.

We have some LOB-concerns which forces us to do a lot (and kinda complex) local IPC between our app and a third party app.

And to use one identical API technology on all Platforms targets (Android, iOS and Windows) we've chosen grpc.

I've got the "same" problem.
I'm trying to add DI to my maui app using the idea James wrote here https://montemagno.com/add-asp-net-cores-dependency-injection-into-xamarin-apps-with-hostbuilder/
And then I get the error:

NETSDK1082 There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'iossimulator-x64'.
Sample.Mobile.Maui
C:\Program Files\dotnet\sdk\6.0.100-rc.2.21505.57\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets 427

The same goes for maccatalyst-x64, android-x86 and linux-arm.

I created a mauilib with the default structure:

<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<TargetFrameworks>net6.0-ios;net6.0-android;net6.0-maccatalyst</TargetFrameworks>
		<!-- <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows')) and '$(MSBuildRuntimeType)' == 'Full'">$(TargetFrameworks);net6.0-windows10.0.19041</TargetFrameworks> -->
		<TargetPlatformMinVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.17763.0</TargetPlatformMinVersion>
		<UseMaui>true</UseMaui>
		<SingleProject>true</SingleProject>

		<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-ios'">14.2</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-maccatalyst'">14.0</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-android'">21.0</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.18362.0</SupportedOSPlatformVersion>
	</PropertyGroup>

	<ItemGroup>
	  <Folder Include="Platforms\iOS\" />
	  <Folder Include="Platforms\Windows\" />
	  <Folder Include="Resources\Fonts\" />
	  <Folder Include="Resources\Images\" />
	</ItemGroup>

</Project>

I tried recreating the projects twice from the command line, but it still won't work. dotnet new maui and dotnet new mauilib.

Is there a workaround for this? I'd very much like to be able to use DI, but I'm blocked as is.

Checking up the nuget repository, I found the references, but for .Mono. Is there something I'm doing incorrectly?
2021-10-20 at 10 40 51@2x

@eestein .NET MAUI already has support for dependency injection built-in. MauiAppBuilder exposes a Services property that you can use to configure your services. You shouldn't need to add any additional dependencies.

@danroth27 thanks, I appreciate you taking the time to evaluate my question.
The thing is, I'm not adding anything extra.

This is the info for my maui lib.

These are my usings:

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Maui.Hosting;

These are the only nuget packages I've got installed:
image

These are the dependencies:
image

This is my csproj:

<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<TargetFrameworks>net6.0;net6.0-ios;net6.0-android;net6.0-maccatalyst</TargetFrameworks>
		<Nullable>enable</Nullable>
		<UseMaui>true</UseMaui>
		<SingleProject>true</SingleProject>

		<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-ios'">14.2</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-maccatalyst'">14.0</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="'$(TargetFramework)' == 'net6.0-android'">21.0</SupportedOSPlatformVersion>
		<SupportedOSPlatformVersion Condition="$(TargetFramework.Contains('-windows'))">10.0.18362.0</SupportedOSPlatformVersion>
	</PropertyGroup>

	<ItemGroup>
		<ProjectReference Include="..\Sample.Data\Sample.Data.csproj" />
	</ItemGroup>

</Project>

And I still get the error:

/usr/local/share/dotnet/sdk/6.0.100-rc.2.21505.57/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(427,5): error NETSDK1082: There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'iossimulator-x64'. [/Users/eestein/Documents/dev/smp/sample-repo/Sample/Sample.Mobile.Maui/Sample.Mobile.Maui.csproj]

I'm not trying to waste anyone's time here, believe me when I tell you I research a lot before asking. The thing is I'm stuck on this one since yesterday. Before trying many things I found online I recreated the projects twice and they still won't work. I tried recreating from VS2022 and also from the command line on my macOS. I still get the error when I reference my mauilib from the maui app.

Why did you include ASP.NET Core if you're only trying to use dependency injection?

@davidfowl I didn't... I just created the maui lib using the provided template. And, I also tried removing that framework, I just couldn't find a way to do so.

I do need to use HttpClient, though

Eilon commented

@eestein is that the CSPROJ of the project that's failing, /Users/eestein/Documents/dev/smp/sample-repo/Sample/Sample.Mobile.Maui/Sample.Mobile.Maui.csproj? Is there any other .targets or .props file or a global.json that might be affecting things?

@Eilon let me take a closer look and I'll get back to you on that. Thanks.

I'm also looking for specific packages that could be adding the FW.

Maybe it's the SampleData project reference?

Eilon commented

A plain dotnet new mauilib should not reference AspNetCore in any way, so something else is bringing it in.

Thank you, gentlemen!
@davidfowl your comment made me realize there was one specific thing I hadn't tracked. The problem was that one of the libs had a reference to FluentValidations.AspNetCore instead of FluentValidations. That's what was loading the aspnetcore FW.

I'm sorry to have wasted your time. But I also think, if possible, a better error message could be provided. If in the message we could see the offending library, that would help a lot!

Thank you all, @danroth27 , @Eilon and @davidfowl

Please consider my suggestion for the error message.

Come on guys and gals, GRPC is THE strongly advertised tech from MS for IPC and SOA.
You really need to bring asp.net to Net 6 (Xamarin) iOS and Android Runtimes.

In the end, that was the promise MS made, one runtime for all Platforms, not: your lib might only run on one or two Net 6 runtimes (bot not on ios or android or uwp).

Today we can still use the "Grpc.Core" Server wich works without asp.net, but this will be deprecated in the near future.

rpc-dotnet (the Grpc.Net.Client and Grpc.AspNetCore.Server nuget packages) is now the recommended gRPC 
implementation for .NET/C#. The original gRPC C# implementation (the Grpc.Core nuget package)

https://grpc.io/blog/grpc-csharp-future/

I am quite confused why this is still not supported. I already use the Kestrel webservice in my Xamarin app for a while. It seems that Microsoft.AspNetCore (v2.2.0) works fine in Xamarin and probably will work in MAUI too. Later versions don't work anymore, because they are not available as separate packages. I never understood why an application that exposes a web-service should be treated so special (I don't know of any other language that does this). ASP.NET core was just a bunch of packages with .NET core v2.2 and it worked fine.

I tested it with iOS, Android and UWP applications without any issues. I was hoping that MAUI and .NET 6 would really bring us one .NET.

Hi folks. I'd like to collect some more details on the specific scenarios for using ASP.NET Core in a mobile app. So far from the feedback in this issue I've identified two scenarios:

Anything else?

@danroth27 thanks for taking a look into this.

Additional to #35077 there is local network GRPC planned.
For example:

  • GRPC call from a smartwatch to mobile-phone
  • GRPC call from a pc to a mobile phone

tl/dr:

  • case "smartwatch -> mobile" : ad-hoc controlling the app temporarily, when you need your hands and cannot hold the mobile phone at the moment; afterwards continuing on the phone
  • case "pc -> mobile phone": use the convenience of a keyboard and big screen to enter data and review the result of the data collected with the mobile phone

It all boils down to one person continuously switching between 3 devices (mobile phone, pc, smartwatch) to do its work.
Functionality/state which is held on one "main" device (usually mobile phone), and depending the circumstances is controlled by phone itself, smartwatch, pc.

Usually you would do that with a central server/could service holding the state/functionality.
For privacy and ease of configuration reasons, we are bound to the solution of no-server/cloud solution, where the "main" device holds the state.

Hi folks. I'd like to collect some more details on the specific scenarios for using ASP.NET Core in a mobile app. So far from the feedback in this issue I've identified two scenarios:

Anything else?

This absolutely wonderful, thinking about a fully functioning backend web server (restful api, gRPC, signalR, database etc.) working with WebView, this gonna change the way people build mobile apps!!!

Really looking forward to this.

Putting this on the @dotnet/aspnet-blazor-eng radar. This is not really a general area-infrastructure issue.

@dougbu I’m not sure why this is marked a Blazor issue. It has nothing to do with Blazor. When you read my comment from December 7, then I try to explain that it is a fundamental .NET issue, because Kestrel isn’t an ordinary package anymore, but considered a β€œplatform”. It”s not a real MAUI issue, but a fundamental ASP.NET issue.

We implemented a Kestrel based webserver (using ancient Kestrel package from the .NET Core 2.2 era) and have an Angular client on top of it. It works great, but not being able to upgrade Kestrel is not a sustainable solution.

This is area-runtime as it is about being able to use <FrameworkReference Include="Microsoft.AspNetCore.App" /> within a Maui application.

Thanks @ramondeklein and @javiercn for clearing up my confusion

I'm actually not sure this belongs in runtime πŸ˜„

@davidfowl well... it's about kestrel... πŸ˜„

Hi folks. I'd like to collect some more details on the specific scenarios for using ASP.NET Core in a mobile app. So far from the feedback in this issue I've identified two scenarios:

@danroth27 Thank you very much for giving this attention. I've run into this in these scenarios:

  1. I've made a controlpanel for starting, stopping, setting port, getting messages etc. for a local webserver made with Kestrel and Minimal api in MAUI. I was hoping that it would be cross platform, so I could use it on Mac Desktop, but using Sdk="Microsoft.NET.Sdk.Web" tells me that this is a no go on Catalyst becasue of There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'maccatalyst-x64'
    The usecase here is "Make a crossplatform (local) server with GUI control"

  2. I tried to build my Controlpanel+server in Blazor WASM, but got a similar error.
    The usecase here is "Build and distribute an API that can run on client computer without install"

  3. Quite a few IOS apps use local servers for sharing files with desktop computers on the same network. It's a really simple and nice way to share data.
    The usecase here is "Share data from App on local network via http"

  4. Expose a "Control panel" for a mobile app. Start/stop/Record/Pause/Take photo etc.
    The usecase here is "Expose a web GUI interface on the local network to control an app"

@davidfowl wrote

I'm actually not sure this belongs in runtime πŸ˜„

If this means making Kestrel usable without the breaking dependencies , +1000 thums up :-)

@danroth27 For us the requirement would be to wrap an SPA that talks to an backend together with that backend into a desktop application. On Windows that is not a problem, but this application should also work on a Mac, so MacCatalyst should be supported.

The embedded backend should be able to provide http Endpoints for the SPA running in a MAUI Webview, so that the SPA app can access the local backend, as well as provide support for EF Core so that the standalone desktop version can connect to a database (which would require to open a TCP connection, which also does not work on the iOS-App-wrapped-in-catalyst at the moment.

For the moment Windows and Mac-Desktop are the main targets, Linux would be awesome. Mobile (iOS / Android) not so much.

Plan B would be to use an electron host that could launch the API as another process, but when we are not within the same application it's way more complicated to TLS the api access without running into several self-signed certificate issues.

Exposing a real TCP listener in your app can be problematic for multiple reasons (listeners may be blocked by local firewall-type tools, and it's difficult to be sure that you're not processing requests from unsanctioned 3rd-party processes running on the same machine). If at all possible I'd recommend setting up a different, non-HTTP communication channel from your JS code to the hosting .NET application. That's how BlazorWebView works, and can be achieved using the web view's JS interop APIs.

Exposing a real TCP listener in your app can be problematic for multiple reasons (listeners may be blocked by local firewall-type tools, and it's difficult to be sure that you're not processing requests from unsanctioned 3rd-party processes running on the same machine). If at all possible I'd recommend setting up a different, non-HTTP communication channel from your JS code to the hosting .NET application. That's how BlazorWebView works, and can be achieved using the web view's JS interop APIs.

The idea is to take a currently existing and cloud-hosted App-environment (SPA and corresponding API) and package that together as a standalone Desktop app, that should be able to run on deliberately non-connected computers (yes, these still do exist). And no, there are no unsanctioned processes on that machine, for sure ;)

Let's just for a moment assume that it would be feasible to monkeypatch the fetch / http APIs in the browser to redirect all of the http requests the SPA does, through a JS interop API. Then the next big problem would be to replace the inner workings of the API part to receive the interop calls, create a fake request and then somehow dispatch that through to the hundreds of controller actions which are called.

But to achieve that, we would still need to be able to compile the existing code of the system, especially the controllers, the DI system, the SignalR Hub from ASP.NET Core and everything else including the EF Core part of the API against Mac Catalyst, to even try to achieve to replace all the inner workings. That would still require ASP.NET Core to support the MAUI runtimes (at least MacCatalyst).

Electron would make this possible, but the client would be way more happy if it was a pure .NET solution.

Hi folks. I'd like to collect some more details on the specific scenarios for using ASP.NET Core in a mobile app. So far from the feedback in this issue I've identified two scenarios:

* Building a mobile app as a locally hosted web app ([Support for MAUI runtimes in ASP.NET Core? #35077 (comment)](https://github.com/dotnet/aspnetcore/issues/35077#issue-962146241))

* IPC between apps using gRPC ([Support for MAUI runtimes in ASP.NET Core? #35077 (comment)](https://github.com/dotnet/aspnetcore/issues/35077#issuecomment-908238983))

Anything else?

I think I have a very simple use-case, much simpler than others in this thread. I don't need to run Kestrel at all.

I want to have one application code base but with two deployments:

  • to a mobile app (Android)
  • to a website

But since Blazor Hybrid cannot be deployed as a website, I tried to create 3 projects:

  • Blazor Server-Side app (Web)
  • MAUI Blazor Hybrid (Android)
  • Shared library containing razor pages and components

I can connect Web to the shared library....but this has to be a "Razor Class Library" which references Microsoft.AspNetCore.App.

Connecting the Android project with shared library works but it won't build because of the error mentioned in the first post.

I can connect Web to the shared library....but this has to be a "Razor Class Library" which references Microsoft.AspNetCore.App.

@czmirek A Razor Class Library should only reference Microsoft.AspNetCore.App if it's setup to contain MVC Views or Razor Pages (.cshtml files). If your Razor Class Library only contains Blazor components, then it doesn't need to reference Microsoft.AspNetCore.App.

When you create the Razor Class Library, make sure the "Support pages and views" option is not checked:

image

The project file for the Razor Class Library should look something like this (no FrameworkReference):

<Project Sdk="Microsoft.NET.Sdk.Razor">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>


  <ItemGroup>
    <SupportedPlatform Include="browser" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="6.0.2" />
  </ItemGroup>

</Project>

Just wanted to leave a +1 on gRPC with Android.

We have a framework in place which we use with monoandroid + netcoreapp3.1 + netstandard2.1. All modules either use gRPC as client or offer one or more services through gRPC. Everything runs using Grpc.Core which is EOL in just 3 months. So we are not very comfortable to not have any way forward right now... And we heavily invested into gRPC by also using xDS (client + server), interceptors for AuthN + AuthZ, building our tracing and logging stacks on top of it, and built our whole environment around it.

We use it for IPC on the device between modules, but also for communication with other devices and the warehouse control system (intralogistics). All connected through a central xDS server with custom dynamic service management, where the management is also done through gRPC. We use lots of bi-directional streaming too, like for observers and events.

We had hoped that the unification of .NET 6 would resolve that issue before the EOL. So I would really love to see that this gets some attention, since it doesn't seem to be an so unusual use-case anymore.

Hello. I would just like to add my use case to your discussion.
I am working on an online web app that creates HTML presentations, similar to RevealJS.
I would like to create an offline app using MAUI but ideally I don't want to run the HTML file from the file system, ideally I want to spin up a web server and then copy the files there.
The HTML presentation and asset files (images, etc) are in a zip for offline viewing, so the MAUI app would spin up a server, unzip/deploy the files to that server then display the index.html in a WebView.

My use case is not exactly what you are talking about, I don't need a ASP server, just a plain old web server.

Hi. I also ran into this issue. Not because I actually wanted to spin up a webserver, but because I use a shared project which includes all the request/response models for my API. I use StronglyTypedId for my models, which automatically generates the required structs and converters. It also generates a ValueConverter for EntityFrameworkCore and because of this, Microsoft.NETCore.App gets referenced.
I know that maybe this is an edgecase, but it's still a big problem, because the only option I have right now, is to not use StronglyTypedId, otherwise I'm not able to reference the shared project.

Hi. I have created a sample project that ASP.NET Core 2.2 works fine on Xamarin.Android 12 and net6.0-android.
I think since the old version of 2.2 works fine, the new version of 6.0 shouldn't be too difficult to run, but at the moment the SDK is blocking the reference.

this is the compiled APK package

net6-Signed.apk

XamarinAndroid12-Signed.apk

https://github.com/BeyondDimension/AspNetCore.Mobile/tree/net6.0-android_with_asp.net_core_2.2

Also in this example the WebHost is hosted on the activity, it would be better to host it in the Foreground Services

Eilon commented

@AigioL yup, this pattern may very well have worked in older versions of ASP.NET Core because back then a lot of the code was in regular NuGet packages and didn't use a "runtime". In the "runtime" model many NuGet packages contain just API definitions (if at all), but all the implementation is in a "runtime" that is platform-specific. But in more recent versions of ASP.NET Core, the "runtime" is used for a lot more features, meaning that if you don't have a compatible runtime for the platform you're running, you have no code to run.

Any update on this? I would like to run a Kestrel server on an iOS device using MAUI, I was able to do this on Xamarin.

Exposing a real TCP listener in your app can be problematic for multiple reasons (listeners may be blocked by local firewall-type tools, and it's difficult to be sure that you're not processing requests from unsanctioned 3rd-party processes running on the same machine). If at all possible I'd recommend setting up a different, non-HTTP communication channel from your JS code to the hosting .NET application. That's how BlazorWebView works, and can be achieved using the web view's JS interop APIs.

Exposing a http listener / tcp listener is no problem at all we're doing this currently with our Xamarin solution. Mobile os'es like Android and IOS are working out of the box with the solution below. For your third party concern it's easy to fix this by simply adding an authentication header on a custom Webview renderer. I think the solution with JS interop is a lot hackier way to run a real world React application with websockets and ajax requests.

private static Uri GetFreeListenerEndPoint()
{
            var l = new TcpListener(IPAddress.Loopback, 0);
            l.Start();
            var ep = (IPEndPoint)l.LocalEndpoint;
            l.Stop();

            return new Uri($"http://{ep.Address}:{ep.Port}/");
}

Interesting thread, and I thought I would put my use case in here.

I have an app called PresenceLight, which is currently a .NET 6 WPF app that broadcasts Teams presence to smart lights and as part of that app, I have to do an OAuth dance to register access of PresenceLight to a user's LIFX Cloud account. I am currently doing this by spinning up a Kestrel server that runs during the token retrieval process. Here is the code that does that

https://github.com/isaacrlevin/presencelight/blob/083e92bd5245f10cb613fa3025f4d964cea1a5a4/src/PresenceLight.Core/Lights/LifxServices/LIFXOAuthHelper.cs#L38

I see this sort of experience is not available currently in MAUI because of lack of MAUI runtime support for ASP.NET Core. I know there are alternative workarounds, but would love if the same experience I have building an app in WPF would just work in MAUI.

Interesting thread indeed, just to add to the examples on why it would be great to be able to run ASP.NET Core 6 with (in my case) net6.0-android...

We're building an app for azena.com, an Android based OS for AI-cameras. To be able to expose HTTP API's, they host the webserver and we get a RPC-like callback with an 'AzenHttpRequest' (including a request-stream, method, etc.) that must be returned with an 'AzenaHttpResponse'. We already have a lot of ApiControlers/routes that we host on other platforms and want to re-use. We were able to bring IServer, IFeatureCollection and all to life, but only in the aspnetcore 2.2. It would be great if somehow this was possible with individual packages or if the net6+ generation of the runtime got compatible with net6.0-android.

Exposing a http listener / tcp listener is no problem at all we're doing this currently with our Xamarin solution. Mobile os'es like Android and IOS are working out of the box with the solution below. For your third party concern it's easy to fix this by simply adding an authentication header on a custom Webview renderer.

A TCP listener is not an HTTP server. Even the HTTP listener is a very basic primitive compared to Kestrel that has much more features. One of the downsides of the HTTP listener is that it doesn't support request cancellation, which makes it difficult to implement an event-source handler. With Kestrel the event-source is alive as long as the HTTP request isn't cancelled. Also Kestrel has a much broader ecosystem and supports all kinds of middleware that can be useful for authentication, caching, rate-limiting, ... Implementing this manually is a source of bugs and potential security issues.

Choosing a base SDK that targets either ASP.NET Core, MAUI, WPF, ... is nice as a convenience feature, but it shouldn't dictate the possible combinations. I don't understand why you can't combine Kestrel / ASP.NET Core with WPF and/or MAUI. Every article describing MAUI speaks about "one .NET", but it's simply not true. There is no one .NET. You still need Mono for some projects and you can't even combine libraries within a single architecture.

Eilon commented

I don't understand why you can't combine Kestrel / ASP.NET Core with WPF and/or MAUI

It's a feature request that hasn't been implemented, that's why.

I don't understand why you can't combine Kestrel / ASP.NET Core with WPF and/or MAUI

It's a feature request that hasn't been implemented, that's why.

Real constructive argument... Why is combining libraries considered a feature? Why not just add the Kestrel assemblies and the MAUI or WPF assemblies in one executable? It worked that way up to .NET Core v2.0, but MS decided to make things "easier" by providing additional frameworks that are not interoperable...

@ramondeklein we know the feature is important, we have a list of scenarios, it hasn't been prioritized amongst the 7.0 work, we haven't closed on the plan here as yet, and we'll update the issue when we do.

@davidfowl what’s your suggested workaround in the meanwhile?

Googles grpc Server paket was deprecated a year ago in favor for the MS grpc Server, will Google’s Paket work under MAUI?

We have an existing Xamarin project with grpc.
Should we:

  • A: wait two years and keep using Xamarin, which is already badly supported today?
  • B: switch our project to MAUI, and hope the deprecated Google grpc server will work under Maui for the next two years?
  • C: abandon the highly by MS advertised technology GRPC and use another API technology, like 0MQ or MQTT?

The most short term thing you can do to get an Http server going would be to use HttpListener.

The most short term thing you can do to get an Http server going would be to use HttpListener.

Sadly that doesn’t answer the question.
I don’t see how that would work with the MS GRPC Server which uses HTTP/2.
Could you please elaborate a little and try to provide an actual workaround for us to use GRPC server in the next (at least) two years.

According to https://groups.google.com/g/grpc-io/c/OTj5mb1qzb0 we can at least use the old Grpc.Core for one more year until we run into the end-of-life issues again. The new lib sadly does still not really work on the Xamarin stack (while the old did). Sadly, @jtattermusch also mentioned there, that support for Xamarin and Unity will most likely be dropped. That's a huge bummer for us, since it basically means, we now have a whole product and framework build on top of a dying horse without real alternative.

Sadly that doesn’t answer the question. I don’t see how that would work with the MS GRPC Server which uses HTTP/2

Ah sorry, the question was about gRPC specifically, my bad.

Could you please elaborate a little and try to provide an actual workaround for us to use GRPC server in the next (at least) two years.

What @Falco20019 said about grpc.core is your best bet in the short term while we figure this out.

  • A: wait two years and keep using Xamarin, which is already badly supported today?
  • B: switch our project to MAUI, and hope the deprecated Google grpc server will work under Maui for the next two years?
  • C: abandon the highly by MS advertised technology GRPC and use another API technology, like 0MQ or MQTT?

Option B is what would be suggested and is also done by us.

We hope, that ASP.NET Core support is added at some point or that grpc-dotnet decides to not depend on ASP.NET Core but just on the interfaces (like we had Microsoft.AspNetCore.Hosting.Abstractions in the past) used there, as these are technically also mostly available on the Generic Host. It's just missing some of the pre-existing dependencies and parts of the pipeline. But in my opinion, this is something that could be left to the end-user to take care of. So on ASP.NET Core it would just be working, on Xamarin, you at least could fill the gaps yourself. But without abstraction package, we are out of luck right now.

if the MAUI cross-platform application cannot communicate with Asp server, than the whole MAUI is useless... It can be used to create a simple "Calculator" app, Enterprise cross-platform client-server applications are not possible to be created with dotnet.
In my opinion, this should be fixed ASAP if Microsoft wants MAUI to be treated seriously.

@kucint I think you got this issue wrong. This is not about MAUI communicating with an ASP.NET Core Backend (that is working fine already), but about HOSTING an ASP.NET Core SERVER inside a MAUI-App using kestrel...

@chrfin Right, I got it wrong. Thanks for the clarification.
However, I cant agree with you completely. I still cannot create macOS MAUI app that references ASP. See Maui and Grpc cannot work together on MacOS?.
I would be happy if you would tell me that I miss something here and it is possible.

@kucint GRPC needs an ASP.NET Core Server -> for that case it's the correct issue ;-)...

@chrfin Thanks!
Does "my issue" (gRPC and MAUI on macOS) belong to the current thread? Or shall I rather create a new one? What do you think?

@kucint It depends on your use-case. #6057 is sadly not that expressive on that. Do you want to host an gRPC service to be called by a third party on macOS or do you only want to use the gRPC client on Windows + macOS? If the later, then you should not include Grpc.AspNetCore but Grpc.Net.Client which works fine on all platforms that support HTTP/2. And for those who don't (like Android) there is a workaround.

There is a good entry page for that here: https://docs.microsoft.com/en-us/aspnet/core/grpc/supported-platforms?view=aspnetcore-6.0

So this thread would only be relevant for hosting an gRPC server on your macOS application using MAUI. But according to https://docs.microsoft.com/en-us/aspnet/core/grpc/troubleshoot?view=aspnetcore-6.0#unable-to-start-aspnet-core-grpc-app-on-macos there definitely seems to be support for ASP.NET Core on macOS (otherwise this page would make no sense).

You might need to have the part of code for running ASP.NET in a separate library targeting net6.0 instead of net6.0-maccatalyst for it to work. But that would sound more like a build-chain issue and not like a runtime issue (but still something IMO worth to have discussed/linked in here).

Sadly that doesn’t answer the question. I don’t see how that would work with the MS GRPC Server which uses HTTP/2

Ah sorry, the question was about gRPC specifically, my bad.

Could you please elaborate a little and try to provide an actual workaround for us to use GRPC server in the next (at least) two years.

What @Falco20019 said about grpc.core is your best bet in the short term while we figure this out.

Thanks for taking a second look and the answer.

@Falco20019 Thanks for explanation. This helped a lot.
I want to use the gRPC client on Windows + macOS, as you correctly assumed.
Following your advice, I switched to Grpc.Net.Client in my client app.
So the situation looks as follows, I have following projects in my Solution:

  • MauiApp
    • targets net6.0-windows10.0.19041 and net6.0-maccatalyst
    • references GrpcLib
  • GrpcLib
    • targets net6.0
    • references Grpc.Net.Client , Grpc.Tools, Google.Protobuf

I still get an error when building MauiApp
C:\Program Files\dotnet\sdk\6.0.300\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(427,5): error NETSDK1082: There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'maccatalyst-x64'.

Stupid question:

  • I currently build the solution on windows machine rather than mac directly.
    Can this be a cause of the error? Will error disappear when I build the solution on mac?

@kucint I would like to move helping you on that issue over at dotnet/maui#6057 (comment) to avoid triggering notifications for everyone :) Since the client should not have a reference onto ASP.NET Core, it would not belong here.

if the MAUI cross-platform application cannot communicate with Asp server, than the whole MAUI is useless... It can be used to create a simple "Calculator" app, Enterprise cross-platform client-server applications are not possible to be created with dotnet. In my opinion, this should be fixed ASAP if Microsoft wants MAUI to be treated seriously.

Totally agree - this means we are back to Electron and MAUI is out of the picture. Also my other grief is that being "cross platform", there are no separate considerations between desktop platforms where it makes sense to have a server vs mobile platforms. I don't see why referencing Microsoft.AspNetCore.App is technically an issue for desktop platforms - totally see that the frameworks needs to be restricted for mobile platforms but macos, linux and windows - please don't restrict these.

I don't understand why you can't combine Kestrel / ASP.NET Core with WPF and/or MAUI

It's a feature request that hasn't been implemented, that's why.

I'd say this one is tricky because for Windows platform you can reference the asp net core but until you start exploring other platforms then you realize that it is a limitation. We had to do quite a bit of prototyping to figure out this was a hard limitation.

@danroth27 @davidfowl Is there any roadmap for this? Grpc.Core is dropped in May 2023. The new path is still not usable on .net6.0-android. I understand that it has no priority for .NET 7 but would still love to see it at least on some roadmap for .NET 8 as gRPC on Android is business critical for us.

I also understand the decision to drop a feature that was only marked as experimental, but as it did work, there are companies who build their software using it. Including ours. We also are heavily using xDS support in Grpc.Core and look forward for it to return in the new library, as the workaround to use an off-process proxy like envoy is just not working with Android.

Yes for .NET 8 there will be an effort to figure out what needs to be done to make this scenario work.

@danroth27 @davidfowl we are upgrading a Xamarin Native (Android) app to .NET 6. Our app relies on a WCF project which was migrated to CoreWCF (NET 6). We installed CoreWCF.WebHttp v1.1.0) NuGet package but we get the error: "there was no runtime pack for Microsoft.AspNetCore.App availabile for the specified RuntimeIdentified' android-arm64. Looks like this CoreWCF.WebHttp package depends on some AspNetCore packages. Any suggestion here?

Is the new CoreWCF release compatible with Xamarin Native under NET6?

Is the new CoreWCF release compatible with Xamarin Native under NET6?

@adolfo1981 Unfortunately no, I don't believe so. We don't have ASP.NET Core support for mobile scenarios. That's what this issue tracks adding, specifically for .NET MAUI.

@danroth27 Thanks for the quick reply! We'll have to evaluate other options then.

@danroth27 I want to use Asp.NET Core in a .NET MAUI desktop application for Windows and MacOS. In .NET MAUI project I unchecked iOS and Android targets. I added following in csproj file:



When I compile it on windows, it give me this error:
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'maccatalyst-x64'
When I remove net6.0-maccatalyst from project file, then it compile successfully and I was able to start web server on windows MAUI desktop application.
Can you guys add support Asp.NET core in maccatalyst-x64?

@danroth27 I want to use Asp.NET Core in desktop platforms on Windows and MacOS. In .NET MAUI project I unchecked iOS and Android targets. I added following in csproj file:

If you want to use ASP.NET Core, you should not use the MAUI template but the ASP.NET Core template. MAUI is for the UI which you won't use.

See dotnet/maui#6057 (comment) for a similar case. You just need to target net6.0 instead of a platform specific one to have the cross platform ASP.NET Core version available.

If you want to embed the generic host into a desktop UI, you might want to put the kestrel part into a separate project targeting net6.0 and call it from your MAUI assembly.

@Falco20019 I want to embed the kestrel in desktop UI. Your proposed solution does not work. I created separate Asp.NET core project and added reference to MAUI project, it gives compile time errors:
There was no runtime pack for Microsoft.AspNetCore.App available for the specified RuntimeIdentifier 'maccatalyst-x64'

You can not directly include it. I meant to create the assembly separately and have the UI start and stop the other assembly. You basically have to deploy them together.

It's sadly not possible to combine MAUI with Kestrel right now in one assembly. It would work if you could target net6.0-macos, but AFAIK needs MAUI net6.0-maccatalyst.

Because to me, it sounds you only want to have something like Start/Stop Buttons and show some other information through MAUI for the frontend part?

I only wanted to offer you a workaround. Making it possible out of the box is definitely why it's good to have your post in here πŸ‘Œ

Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue.

This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue!

@danroth27 Please keep open until there is another official place

We have just hit this issue too. Our use case is a MAUI application that is displaying charts using TradingView Charting Library, which is implemented as a JS client that needs a web server as its data feed.

This sadly stops me from being able to port PresenceLight to MAUI as I have to spin up a Kestrel server to handle auth redirects from the desktop client. Is there a workaround for this in the time being @davidfowl?

This definitely needs to be implemented ASAP. there are LOB apps out there, which are depending on this feature and are now stuck with Xamarin ☹️

Eilon commented

This definitely needs to be implemented ASAP. there are LOB apps out there, which are depending on this feature and are now stuck with Xamarin ☹️

I don't think there's any change here between Xamarin and .NET MAUI. This is about supporting ASP.NET Core on Android/iOS/MacCat target frameworks.

We have a javascript static application and API + SignalR thats run on a Asp Net Core Server on a WindowsForms application.
Supporting MAUI to run under the cloth a API/Static/SignalR is technically possible (For Windows, IOS, Android, ...)?
Thats really useful as we can have a WebView on MAUI.

We needed a local API to interface with an online web application, so we needed ASP.NET api support. After finding out we can't use it because of the exact same issue, we went ahead and rewrote our API (it was only a couple of API calls) using HttpListener. If anyone needs basic functionality for some cross-platform interfacing, I would suggest doing the same.

We needed a local API to interface with an online web application, so we needed ASP.NET api support. After finding out we can't use it because of the exact same issue, we went ahead and rewrote our API (it was only a couple of API calls) using HttpListener. If anyone needs basic functionality for some cross-platform interfacing, I would suggest doing the same.

In some cases the HttpListener is a reasonable alternative (although it's pretty low-level). The biggest issue with HttpListener is that it doesn't support a request aborted notification. But of course you also miss all the ASP.NET middleware options. It would be good if Microsoft could explain why it is so difficult. AFAIK, Kestrel is 100% C# code, so why isn't it possible to combine it with MAUI?

I would like to ask the same question as @ramondeklein. What would it take to make ASP.NET Core to run on maccatalyst?

@MartyIX You could compile your own Kestrel from aspnetcore. The IsPackable .csproj PropertyGroup Element will need adjusting on a few of the packages. I also commented out hostBuilder.UseQuic in WebHostBuilderKestrelExtensions.cs and removed Libuv and Transport.Libuv and Transport.Quic from Kestrel.slnf.

Below is basically what I did:

  1. clone aspnetcore
  2. git checkout release/6.0
  3. git checkout tags/v6.0.11
  4. git submodule update --init --recursive
  5. patch -p1 < kestrel-6.0.11.txt
  6. ./restore.sh
  7. zsh -e pack.sh.txt (it's a zsh script)
  8. find artifacts -name '*.nupkg' | ggrep 6.0.11.nupkg | xargs -I % cp -i % ~/yourNugetFolder
  9. dotnet new maui -o MauiEmbeddedKestrel --name MauiEmbeddedKestrel
  10. modify relevant .csproj
  11. update MainPage
  12. dotnet build -t:Run -f net6.0-maccatalyst

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="6.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Http.Results" Version="6.0.11" />
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="6.0.11" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="6.0.11" />
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="6.0.11" />
</ItemGroup>

pack.sh.txt
kestrel-6.0.11.txt
MainPage.xaml.txt
MainPage.xaml.cs.txt

Oh, thanks! I'm looking forward to testing it!

@brianmed are you willing to create a nuget package from your changes? Would help a ton!

@brianmed are you willing to create a nuget package from your changes? Would help a ton!

@DoubleDBE I will not be, however, feel free and do so!!

I tried to build asp from source code on macOS arm64 but I get this error when running dotnet build (in folder https://github.com/dotnet/aspnetcore; i.e. step 7):

/Users/username/aspnetcore/src/SiteExtensions/LoggingAggregate/src/Microsoft.AspNetCore.AzureAppServices.SiteExtension/Microsoft.AspNetCore.AzureAppServices.SiteExtension.csproj : error NU1301: The local source '/Users/username/aspnetcore/artifacts/packages/Debug/NonShipping/' doesn't exist. [/Users/username/aspnetcore/AspNetCore.sln]

Does anyone know what might be wrong?

The idea was to find out what would be necessary to make ASP.NET work on MacCatalyst but unfortunately I failed much sooner than that.

@MartyIX What are the exact commands you are running? Did you run ./restore.sh and then the zsh script?

I just cloned and built the nuget packages on macOS x64.

@MartyIX What are the exact commands you are running? Did you run ./restore.sh and then the zsh script?

I have tried to build complete ASP.NET using macOS arm64. Without really wanting to compile it for MacCatalyst. But I failed. I mean I would like to understand what would be needed to make MacCatalyst a supported platform for ASP.NET.

So I was attacking it from a different angle. Anyway, I was following https://github.com/dotnet/aspnetcore/blob/main/docs/BuildFromSource.md.

Another upvote on this issue.
(Looking to run kestrel on Android)

@davidfowl #35077 (comment) - Is this still planned to be done? Is it likely to be done?

btw: Is there anything that the community can help with?

It's really sad that this is still not really officially planned or communicated. This leaves a lot of uncertainty for companies relying on gRPC as the proclaimed best way for communication. Googles library is still going EOS in May but there is also still no way forward using Microsoft's. With MAUI, this only gets worse as there are more and more use-cases arising.

I really hope this gets some attention for .NET 8. If there are ways to support, I am happily to do so.

@davidfowl, any update on this? anything the community can assist with?

No discussion decision yet?

Another ping from me. Pretty hard to claim .net is cross platform if kestrel doesn't run on android. Just saying....

Also hard blocker for us with gRPC on Android.

Hey everyone, appreciate the interest here! Just to give you an update, based on our current workload and priorities, we don't expect we will have this support ready in .NET 8, but we plan to start looking into it late in the cycle. We'll be sure to share an update once we know more.

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@adityamandaleeka Thanks for the update. We will probably move away from .NET because of this. There is no guarantee that it will be addressed for .NET 9, so we'll move to Flutter.

@adityamandaleeka Thanks for the update. We will probably move away from .NET because of this. There is no guarantee that it will be addressed for .NET 9, so we'll move to Flutter.

And Flutter runtime is supported in ASP.NET Core?