lundi 30 janvier 2017

Creating a method at runtime and System.IO Exception

Hello I have been trying to figure this out for a while now and cannot get it correct. I have found a few threads that do similar to what I want to do. but I keep getting a system.Io Assembly cannot be found compile and run the string that was created.

    private bool CalculateBooleanExpression(string expression)
    {
        var classExpression = stringClass.Replace(ReplaceMe,expression);

        var complierParameters = new CompilerParameters()
        {
            GenerateExecutable=false,
            GenerateInMemory = true
        };
        var complier = new CSharpCodeProvider();

        var compilerResults = complier.CompileAssemblyFromSource(complierParameters, classExpression);

//break point here compilerResults.CompiledAssembly is null
        object typeInstance = compilerResults.CompiledAssembly.CreateInstance("BooleanEvaluator");

        MethodInfo methodInfo = typeInstance.GetType().GetMethod("Calculate");

        bool value = (bool)methodInfo.Invoke(typeInstance, new object[] { });

        return true;
    }

Could not load file or assembly 'http://file/C:\Users\james.tays\AppData\Local\Temp\22ozhhme.dll' or one of its dependencies. The system cannot find the file specified.

can anyone tell me how to debug this so i can figure out where there error is?





Aucun commentaire:

Enregistrer un commentaire