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

Closed Unassigned: Exception when calling ToString() on Primitive Object [87]

0
0
I am trying to call ToString() on an int object and I am getting the following exception

An unhandled exception of type 'Microsoft.ClearScript.ScriptEngineException' occurred in ClearScriptV8-32.dll

Additional information: TypeError: obj.IntTest.ToString is not a function.

Below is a snippet of code which is causing the issue.

__DataObject.cs__

```
using System;
using System.Collections.Generic;

namespace T4EditorTest
{
public class DataObject
{
public DataObject()
{
Children = new List<SubDataObject>();
}

public Guid Id { get; set; }

public string SystemName { get; set; }

public string DisplayName { get; set; }

public string Description { get; set; }

public Char CharTest { get; set; }

public int IntTest { get; set; }

public List<SubDataObject> Children { get; set; }

public string IntTestToString()
{
return IntTest.ToString();
}
}

public class SubDataObject
{
public DataObject Parent { get; set; }

public Guid Id { get; set; }

public string SystemName { get; set; }

public string DisplayName { get; set; }

public string Description { get; set; }
}
}
```
__Calling Code__
```
private static void TestScriptEngine()
{
using (var engine = new V8ScriptEngine())
{
engine.AddHostType(typeof(DataObject));
engine.AddHostType("Console", typeof(Console));

const string script = @"
var obj = new DataObject();
obj.DisplayName = 'Hello, Script Engine.';
Console.WriteLine(obj.DisplayName);
//obj.CharTest = '1';
obj.IntTest = 5;
obj.SystemName = obj.IntTest.ToString();
Console.WriteLine(obj.IntTest);";

engine.Execute(script);

var obj = engine.Script["obj"] as DataObject;
}
}
```

Viewing all articles
Browse latest Browse all 2297