Search code examples
servicestackormlite-servicestack

ServiceStack ORMLite encoding issue after upgrade


We have just upgraded some software we have from ServiceStack 4.0.62 to ServiceStack 5.0.0.0.

For some reason ormlite's encoding management seem to have changed.

Code that simply saves a DTO with a string field containing special characters (e.g Ø ← ↑ → ↓ ↔ ↕~ Σ ∂ φ) that used to work in 4.0.62 now saves ? in the DB.

Has anything changed that could cause that breaking change. We did not change the save code, and breakpoint just before save clearly shows the correct characters.

This is basicaly the code we are executing:

DB.Save<DTOType>(dtoInstance)

Solution

  • I was going through ServiceStack ORMlite code and found out about this:

    OrmLiteConfig.DialectProvider.GetStringConverter().UseUnicode;

    So I trying that calling

    OrmLiteConfig.DialectProvider.GetStringConverter(); 
    

    just before the DB.Save call returned false, which would explain the issue, as this would set the dbCmd to use VARCHAR instead of NVARCHAR

    I set

     var stringConverter = OrmLiteConfig.DialectProvider.GetStringConverter();
     stringConverter.UseUnicode = true; 
    

    at AppHost initial configuration and that fixed the issue.

    Apparently I cannot read documentation properly as it was described here

    https://github.com/ServiceStack/ServiceStack.OrmLite/wiki/OrmLite-Type-Converters