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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:47:49+00:00 2026-05-16T16:47:49+00:00

I have two separate projects ( comclient and comserver ), with some very simple

  • 0

I have two separate projects (comclient and comserver), with some very simple code:

comserver/Program.cs

using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace comserver
{
  class Program
  {
    static void Main(string[] args)
    {
      RegisterComObject();
    }

    public static void RegisterComObject()
    {
      Assembly asm = Assembly.GetExecutingAssembly();
      RegistrationServices reg = new RegistrationServices();
      bool f = reg.RegisterAssembly(asm, AssemblyRegistrationFlags.SetCodeBase);
      Console.WriteLine("RegisterAssembly: {0}", f ? "ok" : "fail");
    }
  }

  [ComVisible(true)]
  [Guid("49752A5D-4CAD-495f-A220-07B60CDB6CE8")]
  interface IComServerDemo
  {
    void SayHello(string name);
  }

  [ComVisible(true)]
  [Guid("8FDB8319-6EC3-45b4-A384-1403D3993A07")]
  public class ComServerDemo : IComServerDemo
  {
    public void SayHello(string name)
    {
      Console.WriteLine("Hello {0}!", name);
    }
  }
}

comclient/Program.cs

using System;
using System.Runtime.InteropServices;

namespace comclient
{
  class Program
  {
    static void Main(string[] args)
    {
      ComServerDemo csdObj = new ComServerDemo();
      IComServerDemo csd = (IComServerDemo)csdObj;
      csd.SayHello("Bob");
    }
  }

  [ComImport, Guid("8FDB8319-6EC3-45b4-A384-1403D3993A07")]
  public class ComServerDemo
  {
  }

  [ComImport, Guid("49752A5D-4CAD-495f-A220-07B60CDB6CE8")]
  interface IComServerDemo
  {
    void SayHello(string name);
  }
}

When I run comserver.exe, it registers the COM interface OK:

RegisterAssembly: ok

But when I try to run the COM client, I get this exception:

An unhandled exception of type
‘System.InvalidCastException’ occurred
in comclient.exe

Additional information: Unable to cast
object of type
‘comserver.ComServerDemo’ to type
‘comclient.ComServerDemo’.

Any ideas why I’m getting this exception? The comclient project does not reference the comserver class. Also, I’m trying to create an out of proc COM server, but I have a feeling this might not do the trick – any ideas about this also?

  • 1 1 Answer
  • 1 View
  • 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-16T16:47:49+00:00Added an answer on May 16, 2026 at 4:47 pm

    You need a feature called ‘Type equivalence’, added to .NET 4.0. It is used to allow two distinct .NET types to be considered equivalent when they have the exact same GUID. This feature was used to implement the new ‘Embed Interop Types’ feature, making it unnecessary to deploy PIAs.

    I don’t know enough about it to judge whether you can actually use it to make this code work. Gut instinct says yes. Check out the docs for the [TypeIdentifier] attribute.

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

Sidebar

Related Questions

I have two separate applications (both part of the same system) that share a
I have a project setup with two separate projects in two separate schemes, the
I am currently switching from developing two separate Xcode Projects into using Xcode workspace.
I'm using Eclipse Indigo with the m2e Plugin (Version 1.0.1). I have two separate
I have two C++/CLI projects A and B in separate solutions. I use A
I have two separate projects, a plus and free version. Both projects use a
I have two separate java maven projects: one is my web app itself and
I have two separate solutions with web projects. I need to use one app
i have two separate questions; however, since they are very similar i will ask
Okay, hopefully this is quick and easy. I have two separate java projects, 'Library'

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.