Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CodeDOMProvider error when call from two place
Message
From
27/03/2009 04:29:49
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01391789
Message ID:
01391794
Views:
42
Viv,

(Quick scan of the code)

I think the static method can stay, but not the static properties. They should be declared in the static method

Otherwise, a locking mechanism (lock(...) { })
private static object _evaluator = null;
private static Type _evaluatorType = null;

>Hi,
>
>Try using instance rather than static methods.
>
>
>>Hi,
>>We have an evaluator class that is using CodeDOMProvider (JScript) to evaluate expression in our application. We faced problem that, if two user access to same screen which call the evaluator will hit error. It is working fine if only one user access to the screen. Any ideas?
>>
>>
>>using System;
>>using System.Collections.Generic;
>>using System.Text;
>>using System.Reflection;
>>using System.CodeDom;
>>using System.CodeDom.Compiler;
>>using Microsoft.JScript;
>>
>>namespace Vfs.Generic.Dynamic.Expression
>>{
>>    public class Evaluator
>>    {
>>        private static object _evaluator = null;
>>        private static Type _evaluatorType = null;
>>        private static readonly string _jscriptSource = @"
>>                                                        package Evaluator
>>                                                        {
>>                                                            class Evaluator
>>                                                            {
>>                                                                public function Eval(expr : String) : String
>>                                                                {
>>                                                                    return eval(expr,""unsafe"");
>>                                                                }
>>                                                            }
>>                                                        }
>>                                                        ";
>>
>>        static Evaluator()
>>        {
>>            CodeDomProvider provider = CodeDomProvider.CreateProvider("JScript");
>>
>>            CompilerParameters parameters = new CompilerParameters();
>>            parameters.GenerateInMemory = true;
>>
>>            CompilerResults results = provider.CompileAssemblyFromSource(parameters, _jscriptSource);
>>
>>            Assembly assembly = results.CompiledAssembly;
>>            _evaluatorType = assembly.GetType("Evaluator.Evaluator");
>>
>>            _evaluator = Activator.CreateInstance(_evaluatorType);
>>        }
>>
>>        public static object EvalToObject(string expression)
>>        {
>>            object result;
>>
>>            try
>>            {
>>                result = _evaluatorType.InvokeMember(
>>                    "Eval",
>>                    BindingFlags.InvokeMethod,
>>                    null,
>>                    _evaluator,
>>                    new object[] { expression }
>>                    );
>>            }
>>            catch (Exception ex)
>>            {
>>                throw new Exception(string.Format("Evaluator: Failed to evaluate expression {0} - {1}", expression, ex.Message));
>>            }
>>
>>            return result;
>>        }
>>
>>        public static string Eval(string expression)
>>        {
>>            object o = EvalToObject(expression);
>>            return o.ToString();
>>        }
>>    }
>>}
>>
>>
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform