Quantcast
Channel: ClearScript
Viewing all articles
Browse latest Browse all 2297

Commented Unassigned: Exception when creating Dates in V8ScriptEngine [113]

0
0
Hello,

I'm trying to create/parse date from a JS evaluate and return them as strings back into c# code as such:

```
using (var engine = new V8ScriptEngine())
{
resultEval = engine.Evaluate(expression);
}
```

where my `expression` is

`new Date()`

and it return an "Microsoft.ClearScript.V8.V8ScriptItem" object with an "UnderlyingSystemType" saying:

'((Microsoft.ClearScript.ScriptItem)resultEval).UnderlyingSystemType' threw an exception of type 'System.NotImplementedException'

Now, I feel like this *should* work, but it's not. Any ideas? I don't think anything went wrong during the build/reference process. Other JS libraries such as Math work flawlessly.

Also, this is only an issue when trying to create a `new` date. Calling `Date()` works, but it only displays today's date.
Comments: Also, I'll explain the full use-case. 1. We have a .NET DateTime object we want to expose to the user. To do this, we expose a macro to the user that we then convert into a JS Date object as such: `new Date(" + dateTimeValue.Year.ToString() + "," + dateTimeValue.Month.ToString() + "," + dateTimeValue.Day.ToString() + "," + dateTimeValue.Hour.ToString() + "," + dateTimeValue.Minute.ToString() + "," + dateTimeValue.Second.ToString() + "," + dateTimeValue.Millisecond + ")";` 2. We want the user to be able to manipulate the date in JS 3. We want the user to be able to return the manipulated date (or a new date) back into .NET At this point, is the best solution to use JS `.toString` and then DateTime.TryParse? because we also want to support user returning strings and numeric datatypes. Thanks!

Viewing all articles
Browse latest Browse all 2297




Latest Images