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 7086125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:30:39+00:00 2026-05-28T07:30:39+00:00

For testing I used a Console application with the following source code: public string

  • 0

For testing I used a Console application with the following source code:

    public string CODEInString = @"namespace MyNamespace.Generator
                                    {
                                        public class Calculator
                                        {
                                            public int Sum(int a, int b)
                                            {
                                                return a + b;
                                            }
                                        }
                                    }";

    public void Create()
    {
        var provider = new CSharpCodeProvider();
        var cp = new CompilerParameters
                     {
                         GenerateInMemory = false,
                         OutputAssembly = "AutoGen.dll"
                     };
        provider.CompileAssemblyFromSource(cp, CODEInString);
    }

With this code inside a console application I can make it work and the AutoGen.dll file is created, from that point I can invoque the calculator’s methods.

My problem happens when I do the same code but inside a MVC 3 application. I can catch the exception if I use the following variable.

var compileResult1 = provider.CompileAssemblyFromSource(cp, CODEInString);

‘compileResult1.CompiledAssembly’ threw an exception of type System.IO.FileNotFoundException’

I also tried to use Server.MapPath(“~/bin/”) to tell the output directory.

Someone could help me here?
Thank you

UPDATE 1
I gave folder’s permissions to the correct user in order to write, so that is not the problem.

  • 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-28T07:30:40+00:00Added an answer on May 28, 2026 at 7:30 am

    I also tried to use Server.MapPath(“~/bin/”) to tell the output directory.

    How exactly did you try that because the following works for me:

    var cp = new CompilerParameters
    {
        GenerateInMemory = false,
        OutputAssembly = Server.MapPath("~/bin/AutoGen.dll")
    };
    

    And here’s my full test code:

    public ActionResult Index()
    {
        var code = 
        @"
            namespace MyNamespace.Generator
            {
                public class Calculator
                {
                    public int Sum(int a, int b)
                    {
                        return a + b;
                    }
                }
            }
        ";
        var provider = new CSharpCodeProvider();
        var cp = new CompilerParameters
        {
            GenerateInMemory = false,
            OutputAssembly = Server.MapPath("~/bin/AutoGen.dll")
        };
        var cr = provider.CompileAssemblyFromSource(cp, code);
    
        var calcType = cr.CompiledAssembly.GetType("MyNamespace.Generator.Calculator");
        var calc = Activator.CreateInstance(calcType);
        var result = (int)calcType.InvokeMember("Sum", BindingFlags.InvokeMethod, null, calc, new object[] { 1, 2 });
    
        return Content("the result is " + result);
    }
    

    Just wanted to point out that before doing this I hope you are fully aware that by writing to the bin folder you are basically killing and unloading the AppDomain of your web application every time you run this code. So if you really want to execute some dynamic code you might consider compiling the assembly in-memory.

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

Sidebar

Related Questions

When I run a class with the following code: public static void main(String[] args)
I'm writing an open source application uses some Symfony components, and using Symfony Console
I am used to python-style REPL testing of code on a shell and I
I have the following code which is part of unit testing for serialization support
I have been doing some testing on the Random class and I have used
If not, is smoke testing still used?
Has anyone used Robotium or Calculon for testing Android apps? Are they useful? Any
I have used a bit of MS VS2008 integrated Unit Testing framework for writing
What best practices have you used in unit testing embedded software that are peculiar
The Dojo Toolkit used to come with a testing facility called Doh. It was

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.