System.ArgumentOutOfRangeException:
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'
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.
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:
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!
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
};
.....
}