System.TimeZoneNotFoundException on ViewPage using ServiceStack.Razor

1.7k Views Asked by At

I have created a view using Servicestack.Razor. On the view page I am trying to get the session using following code.

var session = GetSession<AuthUserSession>().ToJson();

When I put this code on the view page, I get following error:

System.TimeZoneNotFoundException
Exception of type 'System.TimeZoneNotFoundException' was thrown.

Description: HTTP 500.Error processing request.
Details: Non-web exception. Exception origin (name of application or object): mscorlib.

StackTrace is as below:

Exception stack trace:
      at System.TimeZoneInfo.get_Local () [0x00000] in <filename unknown>:0 
      at ServiceStack.Text.Common.DateTimeSerializer..cctor () [0x00000] in <filename unknown>:0 

Is this a bug in Servicestack.Text? How can I solve this?

Note: I am using Mono 3.0.10 on Ubuntu 12.10

3

There are 3 best solutions below

0
On

I was getting this same error while working on a project. In my case it was because I did not have a properly exported TZ environment variable. I had to add the following to my UI init shell script:

read TZ 2>/dev/null < /etc/timezone
export TZ
0
On

Mono has a known & longstanding Timezone bug that affects Windows but it SHOULD work in Linux as long as the TimeZone database is installed at /usr/share/zoneinfo. However, that's exactly the same error I get in Windows if I try to serialize a date, so that would make me think that for some reason, /usr/share/zoneinfo is out of place.

If it's NOT there, the workaround in Comment 6 may help you. But then I believe you have to resort to building ServiceStack.Text from sources so you can apply the workaround.

It might be easier to create a symbolic link at /usr/share/zoneinfo that points to wherever it actually is installed.

0
On

.NET Core defers to the OS for timezone-related operations and unfortunately Windows and Linux have different timezone names. Use TimeZoneConverter to convert between them, if needed.

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
    timeZoneName = TZConvert.WindowsToIana(timeZoneName);
}
var zoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timeZoneName);