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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:00:22+00:00 2026-05-27T23:00:22+00:00

I have an application a.exe which is running fine and has loaded an assembly

  • 0

I have an application a.exe which is running fine and has loaded an assembly b.dll, which is a Prism module if that matters. This dll is loaded from a directory that is not in the path but is in the directory where a.exe resides.

Loading of the assembly is done by Prism, and is set up like this:

public class MyModuleCatalog : ComposablePartCatalog
{
  private readonly AggregateCatalog _catalog;

  public MyModuleCatalog()
  {
      //directory Modules is not in the path, but all
      //dependencies of b.dll are, so b.dll gets loaded fine
    var asmCat = new AssemblyCatalog( "Modules/b.dll" );
    _catalog.Catalogs.Add( asmCat );
  }

  public override IQueryable<ComposablePartDefinition> Parts
  {
    get { return _catalog.Parts; }
  }
}

class BootStrapper : MefBootstrapper
{
  ....
  protected override void ConfigureAggregateCatalog()
  {
    base.ConfigureAggregateCatalog();

    AggregateCatalog.Catalogs.Add( new AssemblyCatalog( Assembly.GetExecutingAssembly() ) );
    AggregateCatalog.Catalogs.Add( new MyModuleCatalog() );
  }
  ....
}

In b.dll there is a class ImInB:

[Export]
public class ImInB
{
  public void DoIt()
  {
    try
    {
      var stream = new MemoryStream();
      //using System.Runtime.Serialization.Formatters.
      var formatter = new BinaryBinaryFormatter();

        //serialize our type
      formatter.Serialize( stream, this.GetType() );

        //get it back
      stream.Position = 0;
      var obj = formatter.Deserialize( stream ); //this throws??
    }
    catch( Exception e )
    {
    }
  }
}

This is just example code, and is part of a persisting framework that loads/saves settings to a database. The object’s type is always serialized and serves as akey to the database. Upon deserializing, the type is retrieved back as a double check against the object that gets loaded.
The function gets called from a.exe:

container.GetExportedValue<ImInB>().DoIt();

The exception thrown upon deserializing the type (whih was serialized sucessfully two lines earlier) is:

"Could not load file or assembly 'b.dll, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
or one of its dependencies. The system cannot find the file specified."

Questions:

  • How is this even possible? The function gets called from within the dll, yet is says it cannot find that dll.
  • How do I fix this? How do I tell Deserialize hey, that dll is already loaded, don’t go looking for it

UPDATE
my second question is basically answered by Felix K; the following code fixes the problem:

public static class AssemblyResolverFix
{
  //Looks up the assembly in the set of currently loaded assemblies,
  //and returns it if the name matches. Else returns null.
  public static Assembly HandleAssemblyResolve( object sender, ResolveEventArgs args )
  {
    foreach( var ass in AppDomain.CurrentDomain.GetAssemblies() )
      if( ass.FullName == args.Name )
        return ass;
    return null;
  }
}

//in main
AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolverFix.HandleAssemblyResolve;

This also proves that the assembly is effectively loaded, including all of it’s dependencies, so the first question remains: it’s a mistery to me why the framework cannot figure this out by itself. Moreover I cannot reproduce it in a second application that uses roughly the same structure.

  • 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-27T23:00:23+00:00Added an answer on May 27, 2026 at 11:00 pm

    I don’t know why this happens when the dll is already loaded but i think this has nothing to do with the serialization itself, it looks like a .NET error to me.

    This might gonna help you, or points you in the right direction:

    AppDomain current = AppDomain.CurrentDomain;
    current.AssemblyResolve += new ResolveEventHandler(HandleAssemblyResolve);
    
    static Assembly HandleAssemblyResolve(object sender, ResolveEventArgs args)
    {
        /* Load the assembly specified in 'args' here and return it, 
           if the assembly is already loaded you can return it here */
    }
    

    Everytime when a dll is missing the resolve method is called, so this should also happen when your dll is missing. dotNET can’t find it because it’s in the “Modules” folder so you have to resolve the reference by yourself.

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

Sidebar

Related Questions

I have an application (winform exe) that I run several times. Does this mean
I have an application, myprogram.exe, which calls functions and code inside a dll, one
I have an external Windows .exe that is actually Java application: Running the .exe
I have an application which takes a string value of the form %programfiles%\directory\tool.exe from
I have a desktop application which contains an App.config (program.exe.config at release) with clearly
I have a rather legacy application EXE written in VB6 and running on a
I have a MS-Visual Studio 2005 workspace having all c code. This application(exe) allocates
I have C# winforms application that needs to start an external exe from time
I have application which needs to use a dll (also written by me) which
I have an application which has 3 services which are dependent on SQL server.

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.