Need to process a dataset via dynamic runtime code in C#

142 views Asked by At

I have been working with C# dynamic code for run time processes. My problem is I cannot seem to pass a dataset object to the dynamic code with out getting:

"Could not load file or assembly 'file:///C:\Users\mgallanx\AppData\Local\Temp\npbylo5z.dll' or one of its dependencies. The system cannot find the file specified."

Here is the simplest dataset processing string I am using:

mycodestring = "using System; 
    using System.Data; 
    namespace DaCodeNS 
     { 
       public static class DaCode 
        { 
          public static DataSet DaMethod( Dataset dsIn) 
          { 
            return dsIn; 
          }
        }
      }"

the calling method sets the parameters to add the System.dll and System.Data.dll, creates an Object[] mp to one element of sIn.

The call then is:

CompilerResults results = provider.CompileAssemblyFromSource (parameters, mycodestring);
var cls = results.CompiledAssembly.GetType ("DaCodeNS.DaCode");
var method = cls.GetMethod ("DaMethod", BindingFlags.Static | BindingFlags.Public);
return (DataSet)  method.Invoke (null, mp);

It breaks at the GetMethod line. I can get similar code passing integers around to play, but changing the return and passed to DataSet blows up. Any help is appreciated.

1

There are 1 answers

4
Paul Mrozowski On

You're most likely not including all of the references needed to make your dynamic code compile/run. A simple way to find all the needed references would be to create a standa-alone project that just includes the code you're going to compile. Then look at the references you needed to add to the project to get it to compile/run.