1

I need to create some Dll files at runtime. The Dll's are getting generated, but it seems that the mvc application freezes AFTER this code is executed. In the output window, I can see that all my Dll's are getting unloaded and after that they all get loaded. What am I doing wrong?

My code:

using (CSharpCodeProvider codeProvider = new CSharpCodeProvider())
        {
            CompilerParameters parameters = new CompilerParameters
            {
                ReferencedAssemblies =
                {
                    string.Format("{0}\\{1}", binDirectory, "SomeDll.dll")
                },
                GenerateExecutable = false,
                OutputAssembly = string.Format("{0}\\{1}", binDirectory, assemblyName)
            };

            var files = Directory.GetFiles(dataDirectory, "*.cs"); //get all generated cs files 

            var result = codeProvider.CompileAssemblyFromFile(parameters, files); //this line causes the application to freeze

            codeProvider.Dispose(); //not sure if this is necessary

            if (result.Errors.HasErrors)
            {
                throw new Exception(result.Errors.ToString());
            }
        }

My output:

'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/2/ROOT-1-131239474882606992): Unloaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'

'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/2/ROOT-1-131239474882606992): Unloaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'

'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/2/ROOT-1-131239474882606992): Unloaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'

(etc)

'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/2/ROOT-2-131239476152101487): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Web\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Web.dll'. Skipped loading symbols.Module is optimized and the debugger option 'Just My Code' is enabled.

'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/2/ROOT-2-131239476152101487): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. Skipped loading symbols.Module is optimized and the debugger option 'Just My Code' is enabled.

'iisexpress.exe' (CLR v4.0.30319: /LM/W3SVC/2/ROOT-2-131239476152101487): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. Skipped loading symbols.Module is optimized and the debugger option 'Just My Code' is enabled.

(etc)

Camilo Terevinto
  • 31,141
  • 6
  • 88
  • 120
Herole
  • 11
  • 2

0 Answers0