axuno / SmartFormat

A lightweight text templating library written in C# which can be a drop-in replacement for string.Format
Other
1.1k stars 105 forks source link

Intermittent Exception #289

Closed kampilan closed 2 years ago

kampilan commented 2 years ago

This is happening intermittently. Perhaps 1 out of 50 times. This might not be totally accurate but it feels like it happens more after the app has been idle for a while. I have no evidence of that. Just a feeling.

Thanks Jim

Smart.Format 3.0.0:

Framework version: net6.0

Exception: SmartFormat.Core.Parsing.ParsingErrors - The format string has 1 issue: '0x3D': Invalid character in the selector In: "host=production-2.cluster-XXXXXXXXXX.us-east-1.rds.amazonaws.com; database=connect_v3_prod;user id={ReplicaDbUserName};password={ReplicaDbPassword};AllowUserVariables=true;" At: ----------------------------------------------------------------------------------------------------------------------------------^

at SmartFormat.Core.Parsing.Parser.HandleParsingErrors(ParsingErrors parsingErrors, Format currentResult) at SmartFormat.Core.Parsing.Parser.ParseFormat(String inputFormat) at SmartFormat.SmartFormatter.Format(IFormatProvider provider, String format, IList`1 args)

var legacy = Smart.Format(LegacyDbConnectionTemplate, secrets);

public class SecretsModel {

public string OriginDbUserName { get; set; } = "";

public string OriginDbPassword { get; set; } = "";

public string ReplicaDbUserName { get; set; } = "";

public string ReplicaDbPassword { get; set; } = "";

}

axunonb commented 2 years ago

Hi, in most cases, such issues which are hard to track have their reason in SmartSettings.IsThreadSafeMode is not set to true in a multi-threaded / async context. That's why SmartSettings.IsThreadSafeMode defaults to true in v3.1.0. Also, static Smart.Format(...) could not be used with multi-threading in v3.0.0, because it used a single static SmartFormatter instance. in v3.1.0 Smart.Format(...) uses a ThreadStatic instance of the SmartFormatter. See more in the current Wiki chapter for v3.1.0