I have some code like this:
var jsonSerializer = new JsonSerializer();
var json = @"{ ""LastModifiedTime"": ""2013-04-19T18:18:09+03:00"" }";
var result = jsonSerializer.Deserialize<dynamic>(new JsonTextReader(new StringReader(json)));
File.SetLastWriteTime("c:/temp/somefile.txt", result.LastModifiedTime);
However, this gives me (at run time since we are speaking about dynamic here):
RuntimeBinderException
The best overloaded method match for 'System.IO.File.SetLastWriteTime(string, System.DateTime)' has some invalid arguments
This feels a bit silly. To me, a bit of the point of dynamic is to not have to explicitly specify types and so forth; this should (ideally) be handled by the runtime. Of course, it may be a bit hard for JSON.NET to know what it should masquerade as in a given situation...
James (or anyone else familiar with the JSON.NET internals), is this by design? If I add a manual DateTime cast like this:
File.SetLastWriteTime("c:/temp/somefile.txt", (DateTime) result.LastModifiedTime);
...all works fine.