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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:34:34+00:00 2026-05-29T10:34:34+00:00

I am attaching to the AppDomain.AssemblyResolve event and then calling Assembly.Load(byte[]) to load the

  • 0

I am attaching to the AppDomain.AssemblyResolve event and then calling Assembly.Load(byte[]) to load the assembly.

It seems that if this is done from multiple Threads I can end up with duplicate assemblies loaded. However if I call Assembly.LoadFrom or Assembly.LoadFile this problem does not occur.

I was just wondering if this is a known qwerk of using Assembly.Load? Is it not thread safe and I need to add extra code to handle this scenario?

Full code follows…

[TestFixture]
public class Tester
{
    [Test]
    public void Run()
    {
        var currentDomain = AppDomain.CurrentDomain;
        currentDomain.AssemblyResolve += ResolveAssembly;

        var thread1 = new Thread(LoadAssembly);
        var thread2 = new Thread(LoadAssembly);

        thread1.Start();
        thread2.Start();
        thread1.Join();
        thread2.Join();
        var assemblies = currentDomain.GetAssemblies();
        Assert.AreEqual(1, assemblies.Count(x => x.GetName().Name == "AssemblyToReference"));
    }

    Assembly ResolveAssembly(object sender, ResolveEventArgs args)
    {
        //This works
        //return Assembly.LoadFile(@"PathToAssembly");

        //This works
        //return Assembly.LoadFrom(@"PathToAssembly");

        //This does not work
        return Assembly.Load(File.ReadAllBytes(@"PathToAssembly"));
    }

    void LoadAssembly()
    {
        Assembly.Load("AssemblyToReference");
    }
}
  • 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-29T10:34:36+00:00Added an answer on May 29, 2026 at 10:34 am

    Looking at the implementation details of these methods you can make the case that the LoadFrom and LoadFile methods, since they are using the filesystem, have their synchronization there. That is, both methods get an exclusive lock on the file prior to reading it in. This of course is not the case with the assembly residing in memory.

    (And MSDN has no statement of these methods being thread safe, perhaps that says enough? :))

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

Sidebar

Related Questions

I've been using the macro from this blog entry for attaching the Visual Studio
In as3, I am adding event listener and then attaching the anonymous function to
The following is the chunk of my code that is attaching a movieclip (from
I'm creating dynamic checkbox and attaching onclick event with that. Below is the code:
I'm trying to create an AppDomain and attach to its UnhandledException event from F#,
What am doing is attaching event on a class using a loop and index
I am attaching a method to the post_save signal of my Django model. This
Is there an advantage to dynamically attaching/detaching event handlers? Would manually detaching handlers help
I am interested in a profiler that is capable of attaching to a .NET
If I'm attaching a unique ID to #Atest1 , #Atest2 , does this make

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.