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: Hello! This is currently by design. That is, ClearScript's script object proxies implement a [system interface](https://msdn.microsoft.com/en-us/library/system.reflection.ireflect(v=vs.110).aspx) that includes [`UnderlyingSystemType`](https://msdn.microsoft.com/en-us/library/system.reflection.ireflect.underlyingsystemtype(v=vs.110).aspx), but their implementation of that property is just an exception-throwing stub. That's because the property doesn't appear to be useful or even appropriate for objects that don't represent types. Why are you invoking this property? What do you expect it to return? Perhaps more to the point, what would you like to do on the .NET side with a JavaScript `Date` object? Thanks!

Viewing all articles
Browse latest Browse all 2297