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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:47:41+00:00 2026-05-16T22:47:41+00:00

I have come across a strange behaviour in my (huge) .NET 4 project. At

  • 0

I have come across a strange behaviour in my (huge) .NET 4 project. At some point in the code, I am referring to a fully qualified type, say:

System.Type type = typeof (Foo.Bar.Xyz);

later on, I do this:

System.Type type = System.Type.GetType ("Foo.Bar.Xyz");

and I get back null. I cannot make sense of why this is happening, because my type name is correct, and I have checked with other types and they get resolved properly. Moreover, the following LINQ query finds the type:

var types = from assembly in System.AppDomain.CurrentDomain.GetAssemblies ()
            from assemblyType in assembly.GetTypes ()
            where assemblyType.FullName == typeName
            select assemblyType;

System.Type type = types.FirstOrDefault ();

Are there any reasons why System.Type.GetType could fail?

I have finally had to resort to this piece of code instead of GetType:

System.Type MyGetType(string typeName)
{
    System.Type type = System.Type.GetType (typeName);

    if (type == null)
    {
        var types = from assembly in System.AppDomain.CurrentDomain.GetAssemblies ()
                    from assemblyType in assembly.GetTypes ()
                    where assemblyType.FullName == typeName
                    select assemblyType;

        type = types.FirstOrDefault ();
    }

    return type;
}
  • 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-16T22:47:41+00:00Added an answer on May 16, 2026 at 10:47 pm

    If you just give a class name (which does need to be fully-qualified in terms of the namespace, of course) Type.GetType(string) will only look in the currently executing assembly and mscorlib. If you want to get types from any other assembly, you need to specify the absolutely full name including the assembly information. As François says, Type.AssemblyQualifiedName is a good way of seeing this. Here’s an example:

    using System;
    using System.Windows.Forms;
    
    class Test
    {
        static void Main()
        {
            string name = typeof(Form).AssemblyQualifiedName;
            Console.WriteLine(name);
    
            Type type = Type.GetType(name);
            Console.WriteLine(type);
        }
    }
    

    Output:

    System.Windows.Forms.Form, System.Windows.Forms, Version=4.0.0.0, Culture=neutral,
    PublicKeyToken=b77a5c561934e089
    System.Windows.Forms.Form

    Note that if you’re using a strongly named assembly (like Form in this case) you must include all the assembly information – versioning, public key token etc.

    If you’re using a non-strongly-named assembly, it’s easier – something like:

    Foo.Bar.Baz, MyCompany.MyAssembly
    

    for a type called Baz in namespace Foo.Bar, in assembly MyCompany.MyAssembly. Note the absence of “.dll” at the end – that’s part of the filename, but not the assembly name.

    You should also be aware of the differences between C# names and CLR names for things like nested classes and generics. For example, typeof(List<>.Enumerator) has a name of System.Collections.Generic.List`1+Enumerator[T]. The generics side is tricky to work out, but the nested type bit is easy – it’s just represented with a “+” instead of the “.” you’d use in C#.

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

Sidebar

Related Questions

I have come across some strange behaviour, and I'm assuming a bug in Firefox,
While analyzing some library code supplied by another company we have come across strange
During my university exercise I have come across strange behaviour of a variable. /*
I have come across a strange error. I have an Android project that uses
I have come across a strange behavior with Microsoft Code Contracts that I don't
I have come across some strange behavior in my iPhone Objective-C app. I am
I have come across a strange bug in my code and I cannot understand
I have come across through a strange behaviour of Linq : with two linq
I've come across some strange behaviour in Visual Studio 2010 when using anonymous methods
I have come across C++03 some code that takes this form: struct Foo {

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.