1

I am trying to compile code with codeDom with this function:

   public static bool Compile(string Output, string Source, string Icon, string resources)
   {
      CompilerParameters Parameters = new CompilerParameters();
      CompilerResults cresults = default(CompilerResults);
      Dictionary<string, string> providerOptions = new Dictionary<string, string>();
      providerOptions.Add("CompilerVersion", "v2.0");
      CSharpCodeProvider Compiler = new CSharpCodeProvider(providerOptions);
      Parameters.GenerateExecutable = true;
      Parameters.TreatWarningsAsErrors = false;
      Parameters.OutputAssembly = Output;
      Parameters.EmbeddedResources.Add("System");

      Parameters.CompilerOptions = "/target:winexe /platform:x86";
      if (!string.IsNullOrEmpty(Icon))
      {
         Parameters.CompilerOptions += " /win32icon" + Icon;
      }
      cresults = Compiler.CompileAssemblyFromSource(Parameters, Source);

      if (cresults.Errors.Count > 0)
      {
         foreach (CompilerError compile_error in cresults.Errors)
         {
            CompilerError error = compile_error;
            MessageBox.Show(error + "");
         }
         return false;
      }
      return true;
   }

source has these libarys (not sure if it's libarys I'm rather a java develloper):

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml;
using System.Data.SQLite;
using System.Data;
using System.Text;
using System.Collections.Specialized;
using System.Net;
using Dns = System.Net.Dns;
using AddressFamily = System.Net.Sockets.AddressFamily;
using System.Reflection;
using System.Diagnostics;
using System.Runtime.InteropServices;
using Microsoft.Win32;
using System.ComponentModel;
using System.IO;
using System.Security.Cryptography;

But when I compile I get these errors:

c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(3,14) : error CS0234: The type or namespace name 'Windows' does not exist in the namespace 'System' (are you missing an assembly reference?)
c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(4,14) : error CS0234: The type or namespace name 'Xml' does not exist in the namespace 'System' (are you missing an assembly reference?)
c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(5,14) : error CS0234: The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)
c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(6,14) : error CS0234: The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)
c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(8,26) : error CS0234: The type or namespace name 'Specialized' does not exist in the namespace 'System.Collections' (are you missing an assembly reference?)
c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(9,14) : error CS0234: The type or namespace name 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?)
c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(16,14) : error CS0234: The type or namespace name 'ComponentModel' does not exist in the namespace 'System' (are you missing an assembly reference?)
c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(10,20) : error CS0234: The type or namespace name 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?)
c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(11,30) : error CS0234: The type or namespace name 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?)
c:\Users\Augustin\AppData\Local\Temp\odq0sdk5.0.cs(60,14) : error CS0246: The type or namespace name 'DataTable' could not be found (are you missing a using directive or an assembly reference?)

How can I solve these errors?

1 Answer 1

2

The problem that you didn't add referenced assemblies. All these errors are related to another assembly that should be added:

Parameters.ReferencedAssemblies.Add("System.dll"); // System, System.Net, etc namespaces
Parameters.ReferencedAssemblies.Add("System.Data.dll"); // System.Data namespace
Parameters.ReferencedAssemblies.Add("System.Data.SQLite.dll"); // System.Data.SqlLite namespace
Parameters.ReferencedAssemblies.Add("System.Xml.dll"); // System.Xml namespace
Parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll"); // System.Windows.Forms namespace

If your code uses these namespaces, then all appropriate assemblies should be added to ReferencedAssemblies collection

PS. I don't know what is correct assembly name for SQLite assembly, as I guess it's System.Data.SQLite.dll, but I can be wrong

Sign up to request clarification or add additional context in comments.

6 Comments

error CS0006: Metadata file 'System.Net.dll' could not be found
yep. I've mistaken. It should be just System.dll. I've updated answer
What dll should I use for System.Resources?
Based on that article - msdn.microsoft.com/library/… it's in mscorlib.dll, but I suppose it should be linked automatically
error CS0246: The type or namespace name 'Recource' could not be found (are you missing a using directive or an assembly reference?)
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.