Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
CodeDOMProvider error when call from two place
Message
De
27/03/2009 04:29:49
 
 
À
27/03/2009 03:48:43
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01391789
Message ID:
01391794
Vues:
43
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform