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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:46:08+00:00 2026-05-25T12:46:08+00:00

My task: Find all Forms (WindowsForm or WPF, doesn’t matter) in a dll or

  • 0

My task: Find all Forms (WindowsForm or WPF, doesn’t matter) in a dll or exe file and return that list. In theory that works (meaning: if I’ve an assembly with a WPF or WindowsForm my code manages to get all Forms, TextBoxes, Labels etc. ). When it comes to “real” assemblies it fails. I get FileNotFound exceptions when calling GetExportedTypes() for every “custom” assembly (.NET assemblies are found, no problems there). I already use GetReferencedAssemblies() to load the referenced assemblies (Reflection.Assembly.LoadFrom) and yes it does work (all assemblies are found and loaded into the AppDomain) but it doesn’t help.

I checked the version numbers (they match), I copied my executable and the assembly into one directory with all referenced assemblies, doesn’t work.

Here is my code, maybe someone figures out what I’m (obviously) doing wrong:

foreach (AssemblyName reference in selectedAssembly.GetReferencedAssemblies())
{
      if (System.IO.File.Exists(
             System.IO.Path.GetDirectoryName(selectedAssembly.Location) + 
                @"\" + reference.Name + ".dll"))
      {
         System.Reflection.Assembly.LoadFrom(
            System.IO.Path.GetDirectoryName(selectedAssembly.Location) + 
               @"\" + reference.Name + ".dll");
      }
      else if (System.IO.File.Exists(@"C:\dll\" + reference.Name + ".dll"))
      {
         System.Reflection.Assembly.LoadFrom(@"C:\dll\" + reference.Name + ".dll");
      }
      else
      {
         System.Reflection.Assembly.ReflectionOnlyLoad(reference.FullName);
      }

      selectedAssembly.GetExportedTypes();       
}

at first check if the referenced dll exists in the directory where the assembly is, if not check if it exists in C:\dll and if it’s not there try and use the GAC. it does work and I’ve no errors from there but as soon as I come to GetExportedTypes it fails with a FileNotFound exception on the first custom library.

*edit 1 what do I mean by “real assemblies”: I mean assemblies which are more complex and have references to non-standard-.NET libraries/assemblies


Thanks for the hint to fuslogvw.exe Hans Passant but what do you mean by “with code like this”?


okay I used fuslogvw.exe and I get two exceptions for every single dll that is referenced by the “selectedAssembly”.
The first one says something like
“The binding starts in LoadFrom-context
The image owned by the system isn’t searched in LoadFrom-Context”

the other logentry says that the dll referenced by the selectedAssembly couldn’t be found and it tried to download it from application’s base path and all directories below…but not from it’s actual location…so, key question: how do I change the Load-context to LoadFrom? And why is .NET so stubborn on this? I mean the assemblies are loaded in the AppDomain, it shouldn’t care about the actual location of the assembly.


okay problem solved. Here is the solution:
http://ayende.com/blog/1376/solving-the-assembly-load-context-problem

I implemented that into my existing class (removed the static-keyword and put the body of the Init method into my method), compiled it and it worked.

Thanks for your help guys.

  • 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-25T12:46:09+00:00Added an answer on May 25, 2026 at 12:46 pm

    okay problem solved. Here is the solution: http://ayende.com/blog/1376/solving-the-assembly-load-context-problem

    I implemented that into my existing class (removed the static-keyword and put the body of the Init method into my method), compiled it and it worked.

    Thanks for your help guys.

    just in case the website will someday be unavailable, here is the sourcecode from ayende

    static Dictionary<string, Assembly>assemblies;   
    
    public static void Init()
    {
    
        assemblies = new Dictionary<string, Assembly>();
    
        AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(CurrentDomain_AssemblyLoad);
    
        AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
    }
    
    static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
    
        Assembly assembly = null;
    
        assemblies.TryGetValue(args.Name, out assembly);
    
        return assembly;
    
    } 
    
    static void CurrentDomain_AssemblyLoad(object sender, AssemblyLoadEventArgs args)
    {
    
        Assembly assembly = args.LoadedAssembly;
        assemblies[assembly.FullName] = assembly;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know zero javascript, and have one simple task: Find all text in the
I'm using find for a task and I noticed that when I do something
It's a trivial task to find out if an object is referenced by something
How do you find out the height of the task tray in vb.net, programmatically?
Once again I find myself failing at some really simple task in C++. Sometimes
The task is to take a list of tables which is changeable. Write a
I often find myself with fairly complex data that represents something that my objects
I need to find all invocations of some logging macros in the code. The
I am doing an application that will compute all 2 size frequent itemset from
So - working with C# and Windows Forms, I have a bunch of Task

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.