모든 것이 제대로 된 것처럼 보일지라도 원격 객체를 만들고 오류를 얻으려고 했으므로 Microsoft에서 바로 샘플 코드를 단순화하고 실행하기로 결정했습니다. (http://msdn.microsoft.com/en/ -us/library/system.marshalbyrefobject.aspx).이 간단한 원격 작업 예제는 내 랩톱에서 작동하지만 내 데스크톱에서는 작동하지 않는 이유는 무엇입니까?
이 코드를 실행할 때 CreateInstanceAndUnwrap()을 호출 할 때 TypeLoadException이 발생합니다. 그러나, 난 그냥 내 랩탑에서 그것을 시도하고 괜찮 았어. 아무도 랩탑에서 작동하지만 데스크톱에서는 작동하지 않는 이유를 알지 못합니다. 방금 각각에 콘솔 앱을 만들었고 아래 코드를 복사하여 붙여 넣었습니다. 그래서 두 코드가 다른 점을 이해하지 못합니다.
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();
}
}
편집 : 그래서, 난 그냥 나에게이 파일이나 어셈블리 'System.RuntimeType'를로드 할 수 없습니다 없다는 오류를 준 로컬 도메인에 심지어 활성제를 사용하여 형식의 인스턴스를 만들려고 또는 종속성 중 하나가 될 수 있습니다. .NET 프레임 워크의 내부 유형이 원하는 경우에도 배포하지 못하게하는 방식으로 보았습니다. 이제는 매우 당황 스럽습니다.
편집 : 아무의 InnerException이 없지만, 여기 스택 :
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()
아, 그리고 예외가 읽
{"Could not load type 'Worker' from assembly 'ConsoleApplication1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.":"Worker"}
을 또한, 나는이 코드 줄 실행 시도 :
을var w = Activator.CreateInstance(typeof(Worker).GetType().FullName, "Worker");
및 FileNotFoundException이 있습니다.
Could not load file or assembly 'System.RuntimeType' or one of its dependencies. The system cannot find the file specified.
System.RuntimeType
를 반환합니다. 그리고 나는 스택을 어떻게 만들지 모르기 때문에 게시하는 것을 생각하지 않았지만 거기에 유용한 것을 볼 수 있기를 바랍니다. –@HansPassant 예, 둘 다 Framework 4 클라이언트 프로파일에 있습니다. –
@HansPassant 로컬 도메인에서 Activator를 사용하려고해도 (내 게시물의 마지막 업데이트에서 언급 한 것처럼) –