출력 유형이 netmodule 인 C# 코드를 만들었습니다. 이것은 C++ 코드에서 사용되고 있습니다.C#을 사용하여 C#을 호출 할 때 다른 appdomain에 객체를 만들 수 없습니다.
이미로드 된 동일한 어셈블리의 개체를 만들고 싶습니다. 그러나 별도의 AppDomain에 있습니다. 그러나이 작업을 수행 할 때 CreateInstanceAndUnwrap 메서드를 사용하여 개체를 만들려면 어셈블리를로드 할 수 없습니다. 독립 실행 형 C# 코드를 사용하여 동일한 작업을 수행하려고하면 잘 동작합니다.
C++ :
TestClass __gc *testObj;
testObj = AppDomainProcessor::getInstance()->newTestObj((LPWSTR)domName);
//testObj->otherOperation...
C#을
namespace TestNS {
public class AppDomainProcessor {
...
public TestClass newTestObj(String domName) {
AppDomain appDomain = AppDomain.CreateDommain(domName);
TestClass testObj = (TestClass)appDomain.CreateInstanceAndUnwrap(typeof(TestClass).Assembly.FullName,typeof(TestClass).FullName);
//Could not load file or assembly 'MyManaged, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified
return testObj;
}
...
}
public class TestClass : MarshalByRefObject {
...
}
}
는 내가의 AssemblyName 인쇄 및 C++ 코드에서 컴파일 된 DLL의 이름으로 그것을 발견. 독립형 C#에서 시도 할 때, 그것은 exe의 이름이었습니다.
C++과 C#을 함께 사용할 때 AppDomain을 만드는 적절한 방법입니까? 또는 AppDomain을 만드는 데 실수를했습니다. 도와주세요.
오류 메시지가 표시됩니까? 그럴 경우 질문에 복사하여 붙여 넣으십시오. –
@RobertHarvey 코드 근처의 주석에 오류가 추가되었습니다. –
그 오류 메시지는 간단한 파일 찾기 문제인 것처럼 보입니다. –