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

Can't get Smart.Format 2.3 working #113

Closed shawndotey closed 5 years ago

shawndotey commented 5 years ago

2.3 or Above Running on .NET Framework 4.5.1

From your documentation:

 var addrList = new[] { new { Name = "Jim", Address = new { City = "New York", State = "NY" } } };
 var test = Smart.Format("{Name} from {Address.City}, {Address.State}", addrList);

Should Output: "Jim from New York, NY" Outputs: " from , "

2.2.0 Works as expected.

Thanks!

axunonb commented 5 years ago

Just checked with v2.3.1 and .Net Framework 4.5.1 in a new project: cannot reproduce the false output, sorry. Please try your test with

Smart.Default.Settings.FormatErrorAction = ErrorAction.ThrowError;
Smart.Default.Settings.ParseErrorAction = ErrorAction.ThrowError;

and you will get an exception with more details.

axunonb commented 5 years ago

Did catching the exception shed some light into your issue?

axunonb commented 5 years ago

Closing after no response

shawndotey commented 5 years ago

Sorry but I do not have time to test, I am using 2.2.0 instead.

martinwtaylor commented 5 years ago

I know this is a closed topic, but in case it helps anyone who googles their way here, I had a similar issue after using Nuget to get MailMergeLib (which has SmartFormat as a dependency) - in dev everything was happy but on deploying the merge fields output empty strings.

Initially, I thought the problem was with that library, so used SmartFormat directly but still had the same issue. After turning on the errors, I got "Could not load file or assembly 'Newtonsoft.Json, Version=11.0.0.0 ..." It seems to be that 2.3.0 and 2.3.1.1 is expecting to use Newtonsoft.Json 11 wheras my application was using Newtonsoft.Json 12.0.1

I was able to get SmartFormat working by upgrading to latest version (2.4.1), which also expect to use Newtonsoft.Json 12.0.1

axunonb commented 5 years ago

Thanks a lot for this very useful hint