compiling from code

  • Thread starter Thread starter ultim
  • Start date Start date
U

ultim

Hi!
I need to compile a piece of code from my application, so
i used the Microsoft.CSharp.Compiler class. However, at
the Compiler.Compile() Method i get the following
exception:

'System.Runtime.InteropServices.COMException' occurred in
cscompmgd.dll
Additional information: Cannot change thread mode after it
is set.

The code that produced this error is as follows:

string[] src = new string[1];
src[0] = str;

string[] nms = new string[1];
nms[0] = "clsRajzolo.cls";

string[] imps = new string[3];
imps[0] = "System.dll";
imps[1] = "System.Drawing.dll";
imps[2] = "System.Windows.Forms.dll";

Hashtable ht = new Hashtable();
ht.Add("target","library");

CompilerError[] ce = Compiler.Compile
(src,nms,"C:\testrajz.dll",imps,ht);
 
Hi,
Do u have all the windows updates in u'r computer?? If not
then please do that because most of the COMException
occurs due to this.
Shrawan
 
Hello,

Instead of using the single-threaded process model use the multithreaded
apartment model.

using System;
using System.Collections;
using Microsoft.CSharp;

namespace CompileTest
{
class Class1
{
[MTAThread]
static void Main(string[] args)
{
string[] src = new string[1];
src[0] = "// dummy";

string[] nms = new string[1];
nms[0] = "clsRajzolo.cls";

string[] imps = new string[3];
imps[0] = "System.dll";
imps[1] = "System.Drawing.dll";
imps[2] = "System.Windows.Forms.dll";

Hashtable ht = new Hashtable();
ht.Add("target","library");

CompilerError[] ce =
Compiler.Compile(src,nms,"C:\\testrajz.dll",imps,ht);
}
}
}

Gabriele
 
Back
Top