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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:47:46+00:00 2026-05-15T11:47:46+00:00

I am trying to customize the assembly resolution process by wrapping the AppDomain and

  • 0

I am trying to customize the assembly resolution process by wrapping the AppDomain and its AssemblyResolve event inside a class. The simplified version of my ClassLoader is below. The problem I am having is that when the event AssemblyResolve is fired, it seems that I get a new instance of ClassLoader, not the one I previously created.

[Serializable]
public class ClassLoader // : IDisposable
{
    public AppDomain Domain { get; private set; }
    public string FooProperty { get; set; }

    public ClassLoader(string domain) {
        Domain = AppDomain.CreateDomain(domain);
        Domain.AssemblyResolve += Domain_AssemblyResolve;
    }

    private Assembly Domain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        Console.WriteLine(
            "ClassLoader HashCode: {0} FooProperty: {1}\n\n", 
            GetHashCode(), 
            FooProperty);
        // ...
        return null;
    }
    // ...
}

When executing this code, FooProperty is not initialized in the Domain_AssemblyResolve event handler and the ClassLoader instance has a different hash code from “c”.

 var c = new ClassLoader("demo");
 c.FooProperty = "Foo";
 Console.WriteLine(
     "c Hash Code: {0} FooProperty: {1}", 
     c.GetHashCode(), 
     c.FooProperty);
 c.Domain.CreateInstanceAndUnwrap("Not important", "Not important");

Do you what is happening? or some workaround?

Thanks!

  • 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-15T11:47:46+00:00Added an answer on May 15, 2026 at 11:47 am

    The ClassLoader instance c is created on application domain A and since it does not inherits from MarshalByRefObject it will be serialized into the application domain that you are creating at the moment you add the event handler to AssemblyResolve. This happens because the method is an instance method and the delegate will need a reference to the target object where the method will be called.

    If you just want that the FooProperty have a specific value when the event handler is triggered then you can add the event handler only after initializing the property causing the value to be serialized and available in the newly created application domain.

    public string FooProperty { get; private set; }
    
    public ClassLoader(string domain, string fooProperty)
    {
        FooProperty = fooProperty; // Set it before adding event handler
        Domain = AppDomain.CreateDomain(domain);
        Domain.AssemblyResolve += Domain_AssemblyResolve;
    }
    

    If you have the requirement that the instance c is available in both application domains then you should take a look at:

    Making Objects Remotable

    Events and Delegates with .NET Framework Remoting

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

Sidebar

Related Questions

I'm trying to customize the Django Admin. models.py ============= class Question(models.Model): poll = models.ForeignKey(Poll)
I am trying to customize the Event portlet in Plone 3 that shows the
I'm trying to customize some TFS work items via the VS2008 xml editor, but
I'm currently trying to customize a Visual Studio Isolated Shell so it opens a
I'm trying to customize the location of the user.config file. Currently it's stored with
I'm trying to customize the icon that shows in Windows Explorer and in Desktop
I'm trying to customize a table view to display a feed of youtube videos
I am trying to customize the WPF 4.0 DataGrid and need a listing of
I'm testing the dismax requesthandler , im trying to customize the mm ( Minimum
New to php and drupal. I set up drupal and trying to customize the

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.