Search code examples
c#access-violationcodefluent

CodeFluent.RunTime.Client.dll - AccessViolationException


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;
    }
}

Solution

  • 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.