I have a 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 runtime, since we are talking about dynamics here):
RuntimeBinderException The best overloaded method match for 'System.IO.File.SetLastWriteTime(string, System.DateTime)' has some invalid arguments
This is a little stupid. For me, a bit of a dynamic point, there is no need to explicitly specify types, etc .; this should (ideally) be handled by runtime. Of course, for JSON.NET it can be a little difficult to find out what it should mask, as in this situation ...
James (or someone else familiar with internal JSON.NET), is this by design? If I add a manual DateTime statement as follows:
File.SetLastWriteTime("c:/temp/somefile.txt", (DateTime) result.LastModifiedTime);
... everything is working fine.
source share