Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7493669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:06:46+00:00 2026-05-29T17:06:46+00:00

I have been trying to get CodeDom to work so I can dynamically create

  • 0

I have been trying to get CodeDom to work so I can dynamically create code for my application during runtime. However, after many tutorials and trial and error, I have come into a problem I can’t seem to pass. I keep getting compiler errors on code that looks exactly like it should. I get “Unrecognized escape sequence ‘\'” when there is no ‘\’ anywhere in my code.

The errors I get are all on line 1. Here they are in order:
CS1009
CS1056 (3 times in a row)
CS0116

Here is what I have:

The code being compiled:

using System;
using System.Windows.Forms;
namespace sdjkfhj 
{    
    public class Sample 
    {
        public static void main()
        {
            MessageBox.Show("Working");
            return;
        }
    }
}

And the compiler code is as follows:

public void Compile(string file)
    {
        var prov = new Dictionary<string, string>();
        prov.Add("CompilerVersion", "v2.0");
        CSharpCodeProvider c = new CSharpCodeProvider();
        ICodeCompiler comp = c.CreateCompiler();

        CompilerParameters param = new CompilerParameters();
        param.GenerateExecutable = true;
        param.OutputAssembly = file + ".exe";
        param.ReferencedAssemblies.Add("System.dll");
        param.ReferencedAssemblies.Add("System.Windows.Forms.dll");
        if (c.Supports(GeneratorSupport.EntryPointMethod))
            param.MainClass = "Sample";

        CompilerResults results = comp.CompileAssemblyFromSource(param, file);

        if (results.Errors.Count > 0)
        {
            foreach (CompilerError CompErr in results.Errors)
            {
                MessageBox.Show("Line number " + CompErr.Line + ", Error Number: " + CompErr.ErrorNumber + ", '" + CompErr.ErrorText + ";" + Environment.NewLine + Environment.NewLine);
            }
        }
    }

Is there something I’m not doing to compile it right? Are there things I’m missing? I’m kind of lost here. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:06:47+00:00Added an answer on May 29, 2026 at 5:06 pm

    Three things come to mind right away:

    1. There are no semicolons in the code you’re attempting to compile.
    2. If Main is supposed to be your entry point, make it static.
    3. Make your source file different than your target file (something like param.OutputAssembly = file + ".exe";

    Fixing these is really only the first step, you’ll also have to configure the assemblies that your output will need to reference, and it wouldn’t be a bad idea to set MainClass on the CompilerParameters you’re using either.

    A nice example on MSDN

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to get this to work and can't. I have a
I have been trying to get this code to work for a while now
I have been trying to get it to work using this thread but can't
I have been trying to get a spring MVC test application to work. Here
I have been trying to get nServiceBus to work with Ninject 2.0 as the
I have been trying to days now to get this website completed ... however,
I have been trying to get this to work for 12 hrs now and
I have been trying to get a2billing to work for the past 4 days
I have been trying to get the following code working. It's a progress bar
I have been trying to get this query to work but I am stumbed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.