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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:47:34+00:00 2026-06-05T02:47:34+00:00

I have an app which creates some code using CodeDom compiler. I can see

  • 0

I have an app which creates some code using CodeDom compiler. I can see that the generated assembly is in memory. But when I call Type.GetType(typeName), it returns null. I find this a little bit confusing.

What am I doing wrong?

static void Main(string[] args)
{
    // FYI: Code is some dummy class with only 1 instance method.
    string code = System.IO.File.ReadAllText("CodeToCompile.cs.txt");

    string errors = null;
    Assembly asm = DynamicCompiler.Compile(code, generateInMemory: true, generateDebugInfo: false, message: ref errors);

    // Get type from the generated assembly. We know there is only one.
    Type oneAndOnlyTypeInAssembly = asm.GetTypes().First();

    string typeName = oneAndOnlyTypeInAssembly.AssemblyQualifiedName;

    // Tell the type system to return instance of type based on fully qualified name.
    // I'd expect this to work, since the assembly is already loaded to memory.
    Type sameType = Type.GetType(typeName);

    if (sameType != null)
    {
        Console.WriteLine("Type found and equal={0}", oneAndOnlyTypeInAssembly.Equals(sameType));
    }
    else
    {
        Console.WriteLine("Type NOT FOUND");
    }
}
  • 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-06-05T02:47:35+00:00Added an answer on June 5, 2026 at 2:47 am

    Please see the remarks section in MSDN. What you want to do is not supported:

    GetType only works on assemblies loaded from disk. If you call GetType to look up a type defined in a dynamic assembly defined using the System.Reflection.Emit services, you might get inconsistent behavior. The behavior depends on whether the dynamic assembly is persistent, that is, created using the RunAndSave or Save access modes of the System.Reflection.Emit.AssemblyBuilderAccess enumeration. If the dynamic assembly is persistent and has been written to disk before GetType is called, the loader finds the saved assembly on disk, loads that assembly, and retrieves the type from that assembly. If the assembly has not been saved to disk when GetType is called, the method returns null. GetType does not understand transient dynamic assemblies; therefore, calling GetType to retrieve a type in a transient dynamic assembly returns null.

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

Sidebar

Related Questions

I have some C# code which is using CSharpCodeProvider.CompileAssemblyFromSource to create an assembly in
I have an app that creates a variable number of ScatterviewItems based on which
I have a PHP app that creates a CSV file which is forced to
I have a flex app which allows user to create some content. this content
I have a rest app with resteasy, which creates files and stores them and
I have been working on test framework, which creates a new app domain to
I'm writing an Android app. I have a main method, which creates and runs
I have a .NET Compact Framework app that can runs on three windows machines
I have a C# ASP.NET app that creates a JavaScript array of values for
I have some code I that although it works, its making my content erratic.

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.