Hi
I think my TypeSerializer string serializer behaviour is being modified in my dotnetcore web app, but I cannot see where or how this would be happening.
I am experiencing a strange issue where (within my api app) when using the NetCoreAppSettings Get/Set functionality, a string (representing a URL, e.g “https://api.rollbar.com”) is being wrapped in extra doublequotes, so that calling:
appSettings.Set("theApiUrl", "https://api.rollbar.com");
(along the lines of https://github.com/wwwlicious/servicestack-seq-requestlogsfeature/blob/master/src/ServiceStack.Seq.RequestLogsFeature/SeqRequestLogsFeature.cs ), code here:
/// <summary>
/// Sets a seq server url
/// </summary>
public string SeqUrl
{
get => appSettings.GetString(ConfigKeys.SeqUrl);
set
{
appSettings.Set(ConfigKeys.SeqUrl, value);
configValidator.ValidateAndThrow(this);
}
}
actually saves the value setting as “'https://api.rollbar.com”"
So when I later attempt to use the HttpUtils to send a Rollbar tracing message, like so:
var rollbarLogRequest = new RollbarLogRequest();
// Get the url to send to some the appsettings
var getApiUri = appSettings.GetString("theApiUrl");
// Next line crashes, because quote encoding of value inside the getApiUrl string breaks the parsing to new Uri() within SS HttpUtils
var responseFails = getApiUrl.PostJsonToUrlAsync(rollbarLogRequest);
// However, this works perfectly:
var responseWorks = "https://api.rollbar.com".PostJsonToUrlAsync(rollbarLogRequest);
When I attempted to verify that the appsettings setter behaviour in a separate xUnit test project, I can confirm that the strings are NOT getting quote encoded.
[Fact]
public void TestNetCoreAppSettings_ThisWorksGreat()
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", false, true)
.AddEnvironmentVariables();
IConfiguration config = builder.Build();
var netCoreAppSettings = new NetCoreAppSettings(config);
var testIndexName = "dalestest";
var expectedValue = "daleisdoingatest";
netCoreAppSettings.Set(testIndexName, expectedValue);
var getItBack = netCoreAppSettings.Get<string>(testIndexName);
var getItBack2 = netCoreAppSettings.GetString(testIndexName);
Assert.Equal(expectedValue, getItBack);
Assert.Equal(expectedValue, getItBack2);
// THIS typeserializer, in a standalone test class, does NOT escape the string?
var testingAgain = TypeSerializer.SerializeToString(expectedValue);
Assert.Equal(expectedValue, testingAgain);
}
Could there be something funky going on when TypeSerialization is used within my appdomain, possibly due to a jsonserializer or some other setting?
(this is all driven by and based off the excellent https://github.com/wwwlicious/servicestack-seq-requestlogsfeature , which I am adapting to Rollbar, and i will release it as a nuget package once i figure this last bit out)