Can't start server in Xamarin Android #184

Closed
opened 2025-12-29 14:24:37 +01:00 by adam · 0 comments
Owner

Originally created by @eli-darkly on GitHub (Jun 28, 2019).

There's an issue with Xamarin Android's support for ASP.NET Core that currently makes WireMock.Net unusable. I don't think there is currently a workaround, but I think that would be easy to change.

Trying to create a FluentMockServer causes this exception:

System.ArgumentException : A valid non-empty content root must be provided.
Parameter name: contentRootPath
		 at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize (Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, System.String contentRootPath, Microsoft.AspNetCore.Hosting.Internal.WebHostOptions options) [0x00016] in <6ac88ff998174be78f0d6ab05b5f222b>:0 
		 at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices (System.AggregateException& hostingStartupErrors) [0x00116] in <6ac88ff998174be78f0d6ab05b5f222b>:0 
		 at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build () [0x0001a] in <6ac88ff998174be78f0d6ab05b5f222b>:0 
		 at WireMock.Owin.AspNetCoreSelfHost.StartAsync () [0x00039] in <bd776856c0954dd3b7de4c6e428fa31d>:0 
		 at WireMock.Server.FluentMockServer..ctor (WireMock.Settings.IFluentMockServerSettings settings) [0x001e9] in <bd776856c0954dd3b7de4c6e428fa31d>:0 
		 at WireMock.Server.FluentMockServer.Start (System.Nullable`1[T] port, System.Boolean ssl) [0x00018] in <bd776856c0954dd3b7de4c6e428fa31d>:0 

Here's the issue. If you use WebHostBuilder and you don't specify a ContextRootPath in the host builder options, WebHostBuilder tries to create a path from AppContext.BaseDirectory. In Xamarin Android, for whatever reason, there is a known issue where that property is null.

Currently, there is no way to make WireMock set the ContextRootPath. And I don't think that property is actually serving any purpose in this case (since if you're using the filesystem handler, the path is specified by a different mechanism)— but without it, things definitely won't work in Android. I have a solution in mind and I'll submit a PR.

Originally created by @eli-darkly on GitHub (Jun 28, 2019). There's an issue with Xamarin Android's support for ASP.NET Core that currently makes WireMock.Net unusable. I don't think there is currently a workaround, but I think that would be easy to change. Trying to create a FluentMockServer causes this exception: ``` System.ArgumentException : A valid non-empty content root must be provided. Parameter name: contentRootPath at Microsoft.AspNetCore.Hosting.Internal.HostingEnvironmentExtensions.Initialize (Microsoft.AspNetCore.Hosting.IHostingEnvironment hostingEnvironment, System.String contentRootPath, Microsoft.AspNetCore.Hosting.Internal.WebHostOptions options) [0x00016] in <6ac88ff998174be78f0d6ab05b5f222b>:0 at Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices (System.AggregateException& hostingStartupErrors) [0x00116] in <6ac88ff998174be78f0d6ab05b5f222b>:0 at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build () [0x0001a] in <6ac88ff998174be78f0d6ab05b5f222b>:0 at WireMock.Owin.AspNetCoreSelfHost.StartAsync () [0x00039] in <bd776856c0954dd3b7de4c6e428fa31d>:0 at WireMock.Server.FluentMockServer..ctor (WireMock.Settings.IFluentMockServerSettings settings) [0x001e9] in <bd776856c0954dd3b7de4c6e428fa31d>:0 at WireMock.Server.FluentMockServer.Start (System.Nullable`1[T] port, System.Boolean ssl) [0x00018] in <bd776856c0954dd3b7de4c6e428fa31d>:0 ``` Here's the issue. If you use `WebHostBuilder` and you don't specify a `ContextRootPath` in the host builder options, `WebHostBuilder` [tries to create a path](https://github.com/aspnet/Hosting/blob/master/src/Microsoft.AspNetCore.Hosting/WebHostBuilder.cs#L334) from `AppContext.BaseDirectory`. In Xamarin Android, for whatever reason, there is a [known issue](https://github.com/mellinoe/nativelibraryloader/pull/9) where that property is null. Currently, there is no way to make WireMock set the `ContextRootPath`. And I don't think that property is actually serving any purpose in this case (since if you're using the filesystem handler, the path is specified by a different mechanism)— but without it, things definitely won't work in Android. I have a solution in mind and I'll submit a PR.
adam added the bug label 2025-12-29 14:24:37 +01:00
adam closed this issue 2025-12-29 14:24:37 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#184