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

  • Home
  • SEARCH
  • 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 119485
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:39:38+00:00 2026-05-11T03:39:38+00:00

The example program below compiles two in-memory assemblies. The first compilation works fine. The

  • 0

The example program below compiles two in-memory assemblies. The first compilation works fine. The second one fails because it needs access to a class from the first assembly and the type isn’t available.

Specifically: The ReferencedAssemblies member of the CompilerParameters class is a string collection and it is used to load the manifests of the assemblies to obtain their types. It appears the C# compiler gets types strictly from the manifest rather than by using reflection (possibly for performance reasons.) In any case, when an assembly is constructed in memory there is no file and no manifest so the second assembly build fails with an error like this:

COMPILER ERROR: Metadata file ‘ax5lw0tl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ could not be found

Adding an AssemblyResolver event handler doesn’t work. I tried this and it looks like it isn’t ever called. From what I can tell (and I’m a novice with .Net so bear with me) the compiler only cares about the manifest; it’s not actually trying to load the assembly at this time, so AssemblyResolver isn’t in the picture.

I could, if desperate, construct my assemblies on disk which would solve the immediate problem to have a physical dll and manifest to read. I would much rather not do this as it leads to having to manage what will become a very large collection of temporary assemblies on disk.

I’m optimistic .Net can do this and, being a novice, I’m simply missing it.

(I hope the spacing comes out ok on the code sample. It seems to render properly in the preview window for a few moments but once the syntax highlighter is done it rerenders and the spacing is incorrect although it remains readable.)

using System; using System.CodeDom.Compiler; using System.Reflection; using System.Collections.Generic; using Microsoft.CSharp;    namespace AsmCompileTest   {   class Program     {     static Assembly Compile( string code, Assembly referencedAssembly )       {       CompilerParameters cp = new CompilerParameters();       cp.GenerateExecutable = false;       cp.GenerateInMemory = true;        if( null != referencedAssembly )         {         cp.ReferencedAssemblies.Add( referencedAssembly.FullName );         }        CodeDomProvider provider = new CSharpCodeProvider( new Dictionary<string,string> { { 'CompilerVersion', 'v3.5' } } );        CompilerResults compilerResults = provider.CompileAssemblyFromSource( cp, code );        if( compilerResults.Errors.HasErrors )         {         foreach( CompilerError error in compilerResults.Errors )           {           Console.WriteLine( 'COMPILER ERROR: ' + error.ErrorText );           }         }        return compilerResults.CompiledAssembly;       }       static string Code1 = 'using System;' +                           'public class HelloClass' +                           '  {' +                           '  public HelloClass() { Console.WriteLine( \'Hello, World!\' ); }' +                           '  }';       static string Code2 = 'using System;' +                           'public class TestClass' +                           '  {' +                           '  public TestClass() { new HelloClass(); }' +                           '  }';      static void Main()       {       Assembly asm1 = Compile( Code1, null );       Console.WriteLine( 'Compiled: ' + asm1.FullName );          asm1.GetType( 'HelloClass' ).InvokeMember( String.Empty, BindingFlags.CreateInstance, null, null, null );          Assembly asm2 = Compile( Code2, asm1 );       Console.WriteLine( 'Compiled: ' + asm2.FullName );          asm2.GetType( 'TestClass' ).InvokeMember( String.Empty, BindingFlags.CreateInstance, null, null, null );       }     }   } 
  • 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. 2026-05-11T03:39:39+00:00Added an answer on May 11, 2026 at 3:39 am

    Based on documentation found on MSDN and on the code in reflector that I looked at (for the compiler classes) it is not possible to do what you want. The reason is that underneath, the code compiler classes that you are using shell out to the actual compiler.

    Also, the code compiler classes are actually generating the temporary files underneath, and based on the code I looked at in reflector, they are not cleaning up the files. So based on that, I would say just generate the file on the disk in a temporary location, and then add reference to it.

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

Sidebar

Ask A Question

Stats

  • Questions 107k
  • Answers 107k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Some Advantages of Panel: Scrollable Lots of border style options.… May 11, 2026 at 9:02 pm
  • Editorial Team
    Editorial Team added an answer The problem here is that Order is a generic class,… May 11, 2026 at 9:02 pm
  • Editorial Team
    Editorial Team added an answer As an administrator of ClearCase, I would rule out that… May 11, 2026 at 9:02 pm

Related Questions

So my 2009 new years resolution is to learn Java. I recently acquired Java
[resolved] I tweaked the preferences in komodo edit and ended up with: don't auto
I'm a complete n00b in j3d (but an expert in Java). Just starting out,
The simple demo below captures what I am trying to do. In the real

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.