.netwcfnhibernateunicode.net-4.0

Periodically - Unable to translate Unicode character X at index Y to specified code page


In our production site (which is a .net 4 hosted WCF application) we did an upgrade to our product and is now .net 4 (before was .net 3.5). This is a large product with over 200K registered users in production. This issue happens at random and will disappear after doing an iisreset.

I found online some pages but no solution to this issue.

We are seeing the following error:

System.Text.EncoderFallbackException: Unable to translate Unicode character \uD83D at index -1 to specified code page.
  at System.Text.EncoderExceptionFallbackBuffer.Fallback(Char charUnknown, Int32 index)
  at System.Text.EncoderFallbackBuffer.InternalFallback(Char ch, Char*& chars)
  at System.Text.UTF8Encoding.GetBytes(Char* chars, Int32 charCount, Byte* bytes, Int32 byteCount, EncoderNLS baseEncoder)
  at System.Text.EncoderNLS.GetBytes(Char[] chars, Int32 charIndex, Int32 charCount, Byte[] bytes, Int32 byteIndex, Boolean flush)
  at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)
  at System.IO.StreamWriter.Write(Char[] buffer, Int32 index, Int32 count)
  at System.IO.TextWriter.WriteLine(String value)
  at System.IO.TextWriter.SyncTextWriter.WriteLine(String value)
  at NHibernate.AdoNet.AbstractBatcher.ExecuteReader(IDbCommand cmd) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\AdoNet\AbstractBatcher.cs:line 239
  at NHibernate.Driver.BatcherDataReaderWrapper..ctor(IBatcher batcher, IDbCommand command) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Driver\BasicResultSetsCommand.cs:line 99
  at NHibernate.Driver.BasicResultSetsCommand.GetReader(Nullable`1 commandTimeout) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Driver\BasicResultSetsCommand.cs:line 54
  at NHibernate.Impl.MultiCriteriaImpl.GetResultsFromDatabase(IList results) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\MultiCriteriaImpl.cs:line 199
2013-08-26 22:52:56,333 [87] *ERROR* NHibernate.Util.ADOExceptionReporter.LogExceptions() -> Unable to translate Unicode character \uD83D at index -1 to specified code page.

It seems like this is happening in the connection between NHibernate and the DB. currently we are only resetting the servers every time this happened. I would appreciate any assistance as we are baffled with this issue here.


Solution

  • Try to set the "show_sql" flag to false in your web.config as well as turning the hibernate log to be something other than debug.

    Thw problem is when the hibernate trys to log the command but it fails on logging some UTF16 charachter (like some emoji). When show_sql is set to tru, it also writes thw kog to srdout, and this might also cause failure.