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

  • Home
  • SEARCH
  • 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 7057933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:03:09+00:00 2026-05-28T04:03:09+00:00

The scenario goes like this – I have an assembly say ‘MyAssembly’. An interface

  • 0

The scenario goes like this –

  • I have an assembly say ‘MyAssembly’. An interface say ‘IMyInterface’ is defined in this assembly.
  • In the same assembly i have one class(MyClass) with a method define in it as :

public void MyMethod( IMyInterface object ) { }

  • Now in my project, i have created an interface with the same name and exact properties as exposed by the interface “IMyInterface” in ‘MyAssembly’.
  • I have a class which extends this interface(the one which i have created in my project) and i want to pass the object of that class as a parameter to the method “MyMethod” in different assembly using reflection.

Issue is –

  • When i try to invoke the method using reflection, i got this exception that “Cannot convert object to type IMyInterface”.

Code –

Assembly myAssembly = Assembly.LoadFrom("MyAssembly");
object classObject = myAssembly.CreateInstance("MyClass");
Type classType = myAssembly.GetType("MyClass");
MethodInfo myMethod = classType.GetMethod("MyMethod", BindingFlags.Instance);

// Creating an object of class in the latest assembly and need to pass this
// to method in assembly with different version.
ClassExtendingMyInterface obj= new ClassExtendingMyInterface ();

myMethod.Invoke(classObject, new object[] { obj});

If, i am getting it right, this is because object created is in different assembly and the parameter expected by the method is of its own assembly.

Another approach i thought of was to create my own dynamic method in the class which will accept the object of my class.

I have tried to google for and come across through Reflection.Emit or RunSharp to dynamically create your own class. But, we can use this only in our dynamically generated Assemblies but can’t create dynamic methods or class in already existing assembly.

I know generating assemblies at runtime is ain’t good approach. But i can’t think of anything now. Thanks for any help.

  • 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-28T04:03:09+00:00Added an answer on May 28, 2026 at 4:03 am

    You are battling something called “Type identity”, a very important DLL Hell counter-measure in the .NET framework. A type isn’t just identified by its namespace name and type name, it also includes attributes of the assembly from which it came from. Specifically the assembly display name, [AssemblyVersion], [AssemblyCulture], PublicKeyToken and (indirectly) ProcessorArchitecture. You can see the ‘real’ type name with the Type.AssemblyQualifiedName property. The System.String class for example is System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089

    This stops you from faking a type in another assembly unless you can give that assembly the exact same attributes. Much easier is to simply use the existing assembly, should be no problem in your case since you only use an interface.

    Notably is that this requirement was relaxed somewhat in .NET 4. Types that were auto-generated from a COM type library are equivalent if their name and [Guid] matches. Which helped eliminate PIAs and implement the “Embed interop types” feature. Nothing that applies in your case.

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

Sidebar

Related Questions

The scenario goes like this: I have a picture of a paper that I
We have a query which goes like this: select * from foo where some_fk_id
I have a java concurrency problem, it goes like this: There is a Servlet
Scenario: Say I am on an invoice details page. I have a customer name
I’m writing a server/client game, a typical scenario looks like this: one client (clientA)
An odd question this will be, but here goes. I have a page on
The story goes like this... My team has a git repo on a windows
i have trouble with building some projects. please consider this scenario: i have 2
I have a web-application. The flow of processing a form in it goes like
I have the following scenario... When I hover over span.share-this , it triggers a

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.