views:

200

answers:

3

I have a Visual Studio 2008 solution that when I build, returns the following error:

Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.  Parameter name: ticks

There is no reference file/line/column in the error. Becoming quite frustrating as the solution builds in the end, however I cannot debug.

In the solution, there is no reference/using to DateTime.MinValue.Ticks at all...

EDIT:

There are only 2 references to ticks in my solution, and neither of those are causing the issue.

There are no constructor issues with DateTime either. I do not believe it is related to DateTime or ticks at all.

I have found a similar reference where it turned out to be a corrupt image file in the solution, where it did not have a date-modified value. This is not affecting mine though.

+1  A: 

It sounds like you're not initialising ticks.

In that case there won't be a reference to DateTime.MinValue.Ticks.

You'll have to search for ticks and double check all occurrences.

ChrisF
+4  A: 

The error message comes from the DateTime constructor that takes a long value.

Somewhere in your code you are creating a DateTime value from a constant value, so that the actual creation is done at compile time rather than runtime. That value is out of range for the constructor.

Code like this gives the same exception:

public static DateTime startTime = new DateTime(-1);

However, the exception happens at run time. To get it at compile time there is probably something in your markup code, like an argument value in a server control.

Guffa
There is no reference anywhere for this in my code.
mickyjtwin
@mickyjtwin: Don't search for `ticks`, search for `new DateTime` or `DateTime.FromXYZ` and specifically instances of these that don't validate the input.
Aaronaught
@mickyjtwin: It's hard to look for, as there is probably no specific reference either to a ticks property or a DateTime constructor. It can be any attribute with a DateTime type, for example a DateTimePicker control with `Value="-1"`. This would cause a call to the DateTime constructor to create a DateTime value from the attribute.
Guffa
A: 

I don't know if you have ever solved this but I have found that it has occurred due to glitches in the meta data for images.

It has happened in two different projects, created by two different systems, but the culprit has been missing file modified data for images.

I have written a post about this:

http://runtingsproper.blogspot.com/2010/03/solved-error-1-ticks-must-be-between.html

But the basic crux is of the article is to do the following:

  1. Switch to the Output tab and see what the last folder was which was compiled before it borked.
  2. Delete that folder.
  3. Recompile
  4. Keep repeating steps 1 to 3 until the site compiles
  5. When it compiles start bringing back individual files in the last batch you deleted until you find the offending file
rtpHarry