2

I started using CodeFluentRuntimeClient to replace Interop.MSScriptControl.dll.

I succeed here by tweeking a bit the dll to make it work.

We started using the dll in production. On one of the machines that we installed on it (windows server 2012), we are having a Sytem.AccessViolationException.

Here's the stack trace of the event viewer:

enter image description here

enter image description here

Do CodeFluent requieres any other dlls?

EDIT

Here's the code:

public dynamic EvaluateVBScript(string token, string key, string script, IDictionary<string, object> parameterValuePair = null)
{
    try
    {
        using (ScriptEngine engine = new ScriptEngine(ScriptEngine.VBScriptLanguage))
        {
            List<object> parameters = new List<object>() { string.IsNullOrEmpty(token) ? string.Empty : ServiceManager.GetService<IServiceInstance>().GetService<IContextManager>(token).UserName };
            string extraParameters = string.Empty;
            if (parameterValuePair != null && parameterValuePair.Count > 0)
            {
                extraParameters = "," + string.Join(",", parameterValuePair.Select(e => e.Key));
                foreach (var para in parameterValuePair)
                    parameters.Add(para.Value);
            }
            string parsedScript = string.Format(@"Function {0}(NecUserProfile {2})
            {1}
            End Function", key, script, extraParameters);
            ParsedScript parsed = engine.Parse(parsedScript);

            dynamic value = parsed.CallMethod(key, parameters.ToArray());
            return (value != null) ? value.ToString() : string.Empty;
        }
    }
    catch
    {
        throw;
    }
}
Community
  • 1
  • 1
billybob
  • 2,859
  • 6
  • 35
  • 55
  • Can you post the code you use to parse and execute the script? – meziantou Dec 12 '16 at 16:49
  • I posted the code. BTW, this code works on a lot of machines. It breaks only on one machine. – billybob Dec 12 '16 at 16:56
  • The code in the runtime is essentially the same as what you can find here: http://stackoverflow.com/questions/4744105/parse-and-execute-js-by-c-sharp/24868314 can you try to use this code and see if it fails the same? If it does, can you try it with MarshalAs(UnmanagedType.LPWStr)] added around string parameters in ParseText, like in there: https://github.com/Taritsyn/MsieJavaScriptEngine/blob/master/src/MsieJavaScriptEngine/ActiveScript/IActiveScriptParse64.cs – Simon Mourier Dec 13 '16 at 06:59
  • I will give it a try today and come back with a feedback. And btw do you want me to drop the CodeFluent.Runtime.Client.dll and go directly with the code that you provided me? – billybob Dec 13 '16 at 14:51

1 Answers1

0

After some tests, we found out that the client had an antivirus (Kaspersky) installed on his server. Even after disabling the antivirus, the access violation error was still occurring.

After uninstalling the antivirus, we were finally able to execute the JavaScript. We still don't know what rule was set in the antivirus that was blocking the script to be parsed.

I didn't test in the suggested solution by Simon Mounier. I don't know if it would have solved the problem.

The solution was to drop out the CodeFluent.Runtime.Client.dll and use directly the source code provided here. Also add MarshalAs(UnmanagedType.LPWStr)] around the string parameters that are going to be used by the parse function, like in here.

Community
  • 1
  • 1
billybob
  • 2,859
  • 6
  • 35
  • 55