Home > Enterprise >  Get type or namespace not found CodeDom
Get type or namespace not found CodeDom

Time:07-11

I'v been facing this problem for hours now.

I'm playing a little bit with codedom but i get : a type or namespace Threading not found.

My compilator code is this one:

using Microsoft.CSharp;
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CodeDom
{
    public class Compiler
    {
   
        public Compiler(string sourceCode, string savePath)
        {
          
            string[] referencedAssemblies = new string[] { "System.dll", "System.Windows.Forms.dll", "System.Threading.Thread.dll" };

            Dictionary<string, string> providerOptions = new Dictionary<string, string>() { { "CompilerVersion", "v4.0" } };

           
            string compilerOptions = "/target:winexe /platform:anycpu /optimize ";

            using (CSharpCodeProvider cSharpCodeProvider = new CSharpCodeProvider(providerOptions))
            {
               
                CompilerParameters compilerParameters = new CompilerParameters(referencedAssemblies)
                {
                    GenerateExecutable = true,
                    GenerateInMemory = false,
                    OutputAssembly = savePath, 
                    CompilerOptions = compilerOptions,
                    TreatWarningsAsErrors = false,
                    IncludeDebugInformation = false,
                };

                CompilerResults compilerResults = cSharpCodeProvider.CompileAssemblyFromSource(compilerParameters,sourceCode); // source.cs
                if (compilerResults.Errors.Count > 0)
                {
                    foreach (CompilerError compilerError in compilerResults.Errors)
                    {
                        MessageBox.Show(string.Format("{0}\nLine: {1} - Column: {2}\nFile: {3}", compilerError.ErrorText,
                            compilerError.Line, compilerError.Column, compilerError.FileName));
                    }
                    return;
                }
                else
                {
                    MessageBox.Show("Compiled!");
                }
            }
        }
    }
}

I dont understand , I've referenced correctly the dll System.Threading.Thread.dll but it still don't find it.

CodePudding user response:

Can you try System.Threading.dll it should be without Thread in the name.

CodePudding user response:

I used your two solutions and i still get this error.

string[] referencedAssemblies = new string[] { "System.dll", "System.Windows.Forms.dll", "mscorlib.dll" , "System.Threading.dll" };
  • Related