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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T15:17:39+00:00 2026-06-08T15:17:39+00:00

Say I have this little bit of code: public static void LoadSomething(Type t) {

  • 0

Say I have this little bit of code:

public static void LoadSomething(Type t)
{            
    var t1 = Type.GetType(t.AssemblyQualifiedName);

    var t2 = t
        .Assembly
        .GetTypes()
        .First(ta => ta.AssemblyQualifiedName == t.AssemblyQualifiedName);
}

What happens is that t1 is null and t2 is not null. I was confused since if I call it like so…

LoadSomething(typeof(SomeObject));

then neither are null but what I am actually doing is more like this (not really, this is massively simplified but it illustrates my point):

LoadSomething(Assembly.LoadFile(@"C:\....dll").GetTypes().First());

So the first part of my question (for my information) is…

In the second case, since the assembly must be loaded up and I found the type out of it, why does Type.GetType return null?

And secondly (to actually solve my problem)…

Is there some other way that I could load a type when I only have the assembly qualified name as a string (that I know has been previously loaded by using the Assembly.Load methods)?

  • 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-08T15:17:42+00:00Added an answer on June 8, 2026 at 3:17 pm

    Is there some other way that I could load a type when I only have the
    assembly qualified name as a string (that I know has been previously
    loaded by using the Assembly.Load methods)?

    Yes. There is a GetType overload that allows that. It takes an “assembly resolver” function as parameter:

    public static Type LoadSomething(string assemblyQualifiedName)
    {
        // This will return null
        // Just here to test that the simple GetType overload can't return the actual type
        var t0 = Type.GetType(assemblyQualifiedName);
    
        // Throws exception is type was not found
        return Type.GetType(
            assemblyQualifiedName,
            (name) =>
            {
                // Returns the assembly of the type by enumerating loaded assemblies
                // in the app domain            
                return AppDomain.CurrentDomain.GetAssemblies().Where(z => z.FullName == name.FullName).FirstOrDefault();
            },
            null,
            true);
    }
    
    private static void Main(string[] args)
    {
        // Dynamically loads an assembly
        var assembly = Assembly.LoadFrom(@"C:\...\ClassLibrary1.dll");
    
        // Load the types using its assembly qualified name
        var loadedType = LoadSomething("ClassLibrary1.Class1, ClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null");
    
        Console.ReadKey();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say have this immutable record type: public class Record { public Record(int x,
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
My XPath is a little bit rusty... Let's say I have this simple XML
This is a little bit of weird problem here. Say I have a C++
Lets say i have a little bit of code I would like to repeat
This one is a little tricky. Say I have this XmlDocument <Object> <Property1>1</Property1> <Property2>2</Property2>
I'm having a trouble with this little problem. Let's say, I have an array,
Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView
Say I have this class: class myclass { public int Field1{ get; set; }
Say I have this simple method: public IEnumerable<uint> GetNumbers() { uint n = 0;

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.