0

I am experimenting with creating a CryptoKey in .Net and would like to know the source of the following exception:

Exception has been thrown by the target of an invocation. The argument has an unexpected value. Parameter name: expiresUtc

DotNetOpenAuth Version is 4.3.0.0, Runtime Version is 4.0.20926.

I'm passing a byte array and a System.DateTime (set to Utc) to the CryptoKey constructor but keep getting this message. Is it something thrown by the DNOA code? If so, what might be wrong with the System.DateTime? If not then I know it's a problem with my coding environment and I'll have an idea where to look.

BTW, if the code for this constructor is available then I'd be happy to inspect it to answer my question, Thanks in advance for any pointers.

Norman Kleinberg
  • 300
  • 1
  • 10

2 Answers2

1

You should to pass into constructor a parameter with Kind equal to DateTimeKind.Utc, see HostSample extension method:

internal static DateTime AsUtc(this DateTime value) 
{
    if (value.Kind == DateTimeKind.Unspecified) {
        return new DateTime(value.Ticks, DateTimeKind.Utc);
    }
    return value.ToUniversalTime();
}
0

I experienced that same error. What I did was converted the expiresUtc to a UTC date after retrieval from my data store. So something like this:

new CryptoKey(key.Secret, key.ExpiresUtc.ToUniversalTime())
Brandon O'Dell
  • 1,171
  • 1
  • 15
  • 22
  • Brandon: The problem in my case is that I'm using Alpha5 (why? well that's another story). It doesn't handle DateTimeKind, so the upper 2 bits can't be changed and always indicate, I believe, a Local DateTimeKind. I don't see them changing that any time soon and there's no way to get around it. So I've "given up" trying to get Alpha5 to handle .NET in any reasonable fashion. But thanks for posting and trying to help me out. – Norman Kleinberg May 23 '14 at 00:18