Question

I am trying to implement a version of example 1 from here http://msdn.microsoft.com/en-us/library/System.MarshalByRefObject(v=vs.110).aspx into my code.

My aim is to have a class with some methods then load that class into a different appdomain and call its method.

so far I have:

 public class diffDomain : MarshalByRefObject
 {
      public int getNumber()
      {
           return 5;
      }
 }
 internal static class JITCompiler
 {
      internal static wantNumber()
      {
           AppDomain domain = AppDomain.CreateDomain("MyDomain");
           var newSearch = (diffDomain)domain.CreateInstanceAndUnwrap(
                            Assembly.GetExecutingAssembly().FullName,
                            "diffDomain");
      }
 }

I get an error on the Var newSearch line:

Could not load type 'diffDomain' from assembly 'SVM, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
Était-ce utile?

La solution

Your assembly/namespace could be incorrect. To avoid such errors try this:

var newSearch = (diffDomain)domain.CreateInstanceAndUnwrap(
                            typeof(diffDomain).Assembly.FullName,
                            typeof(diffDomain).FullName);

Autres conseils

What you put in your question isn't your real code, as it has an obvious syntax error.

What you put in your question also doesn't demonstrate the issue you're having, because you excluded relevant information.

What I think you've done is put your classes in a namespace. CreateInstanceAndUnwrap expects a fully qualified name. The example you linked to puts the class in the global namespace, so the unqualified name and qualified names are the same. They probably aren't in what you're trying.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top