Strange DateTime Serialization error in RequestDto

This error I see the first time after just rebooting my machine! That code was running hundreds of time before without any error!!

I have a request DTO which I init and then call as follows:

var storeServerConfigRequest = new UpsertBizBusServerConfig()
	RequestMeta = reqMeta,
	Namespace = $"internal:{AccountType.ServiceAccount.ToString()}",
	KeyName = MyServiceConfig.ServiceName,
	InstanceName = Environment.MachineName,
	JsonValue = MyServiceConfig.ServerConfiguration.ToJson(), 
	Expiry = DateTime.MaxValue,
	Version = MyServiceConfig.Version,
	BuildNumber = MyServiceConfig.BuildNumber

catch (BizBusException e)
	Logger.Error($"Error in PersistMyServiceConfig(). Exception: {e.GetAllExceptions()}");

It throws the following Exception:

  at at System.DateTime.op_Addition(DateTime d, TimeSpan t)
  at ServiceStack.Text.DateTimeExtensions.FromUnixTimeMs(Int64 msSince1970, TimeSpan offset) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\DateTimeExtensions.cs:91
  at ServiceStack.Text.Common.DateTimeSerializer.ParseWcfJsonDate(String wcfJsonDate) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\Common\DateTimeSerializer.cs:575
  at ServiceStack.Text.Common.DateTimeSerializer.ParseShortestXsdDateTime(String dateTimeStr) in C:\BuildAgent\work\912418dcce86a188\src\ServiceStack.Text\Common\DateTimeSerializer.cs:90

I am using ServiceStack 5.5 with .NETCore 2.2 on a Fedora 30 Workstation while debugging in my JetBrains Rider IDE.

In the console of my IDE the last statement it writes is:

terminate called after throwing an instance of 'PAL_SEHException'

Any idea what is going on here??

Never seen this error before but it appears it’s a frequent issue for .NET Core on Linux:✓&q=PAL_SEHException

I have NEVER seen such things in the past almost two years where I am writing .NETCore apps. I always develop apps which will run on Linux (docker) on the same OS, which means NEVER on Windows.

I have updated my machine and got new versions of the .NETCore 2.2 runtimes, but no change, still the same error.

Any idea who could help ??

I’ve not seen this error before. Is it due to a TimeZone that makes DateTime.MaxValue overflow?

i.e. does this throw when you use DateTime.MaxValue.AddDays(-1)? What about if you comment out Expiry?

I will test this as well later.

The really strange thing is: I run the code in RELEASE mode and everything works just great and ultra fast as always!!

Don’t know what tons of checks are done in DEBUG mode, maybe also a problem to the JetBrains IDE.

I have downgraded to .NETCore 2.1. but the same problem.

Really strange, I think there is a memory corruption problem somewhere… If I set DateTime.MaxValue.AddDays(-1) in DEBUG mode, it crashes with a completely unrelated error:

System.Exception: Registering IAuthEvents via both AuthFeature.AuthEvents and IOC is not allowed
  at ServiceStack.AuthFeature.AfterPluginsLoaded(IAppHost appHost) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\AuthFeature.cs:235
  at ServiceStack.ServiceStackHost.AfterPluginsLoaded(String specifiedContentType) in C:\BuildAgent\work\3481147c480f4a2f\src\ServiceStack\ServiceStackHost.cs:854

This is an unrelated Startup configuration error which suggests that you’re trying to register AuthEvents in both the IOC and AuthFeature plugin which isn’t allowed.

Very interesting! The last exception seems to be correct, I have enabled the AuthFeature plugin and I found a line of code that explains the exception:

container.RegisterAs<TrackAuthEvents, IAuthEvents>();

And SECOND interesting thing: YES looks like it is a DateTime.MaxValue overflow! If I comment the above line and use DateTime.MaxValue.AddDays(-1) it does NOT throw that first exception!

My timezone is GMT +1

Demis, I use EPOC (which is UnixTime) for all DateTime props in my RabbitMQ messages. Here is some code I use to convert. I must say that my data store is MongoDB which stores all dates automatically in UTC. You can configure the MongoDB driver to automatically convert to local time. The following is an extract from a conversion routine where I convert a ‘Business Object’ to a ‘Message DTO’. The extensive logging shows that I was fiddling around with this quite a bit, since I exchange the data through RabbitMQ with external accounting systems…

I always convert first to local time and thne convert to Unix time. I did never test the edge cases (DateTime.MinValue and DateTime.MaxValue) but this code is running for many months now and did never cause any problems…

public InvoiceMsgDto ToInvoiceMsgDto()
	Logger.Debug($"InvoiceDate: {InvoiceDate:F}, Due date: {InvoiceDueDate:F}");
	var invoiceDate = InvoiceDate.ToLocalTime();	
	var dueDate = InvoiceDueDate.ToLocalTime();	      
	Logger.Debug($"Converted to local dates: InvoiceDate: {invoiceDate:F}, Due date: {dueDate:F}");
	Logger.Debug($"InvoiceDate Epoc Ms: {new DateTimeOffset(invoiceDate).ToUnixTimeMilliseconds().ToString()},  " +
				 $"DueDate Epoc Ms: {new DateTimeOffset(dueDate).ToUnixTimeMilliseconds().ToString()}");
	var invoiceMsgDto = new InvoiceMsgDto
		InvoiceDate = new DateTimeOffset(invoiceDate).ToUnixTimeMilliseconds(),
		InvoiceDueDate = new DateTimeOffset(dueDate).ToUnixTimeMilliseconds(),
		CustomerNumber = InvoiceCustomer.CustomerNumber,
		PaymentTermCode = PaymentTermCode,
		InvoiceNumber = InvoiceNumber,
		InvoiceTotal = InvoiceTotal,
		PayMethodName = PayMethodName,
		InvoiceText = InvoiceText,
		PayslipCode = PayslipCode,
		InvoicePositions = new InvoicePositionMsgDto[InvoicePositions.Count + 1], //we add the debitoren sammelkonto posting here as well