Bug 13684 - When setting OutputAssembly on CompilerParameters, failing to end the string with ".dll" results in exception
Summary: When setting OutputAssembly on CompilerParameters, failing to end the string ...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: 2.10.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2013-08-01 12:46 UTC by Eric Lawrence
Modified: 2013-08-07 15:57 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Eric Lawrence 2013-08-01 12:46:52 UTC
http://www.opensubscriber.com/message/mono-list@lists.ximian.com/9989225.html

If you set the CompilerParameter's OutputAssembly="SomeNameWithoutDLL" you hit the exception:

---------------------------
Compiler error
---------------------------
  at System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule (System.String name, System.String fileName, Boolean emitSymbolInfo, Boolean transient) [0x00000] in <filename unknown>:0 
---------------------------
OK   
---------------------------

On the other hand, if you use OutputAssembly="SomeNameWithDLL.dll" the DLL works fine.


using System;
using Microsoft.CSharp;
using System.CodeDom.Compiler;
using System.Reflection;
using System.Windows.Forms;

namespace Fiddler
{
    public class CSharpScript
    {

        public CSharpScript()
        {
            try
            {
                var oCSC = new CSharpCodeProvider();
                if (null == oCSC) MessageBox.Show("Can't get compiler...");
                CompilerParameters cp = new CompilerParameters();
                cp.GenerateExecutable = false;
                cp.GenerateInMemory = true;
                cp.OutputAssembly = "FiddlerCSharpScript.dll";  // <---- ERROR LINE
                cp.ReferencedAssemblies.Add("Fiddler.exe");
                string sSource = "using System;\nusing Fiddler;\npublic static class Handlers {\npublic static void Main() { FiddlerApplication.Log.LogString(\"Hello World.\" + Environment.StackTrace); } }";
                MessageBox.Show(sSource, "Source");
                CompilerResults oCR = oCSC.CompileAssemblyFromSource(cp, sSource);

                if (oCR.Errors.Count > 0)
                {
                    MessageBox.Show(oCR.Errors[0].ErrorText, "Compiler error"); 
                    return;
                }
               if (oCR == null) MessageBox.Show("Failed compile");
                Type T = oCR.CompiledAssembly.GetType("Handlers");
                if (null == T) MessageBox.Show("Couldn't find main type...");
               MethodInfo methodinfo = T.GetMethod("Main");
                if (methodinfo == null) MessageBox.Show("Failed to find mehtod");

                methodinfo.Invoke(null, null);
            } 
            catch (Exception eX)
            {
                MessageBox.Show(Utilities.DescribeException(eX) + eX.StackTrace, "Failed to compile");
            }
        }
    }
}
Comment 1 Marek Safar 2013-08-07 15:57:35 UTC
I cannot reproduce the issue with Mono 3.2