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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:29:28+00:00 2026-06-14T18:29:28+00:00

I have some classes of objects that should by design originate from remote assemblies.

  • 0

I have some classes of objects that should by design originate from remote assemblies. I would like to be able to compare instances of these classes for equality even if the instances are loaded from different assemblies. In real life these would be loaded from network locations or the web and I would like to compare with a local cache. I have some good results from a solution that uses serialization and a custom serialization binder.

The sample client code I am using to make the comparison is:

    Assembly a = Assembly.LoadFile(@"c:\work\abc1\abc.dll");
    Type t1 = a.GetType("Abc.Def");
    Assembly b = Assembly.LoadFile(@"c:\work\abc2\abc.dll");
    Type t2 = b.GetType("Abc.Def");
    Object o1 = t1.GetConstructors()[0].Invoke(null);
    Object o2 = t2.GetConstructors()[0].Invoke(null);
    Console.WriteLine(o1.Equals(o2));

The pattern I am using in my assembly is:

namespace Abc
{
    internal sealed class DefBinder : SerializationBinder
    {
        public override Type BindToType(string assemblyName, string typeName)
        {
            Type ttd = null;
            try
            {
                ttd = this.GetType().Assembly.GetType(typeName);
            }
            catch (Exception any)
            {
                Debug.WriteLine(any.Message);
            }
            return ttd;
        }
    }


    [Serializable]
    public class Def
    {
        public Def()
        {
            Data = "This is the data";
        }
        public String Data { set; get; }
        public override bool Equals(object obj)
        {
            if (obj.GetType().FullName.Equals(this.GetType().FullName))
            {
                try
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    System.IO.MemoryStream ms = new System.IO.MemoryStream();
                    bf.Serialize(ms, obj);
                    ms.Seek(0, System.IO.SeekOrigin.Begin);
                    bf.Binder = new Abc.DefBinder();
                    Abc.Def that = (Abc.Def)bf.Deserialize(ms);
                    if (this.Data.Equals(that.Data))
                    {
                        return true;
                    }
                }
                catch (Exception any) {
                    Debug.WriteLine(any.Message);
                }
            }
            return false;
        }
    }
}

My question is: This seems to work but it feels hacky, so is there a more direct way to compare objects that might be loaded from different assemblies?

  • 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-14T18:29:29+00:00Added an answer on June 14, 2026 at 6:29 pm

    That is somewhat hacky but is a quick and easy way to get the job done. Another thing you could do is use a lot of reflection to write an equality method for two given types. Something like:

    public bool Equals(Type t1, Type t2)
    {
        var t1Constructors = t1.GetConstructors();
        var t2Constructors = t2.GetConstructors();
        //compare constructors
        var t1Methods = t1.GetMethods();
        var t2Methods = t2.GetMethods();
        //compare methods
        //etc.
    }
    

    and so on, using BindingFlags to get properties/methods/etc. that you care about and inspecting each for equality. Certainly not exactly easy but it would give you a lot of flexibility about determining what “equality” really means in your specific use case.

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

Sidebar

Related Questions

I have some classes that represent immutable objects (Quantity, Price, Probability). Is there some
I have some classes(call it Class A) which I would like to unit test
I have some debugging functions that I would like to refactor, but seeing as
I have some classes in my code. From these classes I initiate objects, say
I would like to initialize 2 classes(say Class ARegister, Class BRegister) that registers some
I have some classes that are used for Styling and all of them display
I have some classes that, for one reason or another, cannot be or need
I have some classes in my app that don't require an ID to be
Let's say I have some classes like this: abstract class View(val writer: XMLStreamWriter) {
In one of my projects, I have some classes that represent entities that cannot

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.