© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
1 reply
Brady Kelly

❔ 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
CoreFxWebApplication
is declared in a private NuGet package. This suspicion is based on the exception being thrown in the
CreateBuilder
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
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
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
System.Uri
resulting in the exception being thrown.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

✅ Application only terminates on exception when debugging in Rider but not when debugging in VS2022
C#CC# / help
3y ago
✅ Exception thrown: 'System.FormatException' in mscorlib.dll
C#CC# / help
2y ago
Exception thrown: 'System.BadImageFormatException' in BruhCode2.dllAn unhandled exception of type '
C#CC# / help
3y ago
❔ httpclient not sending request and no exception is thrown
C#CC# / help
4y ago