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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:47:37+00:00 2026-06-14T23:47:37+00:00

In my code I have an interface – lets say its called InterfaceName and

  • 0

In my code I have an interface – lets say its called InterfaceName and its implementation called InterfaceImpl. Now when I dynamically try to obtain the InterfaceImpl using the following code:

object obj = Activator.CreateInstance("ProjectName","ProjectName.Folder.InterfaceImpl");
InterfaceName in = (InterfaceName)obj; //Error pops up here

I get the following error

Unable to cast object of type 'System.Runtime.Remoting.ObjectHandle' to type 'ProjectName.Folder.InterfaceName'.

Any suggestions on what might be going wrong ?

  • 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-14T23:47:38+00:00Added an answer on June 14, 2026 at 11:47 pm

    If you read the documentation about the method you are calling, it returns

    A handle that must be unwrapped to access the newly created instance.

    Looking at the documentation of ObjectHandle, you simply call Unwrap() in order to get the instance of the type you are trying to create.

    So, I guess your real issue is… Why?

    This method is designed to be called in another AppDomain, and the handle returned back to the calling AppDomain, where the proxy to the instance is “unwrapped”.

    What? That doesn’t explain why?

    Only two types can cross an AppDomain barrier. Types that are serializable (of which copies are created), and types that extend MarshalByRefObject (of which proxies are created and passed). ObjectHandle extends MarshalByRefObject, and so can cross that AppDomain barrier, whereas the type which they are representing may not extend MBRO or be serializable. This method ensures you can get that type instance across the barrier, no matter what.

    So, if you are just trying to instantiate a type, you might want to look at a different overload of CreateInstance. Or just unwrap the result.

    var obj = Activator.CreateInstance("A","A.B.C") as ObjectHandle;
    InterfaceName in = (InterfaceName)obj.Unwrap(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have this code: #import <UIKit/UIKit.h> @interface MyView : UIView @end @implementation MyView
Say I have this code - public interface ParentInterface1 { public List<? extends ChildInterface1>
I have an interface that is called by unmanaged code. It passes a BSTR
Let's say I have an interface: public interface Foo{ String bar(int baz); } Now
I'm trying to figure out why this code won't compile. I have interface A
the code I have is: interfacebase<T> interfaceA extends interface<A> ---> interfaceAImpl implements interfaceA interfaceB
i have this code public interface Interfcae1 { void OP1(); } public interface Interfcae2
I have some code using libxml2's SAX2 interface. I want to be able to
I have this code (which is way simplified from the real code): public interface
If use MongoRepository, You can have following code: @Repository public interface UserRepo extends MongoRepository<User,

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.