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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:10:59+00:00 2026-06-12T23:10:59+00:00

Possible Duplicate: How to prevent ReflectionTypeLoadException when calling Assembly.GetTypes() I would like to get

  • 0

Possible Duplicate:
How to prevent ReflectionTypeLoadException when calling Assembly.GetTypes()

I would like to get all the types in an assembly. However, I get the following error:

System.Reflection.ReflectionTypeLoadException: Unable to load one or
more of the requested types.

The problem is the assembly I am getting the types from is referencing another assembly that is only available in the production environment, and not within the unit test environment.

So, is there any way that I can filter GetTypes or something similar to only return the types actually defined in the assembly and not get the type load exception?

e.g. replacement for

.Assembly.GetTypes().Where(t => t.Namespace.Equals(...
  • 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-12T23:11:00+00:00Added an answer on June 12, 2026 at 11:11 pm

    GetTypes only gets the types that are defined in the assembly, however, you may not be able to load them because they are referencing types that are in an assembly you have not loaded or cannot be found. For example, if you try to load a type that derives from a class in this other assembly then you get a ReflectionTypeLoadException. You can get the types that you did load from the exception object’s Types property. Note that there will be a null for each type you could not load and the LoaderExceptions property has an exception for each of them.

    public static Type[] GetTypesLoaded(Assembly assembly)
    {
        Type[] types;
        try
        {
          types = assembly.GetTypes();
        }
        catch (ReflectionTypeLoadException e)
        {
          types = e.Types.Where(t => t != null).ToArray();
        }
    
        return types;    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Best way to stop SQL Injection in PHP I would like to
Possible Duplicate: Prevent any form of page refresh using jQuery/Javascript how can i prevent
Possible Duplicate: how to prevent your javascripts being stolen,copied, and viewed ? What is
Possible Duplicate: Best way to prevent SQL injection in PHP? I've made a PHP
Possible Duplicate: Is there a clean way to prevent windows.h from creating a near
Possible Duplicate: In Linux, how to prevent a background process from being stopped after
Possible Duplicate: Prevent click event from affecting parent jquery I have a DOM structure
Possible Duplicate: How to prevent IFRAME from redirecting top-level window <iframe width=980px frameborder=0 marginheight=0
Possible Duplicate: Throttle event calls in jQuery I like the .change() functionality of jQuery,
Possible Duplicate: Android: How can I get the current foreground activity (from a service)?

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.