문제

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'.
도움이 되었습니까?

해결책

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

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top