Our project should have simple business rules that our clients can script in Visual Basic. Although our main program is written in C #
the script that clients want to execute may be like this (I am considering the simplest case)
var vbCode = @" If (Row.Code = 12) Then Row.MappedCode = 1 End If";
So, I created a RowData class in C # with the Code and MappedCode properties
namespace ScriptModel { public class RowData { public int Code { get; set; } public int MappedCode { get; set; } } }
I created a simple class of class objects, for example
namespace ScriptModel { public class HostObjectModel { public RowData Row { get; set; } } }
Using Roslyn.Scripting.VisualBasic.ScriptEngine I create an engine, create a session with an instance of HostObjectModel and execute engine.Execute (vbCode, session)
var hostObj = new HostObjectModel(); hostObj.Row = new RowData(); hostObj.Row.Code = 12; var engine = new Roslyn.Scripting.VisualBasic.ScriptEngine( new Assembly[] {hostObj.GetType().Assembly}, new string[] {"ScriptModel"} ); var session = Session.Create(hostObj); engine.Execute(vbCode , session);
And he tells me that
(2.25): error BC30451: "String" was not declared. This may not be available due to its level of protection.
But if I create a similar code snippet in C #
var csharpCode = @" if (Row.Code == 12) { Row.MappedCode = 1; };";
and use CSharp.ScriptEngine, everything will work correctly
So what is the problem, why was VisualBasic.ScriptEngine unable to see the public properties of the class that was compiled in C #, should it be, I think, in the same MSIL language, or am I mistaken?
Update: I installed Visual Basic and created the ScriptModel library on VB. I also replaced the Row property with the Row () function in both the class declaration and vbCode. Nothing helped. :( it seems that VisualBasic.ScriptEngine doesn't work at all when I run it from C #.