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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T14:51:50+00:00 2026-05-11T14:51:50+00:00

I have a problem that is not uncommon when building a plug-in architecture. Assembly

  • 0

I have a problem that is not uncommon when building a plug-in architecture.

  1. Assembly A is the core code — the framework.

  2. Assembly B is a plugin to that code, expected to load dynamically at runtime and make code available for Assembly A to use.

In Visual Studio, Project B (which generates Assembly B) has a reference to Project A (which generates Assembly A), so it can reference the types in Project A and compile just fine. Both projects compile without error and generate DLLs.

But, at runtime, I get cast exceptions like this:

'MyType' cannot be converted to type 'MyType' 

I’ve come to understand that a type defined in one project and referenced in another are considered different types at runtime, even if they resolve fine at compile time.

But, I thought this could be fixed by loading Assembly B into the correct context. So I switched from ‘Assembly.LoadFrom’ to ‘Assembly.Load’ and put Assembly B in the probing path. The idea is that it would load into the same context as Assembly A, and they would be one big, happy family.

I downloaded the Fusion log viewer and watched the assemblies load. Both Assembly A and Assembly B load like this:

Assembly is loaded in default load context.

So, I have ensured they are both loaded in the same load context.

Still, I can’t share types between the two Assemblies. I get casting errors when I try to pass an object (whose type is defined in Assembly A) as a parameter from code in Assembly A to a method on an object in Assembly B.

To summarize:

  1. MyType is defined in Assembly A

  2. From Assembly A, I load Assembly B at runtime into the same load context using ‘Assembly.Load’

  3. From Assembly A, I use Reflection to invoke a static method on a class in Assembly B. I pass this method an object of MyType as a parameter (which is expected, and which compiled just fine).

  4. Fails with: ‘MyType’ cannot be converted to type ‘MyType’

Here’s the code I use to invoke the method, if that matters. This code executes in Assembly A:

TypeFromAssemblyB.GetMethod('MyMethod').Invoke(null, new object[] { ObjectOfTypeDefinedInAssemblyA }); 
  • 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. 2026-05-11T14:51:51+00:00Added an answer on May 11, 2026 at 2:51 pm

    I was sure this should work as you’ve described it, so I wrote a quick and dirty example. My entry assembly is called PluginTest and contains the following class:

    namespace PluginTest {     public class MyType     {         public string Data { get; set; }     } } 

    And my plugin assembly is called Plugin. It references the PluginTest project in Visual Studio and only contains this class:

    using System; using PluginTest;  namespace Plugin {     public class Class1     {         public static void ShowData(MyType input)         {             Console.WriteLine(input.Data);         }     } } 

    Finally back in PluginTest (the executable) I have this code in Main:

    static void Main(string[] args)         {             Assembly pluginAssembly = Assembly.LoadFrom('Plugin.dll');              Type pluginType = pluginAssembly.GetType('Plugin.Class1');              MethodInfo mi = pluginType.GetMethod('ShowData');              mi.Invoke(null, new object[]             {                 new MyType {Data = 'Hello World'}             });              Console.ReadLine();          } 

    As expected this pops up a console window and writes ‘Hello World’ to it. So, in principle, what you are trying to do should work…

    (On preview I like Jonathan’s idea that it may be a version mismatch – do a clean build of the entire solution and make sure that all the dlls get copied to the right folders)

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

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The following will find you the start of the last… May 12, 2026 at 1:14 am
  • Editorial Team
    Editorial Team added an answer probably flv format is one of the most used on… May 12, 2026 at 1:14 am
  • Editorial Team
    Editorial Team added an answer You can use this CREATE VIEW myView AS SELECT test_a.id,… May 12, 2026 at 1:14 am

Related Questions

I have a complex RIA client that communicates with a WCF SOAP web service,
I have a very large C project with many separate C files and headers
This Paper ( When the CRC and TCP checksum disagree ) suggests that since
It is not uncommon for me (or likely anyone else) to have a list

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.