❔ Exception thrown in Rider but not in VS2022

I have a web API with a run/debug configuration derived from launchSettings.json. This file defines an environment variable with
"REMOTE_CONFIGURATION_LOCATION": ""
"REMOTE_CONFIGURATION_LOCATION": ""
When I debug the code under Rider one of my two suspicions is that the following code causes a UriFormatException to be thrown and the api terminates after logging the exception to console.
var builder = CoreFxWebApplication
.CreateBuilder()
.ConfigureDefaults()
.ConfigureTelemetry()
.ConfigureApplicationLogging()
.ConfigureApplicationServices()
.ConfigureCors()
;
var builder = CoreFxWebApplication
.CreateBuilder()
.ConfigureDefaults()
.ConfigureTelemetry()
.ConfigureApplicationLogging()
.ConfigureApplicationServices()
.ConfigureCors()
;
The exception is not thrown at all when I debug the code in VS2022. In the above code,CoreFxWebApplication is declared in a private NuGet package. This suspicion is based on the exception being thrown in the CreateBuilder call above, which looks like this:
public static CoreFxWebApplicationBuilder CreateBuilder(bool useRemoteConfiguration = true) => CoreFxWebApplication.CreateBuilder(Array.Empty<string>(), CoreFxWebApplication.LoadOptions(useRemoteConfiguration));
public static CoreFxWebApplicationBuilder CreateBuilder(
string[] args,
CoreFxServiceOptions options)
{
return new CoreFxWebApplicationBuilder(args, options);
}
...
private static CoreFxServiceOptions LoadOptions(bool useRemoteConfiguration)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder();
builder.Configuration.AddConfiguration(builder.Environment.EnvironmentName, LexisHostingEnvironment.GetAssetGroup(), useRemoteConfiguration, LexisHostingEnvironment.GetRemoteConfigurationUri()?.AbsoluteUri, (Action<IConfigurationBuilder>) null);
builder.Services.Configure<CoreFxServiceOptions>((Action<CoreFxServiceOptions>) (o => o.UseRemoteConfiguration = useRemoteConfiguration)).Configure<CoreFxServiceOptions>((IConfiguration) builder.Configuration.GetSection("ApplicationOptions"));
return builder.Build().Services.GetRequiredService<IOptions<CoreFxServiceOptions>>().Value;
}
public static CoreFxWebApplicationBuilder CreateBuilder(bool useRemoteConfiguration = true) => CoreFxWebApplication.CreateBuilder(Array.Empty<string>(), CoreFxWebApplication.LoadOptions(useRemoteConfiguration));
public static CoreFxWebApplicationBuilder CreateBuilder(
string[] args,
CoreFxServiceOptions options)
{
return new CoreFxWebApplicationBuilder(args, options);
}
...
private static CoreFxServiceOptions LoadOptions(bool useRemoteConfiguration)
{
WebApplicationBuilder builder = WebApplication.CreateBuilder();
builder.Configuration.AddConfiguration(builder.Environment.EnvironmentName, LexisHostingEnvironment.GetAssetGroup(), useRemoteConfiguration, LexisHostingEnvironment.GetRemoteConfigurationUri()?.AbsoluteUri, (Action<IConfigurationBuilder>) null);
builder.Services.Configure<CoreFxServiceOptions>((Action<CoreFxServiceOptions>) (o => o.UseRemoteConfiguration = useRemoteConfiguration)).Configure<CoreFxServiceOptions>((IConfiguration) builder.Configuration.GetSection("ApplicationOptions"));
return builder.Build().Services.GetRequiredService<IOptions<CoreFxServiceOptions>>().Value;
}
The CoreFxWebApplicationBuilder constructor the above code involves the following call:
public static Uri GetRemoteConfigurationUri()
{
Uri configurationUri = (Uri) null;
string environmentVariable = Environment.GetEnvironmentVariable(ServiceDefaults.RemoteConfigurationUri);
if (environmentVariable != null)
configurationUri = new Uri(environmentVariable);
return configurationUri;
}
public static Uri GetRemoteConfigurationUri()
{
Uri configurationUri = (Uri) null;
string environmentVariable = Environment.GetEnvironmentVariable(ServiceDefaults.RemoteConfigurationUri);
if (environmentVariable != null)
configurationUri = new Uri(environmentVariable);
return configurationUri;
}
My other suspicion is hinges on the environment variables defined in the launch profiles for Rider and VS for the API. The Rider profile defines the following variables:
ASPNETCORE_URLS=https://localhost:12345
ASSET_AREA_NAME=maximusvote-local
ASPNETCORE_ENVIRONMENT=Development
ASSET_GROUP=xxxxx
APPLICATION_ID=123456
REMOTE_CONFIGURATION_LOCATION=
ASPNETCORE_URLS=https://localhost:12345
ASSET_AREA_NAME=maximusvote-local
ASPNETCORE_ENVIRONMENT=Development
ASSET_GROUP=xxxxx
APPLICATION_ID=123456
REMOTE_CONFIGURATION_LOCATION=
where the Visual Studio profile defines the same set of variables but without ASPNETCORE_URLS. I can't find any usages of this variable in any of the api source code but a lot of functionality is hidden in NuGet packages. I only have this suspicion because with the URL variable only defined in Rider, the code may somehow be trying to create a System.Uri resulting in the exception being thrown.
1 Reply
Accord
Accord2y ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server