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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:20:35+00:00 2026-06-17T12:20:35+00:00

I was trying to create a remotable object and getting errors even though it

  • 0

I was trying to create a remotable object and getting errors even though it seemed like everything was in order, so I decided to simplify and run a sample piece of code straight from Microsoft (http://msdn.microsoft.com/en-us/library/system.marshalbyrefobject.aspx).

When I run this code I get a TypeLoadException when it calls CreateInstanceAndUnwrap(). However, I just tried it on my laptop and it worked fine. Anybody have any clue why it would work on the laptop but not the desktop?? I just created a console app on each and copy/pasted the code below so I don’t understand what would be different between the two.

using System;
using System.Reflection;

public class Worker : MarshalByRefObject
{
    public void PrintDomain() 
    { 
        Console.WriteLine("Object is executing in AppDomain \"{0}\"",
            AppDomain.CurrentDomain.FriendlyName); 
    }
}

class Example
{
    public static void Main()
    {
        // Create an ordinary instance in the current AppDomain
        Worker localWorker = new Worker();
        localWorker.PrintDomain();

        // Create a new application domain, create an instance 
        // of Worker in the application domain, and execute code 
        // there.
        AppDomain ad = AppDomain.CreateDomain("New domain");
        Worker remoteWorker = (Worker) ad.CreateInstanceAndUnwrap(
            Assembly.GetExecutingAssembly().FullName,
            "Worker");
        remoteWorker.PrintDomain();
    }
}

EDIT: So, I just tried to create an instance of the type using the Activator in the local domain and even that gave me an error saying that it couldn’t load file or assembly ‘System.RuntimeType’ or one of its dependencies. Seeing as how that’s an internal type to the .Net Framework that I couldn’t keep it from deploying even if I wanted to, I’m quite baffled now.

EDIT: There is no InnerException, but here’s the Stack:

   at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type)
   at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
   at System.Activator.CreateInstance(String assemblyName, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at ConsoleApplication1.Example.Main(String[] args) in D:\Projects\Remoting\ConsoleApplication1\Program.cs:line 28
   at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
   at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
   at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
   at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Oh, and the exception reads:

{"Could not load type 'Worker' from assembly 'ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.":"Worker"}

Also, I tried running this line of code:

var w = Activator.CreateInstance(typeof(Worker).GetType().FullName, "Worker");

and got a FileNotFoundException:

Could not load file or assembly 'System.RuntimeType' or one of its dependencies.  The system cannot find the file specified.
  • 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-17T12:20:36+00:00Added an answer on June 17, 2026 at 12:20 pm

    In your initial code, you are trying to instantiate an incomplete typename, and that code shouldn’t work anywhere unless Worker has no namespace. It should be:

    var workerType = typeof(Worker);
    Worker remoteWorker = (Worker) ad.CreateInstanceAndUnwrap(
                // Where Worker is defined (probably the same as current assembly in you case)
                workerType.Assembly.FullName,
                // Worker's *fully-qualified* typename, including the namespace 
                workerType.FullName); 
    

    Your local activation code is mistakenly calling typeof(Worker).GetType().FullName rather than typeof(Worker).FullName.

    typeof(Anything).GetType() will always return System.RuntimeType

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

Sidebar

Related Questions

Trying to create a background-image slideshow and am getting this error... This is the
I'm trying create an immutable object and initialise it from xml config file in
I am trying create a xmldocument object by a different XML see the code
I am new to asp.net & trying create a object, but there is a
I'm trying create an intermediate object to work with elsewhere that I can pass
I'm trying create a simple audio stream server like a concept proof, but I'm
I'm trying create new object from a module class in VBA, and I have
Trying to create an array of structs (new to C), but I am getting
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
I am trying create a delegate representation of constructor by emitting a Dynamic Method,

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.