다음을 통해 공유


AppDomain.CreateInstanceFrom 메서드

정의

지정된 어셈블리 파일에 정의된 지정된 형식의 새 인스턴스를 만듭니다.

오버로드

Name Description
CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)
사용되지 않음.

지정된 어셈블리 파일에 정의된 지정된 형식의 새 인스턴스를 만듭니다.

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

지정된 어셈블리 파일에 정의된 지정된 형식의 새 인스턴스를 만듭니다.

CreateInstanceFrom(String, String, Object[])

지정된 어셈블리 파일에 정의된 지정된 형식의 새 인스턴스를 만듭니다.

CreateInstanceFrom(String, String)

지정된 어셈블리 파일에 정의된 지정된 형식의 새 인스턴스를 만듭니다.

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[], Evidence)

주의

Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.

지정된 어셈블리 파일에 정의된 지정된 형식의 새 인스턴스를 만듭니다.

public:
 virtual System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes, System::Security::Policy::Evidence ^ securityAttributes);
public System.Runtime.Remoting.ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes, System.Security.Policy.Evidence securityAttributes);
[System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")]
public System.Runtime.Remoting.ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes, System.Security.Policy.Evidence securityAttributes);
abstract member CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle
override this.CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle
[<System.Obsolete("Methods which use evidence to sandbox are obsolete and will be removed in a future release of the .NET Framework. Please use an overload of CreateInstanceFrom which does not take an Evidence parameter. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>]
abstract member CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle
override this.CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] * System.Security.Policy.Evidence -> System.Runtime.Remoting.ObjectHandle
Public Function CreateInstanceFrom (assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object(), securityAttributes As Evidence) As ObjectHandle

매개 변수

assemblyFile
String

요청된 형식을 정의하는 어셈블리가 포함된 파일의 경로를 포함한 이름입니다. 어셈블리는 메서드를 사용하여 로드됩니다 LoadFrom(String) .

typeName
String

속성에서 반환한 네임스페이스를 비롯하여 어셈블리가 아닌 요청된 형식의 FullName 정규화된 이름입니다.

ignoreCase
Boolean

대/소문자를 구분하는 검색을 수행할지 여부를 지정하는 부울 값입니다.

bindingAttr
BindingFlags

생성자 검색 typeName 에 영향을 주는 0개 이상의 비트 플래그 조합입니다. 0이면 bindingAttr 공용 생성자에 대한 대/소문자 구분 검색이 수행됩니다.

binder
Binder

바인딩, 인수 형식 강제 변환, 멤버 호출 및 리플렉션을 통해 개체 검색 MemberInfo 을 사용하도록 설정하는 개체입니다. null이면 binder 기본 바인더가 사용됩니다.

args
Object[]

생성자에 전달할 인수입니다. 이 인수 배열은 호출할 생성자의 매개 변수를 숫자, 순서 및 형식으로 일치시켜야 합니다. 매개 변수가 없는 생성자가 선호 args 되는 경우 빈 배열 또는 null이어야 합니다.

culture
CultureInfo

생성자에 대해 선언된 형식에 args 대한 typeName 강제 변환을 제어하는 문화권별 정보입니다. 이 nullCultureInfo 경우 culture 현재 스레드에 대한 스레드가 사용됩니다.

activationAttributes
Object[]

활성화에 참여할 수 있는 하나 이상의 특성 배열입니다. 일반적으로 원격 개체를 활성화하는 데 필요한 URL을 지정하는 단일 UrlAttribute 개체가 포함된 배열입니다.

이 매개 변수는 클라이언트 활성화 개체와 관련이 있습니다. 클라이언트 활성화는 이전 버전과의 호환성을 위해 유지되지만 새 개발에는 권장되지 않는 레거시 기술입니다. 분산 애플리케이션은 Windows Communication Foundation을 대신 사용해야 합니다.

securityAttributes
Evidence

만들기 권한을 부여하는 데 사용되는 정보입니다 typeName.

반환

새 인스턴스의 래퍼이거나 null 찾을 수 없는 개체 typeName 입니다. 실제 개체에 액세스하려면 반환 값을 래핑 해제해야 합니다.

구현

특성

예외

assemblyFilenull입니다.

-또는-

typeNamenull입니다.

호출자는 상속 MarshalByRefObject되지 않는 개체에 대한 활성화 특성을 제공할 수 없습니다.

-또는-

securityAttributes 가 아닙니다 null. 레거시 CAS 정책을 사용하도록 설정 securityAttributesnull하지 않은 경우 .

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

assemblyFile 을(를) 찾을 수 없습니다.

typeName에서 찾을 수 없습니다.assemblyFile

일치하는 공용 생성자를 찾을 수 없습니다.

호출자에게 이 생성자를 호출할 수 있는 충분한 권한이 없습니다.

assemblyFile 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

이 인스턴스는 .입니다 null.

설명

이 메서드에 대한 자세한 내용은 메서드를 참조하세요 Activator.CreateInstanceFrom .

메서드를 CreateInstanceFrom 사용하여 호출이 이루어지는 애플리케이션 도메인 이외의 대상 애플리케이션 도메인에서 인스턴스를 만들면 어셈블리가 대상 애플리케이션 도메인에 로드됩니다. 그러나 인스턴스가 호출 애플리케이션 도메인에서 래핑 해제된 경우 특정 방법으로 래핑 해제된 인스턴스를 사용하면 어셈블리가 호출 애플리케이션 도메인에 로드될 수 있습니다. 예를 들어 인스턴스가 래핑 해제된 후 메서드를 런타임에 바인딩된 메서드를 호출하기 위해 해당 형식 정보를 요청할 수 있습니다. 어셈블리가 호출 애플리케이션 도메인에 로드되면 예외가 발생할 수 있습니다.

  • 동일한 어셈블리의 다른 버전이 이전에 호출 애플리케이션 도메인에 로드되었거나 호출하는 애플리케이션 도메인의 로드 경로가 대상 애플리케이션 도메인의 로드 경로와 다른 경우와 같은 MissingMethodException 예외가 발생할 수 있습니다.

  • 호출하는 애플리케이션 도메인이 인스턴스 형식 InvalidCastException 에 대한 초기 바인딩된 호출을 하는 경우 인스턴스를 캐스팅하려고 할 때 throw될 수 있습니다.

추가 정보

적용 대상

CreateInstanceFrom(String, String, Boolean, BindingFlags, Binder, Object[], CultureInfo, Object[])

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

지정된 어셈블리 파일에 정의된 지정된 형식의 새 인스턴스를 만듭니다.

public:
 System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, bool ignoreCase, System::Reflection::BindingFlags bindingAttr, System::Reflection::Binder ^ binder, cli::array <System::Object ^> ^ args, System::Globalization::CultureInfo ^ culture, cli::array <System::Object ^> ^ activationAttributes);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Type and its constructor could be removed")]
public System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes);
public System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder? binder, object?[]? args, System.Globalization.CultureInfo? culture, object?[]? activationAttributes);
public System.Runtime.Remoting.ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, bool ignoreCase, System.Reflection.BindingFlags bindingAttr, System.Reflection.Binder binder, object[] args, System.Globalization.CultureInfo culture, object[] activationAttributes);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Type and its constructor could be removed")>]
member this.CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] -> System.Runtime.Remoting.ObjectHandle
member this.CreateInstanceFrom : string * string * bool * System.Reflection.BindingFlags * System.Reflection.Binder * obj[] * System.Globalization.CultureInfo * obj[] -> System.Runtime.Remoting.ObjectHandle
Public Function CreateInstanceFrom (assemblyFile As String, typeName As String, ignoreCase As Boolean, bindingAttr As BindingFlags, binder As Binder, args As Object(), culture As CultureInfo, activationAttributes As Object()) As ObjectHandle

매개 변수

assemblyFile
String

요청된 형식을 정의하는 어셈블리가 포함된 파일의 경로를 포함한 이름입니다. 어셈블리는 메서드를 사용하여 로드됩니다 LoadFrom(String) .

typeName
String

속성에서 반환한 네임스페이스를 비롯하여 어셈블리가 아닌 요청된 형식의 FullName 정규화된 이름입니다.

ignoreCase
Boolean

대/소문자를 구분하는 검색을 수행할지 여부를 지정하는 부울 값입니다.

bindingAttr
BindingFlags

생성자 검색 typeName 에 영향을 주는 0개 이상의 비트 플래그 조합입니다. 0이면 bindingAttr 공용 생성자에 대한 대/소문자 구분 검색이 수행됩니다.

binder
Binder

바인딩, 인수 형식 강제 변환, 멤버 호출 및 리플렉션을 통해 개체 검색 MemberInfo 을 사용하도록 설정하는 개체입니다. null이면 binder 기본 바인더가 사용됩니다.

args
Object[]

생성자에 전달할 인수입니다. 이 인수 배열은 호출할 생성자의 매개 변수를 숫자, 순서 및 형식으로 일치시켜야 합니다. 매개 변수가 없는 생성자가 선호 args 되는 경우 빈 배열 또는 null이어야 합니다.

culture
CultureInfo

생성자에 대해 선언된 형식에 args 대한 typeName 강제 변환을 제어하는 문화권별 정보입니다. 이 nullCultureInfo 경우 culture 현재 스레드에 대한 스레드가 사용됩니다.

activationAttributes
Object[]

활성화에 참여할 수 있는 하나 이상의 특성 배열입니다. 일반적으로 원격 개체를 활성화하는 데 필요한 URL을 지정하는 단일 UrlAttribute 개체가 포함된 배열입니다.

이 매개 변수는 클라이언트 활성화 개체와 관련이 있습니다. 클라이언트 활성화는 이전 버전과의 호환성을 위해 유지되지만 새 개발에는 권장되지 않는 레거시 기술입니다. 분산 애플리케이션은 Windows Communication Foundation을 대신 사용해야 합니다.

반환

새 인스턴스의 래퍼이거나 null 찾을 수 없는 개체 typeName 입니다. 실제 개체에 액세스하려면 반환 값을 래핑 해제해야 합니다.

특성

예외

assemblyFilenull입니다.

-또는-

typeNamenull입니다.

호출자는 상속 MarshalByRefObject되지 않는 개체에 대한 활성화 특성을 제공할 수 없습니다.

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

assemblyFile 을(를) 찾을 수 없습니다.

typeName에서 찾을 수 없습니다.assemblyFile

일치하는 공용 생성자를 찾을 수 없습니다.

호출자에게 이 생성자를 호출할 수 있는 충분한 권한이 없습니다.

assemblyFile 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

이 인스턴스는 .입니다 null.

설명

자세한 내용은 Activator.CreateInstanceFrom 메서드를 참조하세요.

메서드를 CreateInstanceFrom 사용하여 호출이 이루어지는 애플리케이션 도메인 이외의 대상 애플리케이션 도메인에서 인스턴스를 만들면 어셈블리가 대상 애플리케이션 도메인에 로드됩니다. 그러나 인스턴스가 호출 애플리케이션 도메인에서 래핑 해제된 경우 특정 방법으로 래핑 해제된 인스턴스를 사용하면 어셈블리가 호출 애플리케이션 도메인에 로드될 수 있습니다. 예를 들어 인스턴스가 래핑 해제된 후 메서드를 런타임에 바인딩된 메서드를 호출하기 위해 해당 형식 정보를 요청할 수 있습니다. 어셈블리가 호출 애플리케이션 도메인에 로드되면 예외가 발생할 수 있습니다.

  • 동일한 어셈블리의 다른 버전이 이전에 호출 애플리케이션 도메인에 로드되었거나 호출하는 애플리케이션 도메인의 로드 경로가 대상 애플리케이션 도메인의 로드 경로와 다른 경우와 같은 MissingMethodException 예외가 발생할 수 있습니다.

  • 호출하는 애플리케이션 도메인이 인스턴스 형식 InvalidCastException 에 대한 초기 바인딩된 호출을 하는 경우 인스턴스를 캐스팅하려고 할 때 throw될 수 있습니다.

추가 정보

적용 대상

CreateInstanceFrom(String, String, Object[])

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

지정된 어셈블리 파일에 정의된 지정된 형식의 새 인스턴스를 만듭니다.

public:
 System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, cli::array <System::Object ^> ^ activationAttributes);
public:
 virtual System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName, cli::array <System::Object ^> ^ activationAttributes);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Type and its constructor could be removed")]
public System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName, object?[]? activationAttributes);
public System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName, object?[]? activationAttributes);
public System.Runtime.Remoting.ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName, object[] activationAttributes);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Type and its constructor could be removed")>]
member this.CreateInstanceFrom : string * string * obj[] -> System.Runtime.Remoting.ObjectHandle
member this.CreateInstanceFrom : string * string * obj[] -> System.Runtime.Remoting.ObjectHandle
abstract member CreateInstanceFrom : string * string * obj[] -> System.Runtime.Remoting.ObjectHandle
override this.CreateInstanceFrom : string * string * obj[] -> System.Runtime.Remoting.ObjectHandle
Public Function CreateInstanceFrom (assemblyFile As String, typeName As String, activationAttributes As Object()) As ObjectHandle

매개 변수

assemblyFile
String

요청된 형식을 정의하는 어셈블리가 포함된 파일의 경로를 포함한 이름입니다. 어셈블리는 메서드를 사용하여 로드됩니다 LoadFrom(String) .

typeName
String

속성에서 반환한 네임스페이스를 비롯하여 어셈블리가 아닌 요청된 형식의 FullName 정규화된 이름입니다.

activationAttributes
Object[]

활성화에 참여할 수 있는 하나 이상의 특성 배열입니다. 일반적으로 원격 개체를 활성화하는 데 필요한 URL을 지정하는 단일 UrlAttribute 개체가 포함된 배열입니다.

이 매개 변수는 클라이언트 활성화 개체와 관련이 있습니다. 클라이언트 활성화는 이전 버전과의 호환성을 위해 유지되지만 새 개발에는 권장되지 않는 레거시 기술입니다. 분산 애플리케이션은 Windows Communication Foundation을 대신 사용해야 합니다.

반환

새 인스턴스의 래퍼이거나 null 찾을 수 없는 개체 typeName 입니다. 실제 개체에 액세스하려면 반환 값을 래핑 해제해야 합니다.

구현

특성

예외

assemblyFilenull입니다.

assemblyFile 을(를) 찾을 수 없습니다.

typeName에서 찾을 수 없습니다.assemblyFile

호출자에게 이 생성자를 호출할 수 있는 충분한 권한이 없습니다.

일치하는 공용 생성자를 찾을 수 없습니다.

호출자는 상속 MarshalByRefObject되지 않는 개체에 대한 활성화 특성을 제공할 수 없습니다.

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

assemblyFile 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

이 인스턴스는 .입니다 null.

설명

매개 변수가 없는 생성자가 typeName 호출됩니다.

이 메서드에 대한 자세한 내용은 메서드를 참조하세요 Activator.CreateInstanceFrom .

메서드를 CreateInstanceFrom 사용하여 호출이 이루어지는 애플리케이션 도메인 이외의 대상 애플리케이션 도메인에서 인스턴스를 만들면 어셈블리가 대상 애플리케이션 도메인에 로드됩니다. 그러나 인스턴스가 호출 애플리케이션 도메인에서 래핑 해제된 경우 특정 방법으로 래핑 해제된 인스턴스를 사용하면 어셈블리가 호출 애플리케이션 도메인에 로드될 수 있습니다. 예를 들어 인스턴스가 래핑 해제된 후 메서드를 런타임에 바인딩된 메서드를 호출하기 위해 해당 형식 정보를 요청할 수 있습니다. 어셈블리가 호출 애플리케이션 도메인에 로드되면 예외가 발생할 수 있습니다.

  • 동일한 어셈블리의 다른 버전이 이전에 호출 애플리케이션 도메인에 로드되었거나 호출하는 애플리케이션 도메인의 로드 경로가 대상 애플리케이션 도메인의 로드 경로와 다른 경우와 같은 MissingMethodException 예외가 발생할 수 있습니다.

  • 호출하는 애플리케이션 도메인이 인스턴스 형식 InvalidCastException 에 대한 초기 바인딩된 호출을 하는 경우 인스턴스를 캐스팅하려고 할 때 throw될 수 있습니다.

추가 정보

적용 대상

CreateInstanceFrom(String, String)

Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs
Source:
AppDomain.cs

지정된 어셈블리 파일에 정의된 지정된 형식의 새 인스턴스를 만듭니다.

public:
 System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName);
public:
 virtual System::Runtime::Remoting::ObjectHandle ^ CreateInstanceFrom(System::String ^ assemblyFile, System::String ^ typeName);
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Type and its constructor could be removed")]
public System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName);
public System.Runtime.Remoting.ObjectHandle? CreateInstanceFrom(string assemblyFile, string typeName);
public System.Runtime.Remoting.ObjectHandle CreateInstanceFrom(string assemblyFile, string typeName);
[<System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Type and its constructor could be removed")>]
member this.CreateInstanceFrom : string * string -> System.Runtime.Remoting.ObjectHandle
member this.CreateInstanceFrom : string * string -> System.Runtime.Remoting.ObjectHandle
abstract member CreateInstanceFrom : string * string -> System.Runtime.Remoting.ObjectHandle
override this.CreateInstanceFrom : string * string -> System.Runtime.Remoting.ObjectHandle
Public Function CreateInstanceFrom (assemblyFile As String, typeName As String) As ObjectHandle

매개 변수

assemblyFile
String

요청된 형식을 정의하는 어셈블리가 포함된 파일의 경로를 포함한 이름입니다. 어셈블리는 메서드를 사용하여 로드됩니다 LoadFrom(String) .

typeName
String

속성에서 반환한 네임스페이스를 비롯하여 어셈블리가 아닌 요청된 형식의 FullName 정규화된 이름입니다.

반환

새 인스턴스의 래퍼이거나 null 찾을 수 없는 개체 typeName 입니다. 실제 개체에 액세스하려면 반환 값을 래핑 해제해야 합니다.

구현

특성

예외

assemblyFilenull입니다.

-또는-

typeNamenull입니다.

assemblyFile 을(를) 찾을 수 없습니다.

typeName에서 찾을 수 없습니다.assemblyFile

작업이 언로드된 애플리케이션 도메인에서 시도됩니다.

매개 변수가 없는 공용 생성자를 찾을 수 없습니다.

호출자에게 이 생성자를 호출할 수 있는 충분한 권한이 없습니다.

assemblyFile 가 현재 로드된 런타임에 유효한 어셈블리가 아닌 경우

어셈블리 또는 모듈이 두 개의 서로 다른 증명 정보로 두 번 로드되었습니다.

이 인스턴스는 .입니다 null.

예제

다음 예제에서는 메서드 오버로드를 CreateInstanceFrom(String, String) 사용하여 대상 애플리케이션 도메인에서 개체의 인스턴스를 만들고 해당 메서드를 호출하는 방법을 보여 줍니다.

이 예제에서는 MarshalableExample 애플리케이션 도메인 경계를 넘어 마샬링할 수 있는 클래스를 정의합니다. 이 예제에서는 현재 실행 중인 어셈블리에 대한 경로를 빌드하고, 대상 애플리케이션 도메인을 만들고, 메서드 오버로드를 사용하여 CreateInstanceFrom(String, String) 예제 어셈블리를 대상 애플리케이션 도메인에 로드하고 인스턴스 MarshalableExample를 만듭니다.

메모

이 예제에서는 경로가 절대적이지만 메서드가 어셈블리를 로드하는 데 사용되므로 상대 경로도 작동 Assembly.LoadFrom 합니다.

개체 핸들을 래핑 해제한 후 이 예제에서는 대상 애플리케이션 도메인에서 개체를 사용하는 세 가지 방법을 보여 줍니다.

  • 리플렉션을 사용하여 런타임에 바인딩된 메서드를 호출합니다. 이렇게 하려면 형식 정보가 필요하므로 어셈블리가 호출자의 애플리케이션 도메인에 로드됩니다. (이 예제에서는 이미 로드되어 있습니다.)

  • 호출자와 호출자 모두에게 알려진 인터페이스로 개체 캐스팅 호출 어셈블리 또는 호출자와 호출 수신자가 참조하는 세 번째 어셈블리에서 인터페이스가 정의된 경우 호출된 어셈블리는 호출자의 애플리케이션 도메인에 로드되지 않습니다.

  • 호출자에게 해당 형식을 알 수 있는 경우 개체를 직접 사용하세요. 어셈블리는 호출자의 애플리케이션 도메인에 로드되어야 합니다.

호출자의 애플리케이션 도메인에 호출된 어셈블리를 로드하지 않도록 하는 또 다른 방법은 호출자가 클래스에서 파생되고 대상 애플리케이션 도메인에서 MarshalByRefObject 실행할 수 있는 메서드를 정의하는 것입니다. 대상 어셈블리가 대상 애플리케이션 도메인에 이미 로드되어 있으므로 이 메서드는 리플렉션을 사용하여 대상 어셈블리를 검사할 수 있습니다. 속성에 대한 예제를 DynamicDirectory 참조하세요.

using namespace System;

public interface class ITest
{
    void Test(String^ greeting);
};

public ref class MarshalableExample : MarshalByRefObject, ITest
{
public:
    virtual void Test(String^ greeting)
    {
        Console::WriteLine("{0} from '{1}'!", greeting,
            AppDomain::CurrentDomain->FriendlyName);
    }
};

void main()
{
    // Construct a path to the current assembly.
    String^ assemblyPath = Environment::CurrentDirectory + "\\" +
        MarshalableExample::typeid->Assembly->GetName()->Name + ".exe";

    AppDomain^ ad = AppDomain::CreateDomain("MyDomain");
 
    System::Runtime::Remoting::ObjectHandle^ oh = 
        ad->CreateInstanceFrom(assemblyPath, "MarshalableExample");

    Object^ obj = oh->Unwrap();


    // Three ways to use the newly created object, depending on how
    // much is known about the type: Late bound, early bound through 
    // a mutually known interface, or early binding of a known type.
    //
    obj->GetType()->InvokeMember("Test", 
        System::Reflection::BindingFlags::InvokeMethod, 
        Type::DefaultBinder, obj, gcnew array<Object^> { "Hello" });

    ITest^ it = (ITest^) obj;
    it->Test("Hi");

    MarshalableExample^ ex = (MarshalableExample^) obj;
    ex->Test("Goodbye");
}

/* This example produces the following output:

Hello from 'MyDomain'!
Hi from 'MyDomain'!
Goodbye from 'MyDomain'!
 */
using System;

public interface ITest
{
    void Test(string greeting);
}

public class MarshalableExample : MarshalByRefObject, ITest
{
    static void Main()
    {
        // Construct a path to the current assembly.
        string assemblyPath = Environment.CurrentDirectory + "\\" +
            typeof(MarshalableExample).Assembly.GetName().Name + ".exe";

        AppDomain ad = AppDomain.CreateDomain("MyDomain");

        System.Runtime.Remoting.ObjectHandle oh =
            ad.CreateInstanceFrom(assemblyPath, "MarshalableExample");

        object obj = oh.Unwrap();

        // Three ways to use the newly created object, depending on how
        // much is known about the type: Late bound, early bound through
        // a mutually known interface, or early binding of a known type.
        //
        obj.GetType().InvokeMember("Test",
            System.Reflection.BindingFlags.InvokeMethod,
            Type.DefaultBinder, obj, new object[] { "Hello" });

        ITest it = (ITest) obj;
        it.Test("Hi");

        MarshalableExample ex = (MarshalableExample) obj;
        ex.Test("Goodbye");
    }

    public void Test(string greeting)
    {
        Console.WriteLine("{0} from '{1}'!", greeting,
            AppDomain.CurrentDomain.FriendlyName);
    }
}

/* This example produces the following output:

Hello from 'MyDomain'!
Hi from 'MyDomain'!
Goodbye from 'MyDomain'!
 */
open System

type ITest =
    abstract Test: string -> unit

type MarshalableExample() =
    inherit MarshalByRefObject()
    
    member _.Test greeting =
        printfn $"{greeting} from '{AppDomain.CurrentDomain.FriendlyName}'!"

    interface ITest with
        member this.Test message = this.Test message 

// Construct a path to the current assembly.
let assemblyPath = 
    Environment.CurrentDirectory + "\\" + typeof<MarshalableExample>.Assembly.GetName().Name + ".exe"

let ad = AppDomain.CreateDomain "MyDomain"

let oh =
    ad.CreateInstanceFrom(assemblyPath, "MarshalableExample")

let obj = oh.Unwrap()

// Three ways to use the newly created object, depending on how
// much is known about the type: Late bound, early bound through
// a mutually known interface, or early binding of a known type.
//
obj.GetType().InvokeMember("Test",
    System.Reflection.BindingFlags.InvokeMethod,
    Type.DefaultBinder, obj, [| box "Hello" |])
|> ignore

let it = obj :?> ITest
it.Test "Hi"

let ex = obj :?> MarshalableExample
ex.Test("Goodbye")

(* This example produces the following output:

Hello from 'MyDomain'!
Hi from 'MyDomain'!
Goodbye from 'MyDomain'!
 *)
Public Interface ITest

    Sub Test(ByVal greeting As String)
End Interface

Public Class MarshalableExample 
    Inherits MarshalByRefObject
    Implements ITest

    Shared Sub Main()
    
        ' Construct a path to the current assembly.
        Dim assemblyPath As String = Environment.CurrentDirectory & "\" &
            GetType(MarshalableExample).Assembly.GetName().Name & ".exe"

        Dim ad As AppDomain = AppDomain.CreateDomain("MyDomain")
 
        Dim oh As System.Runtime.Remoting.ObjectHandle = 
            ad.CreateInstanceFrom(assemblyPath, "MarshalableExample")

        Dim obj As Object = oh.Unwrap()


        ' Three ways to use the newly created object, depending on how
        ' much is known about the type: Late bound, early bound through 
        ' a mutually known interface, or early binding of a known type.
        '
        obj.GetType().InvokeMember("Test", 
            System.Reflection.BindingFlags.InvokeMethod, 
            Type.DefaultBinder, obj, New Object() { "Hello" })

        Dim it As ITest = CType(obj, ITest) 
        it.Test("Hi")

        Dim ex As MarshalableExample = CType(obj, MarshalableExample) 
        ex.Test("Goodbye")
    End Sub

    Public Sub Test(ByVal greeting As String) Implements ITest.Test
    
        Console.WriteLine("{0} from '{1}'!", greeting,
            AppDomain.CurrentDomain.FriendlyName)
    End Sub
End Class

' This example produces the following output:
'
'Hello from 'MyDomain'!
'Hi from 'MyDomain'!
'Goodbye from 'MyDomain'!

설명

매개 변수가 없는 생성자가 typeName 호출됩니다.

자세한 내용은 Activator.CreateInstanceFrom 메서드를 참조하세요.

메서드를 CreateInstanceFrom 사용하여 호출이 이루어지는 애플리케이션 도메인 이외의 대상 애플리케이션 도메인에서 인스턴스를 만들면 어셈블리가 대상 애플리케이션 도메인에 로드됩니다. 그러나 인스턴스가 호출 애플리케이션 도메인에서 래핑 해제된 경우 특정 방법으로 래핑 해제된 인스턴스를 사용하면 어셈블리가 호출 애플리케이션 도메인에 로드될 수 있습니다. 예를 들어 인스턴스가 래핑 해제된 후 메서드를 런타임에 바인딩된 메서드를 호출하기 위해 해당 형식 정보를 요청할 수 있습니다. 어셈블리가 호출 애플리케이션 도메인에 로드되면 예외가 발생할 수 있습니다.

  • 동일한 어셈블리의 다른 버전이 이전에 호출 애플리케이션 도메인에 로드되었거나 호출하는 애플리케이션 도메인의 로드 경로가 대상 애플리케이션 도메인의 로드 경로와 다른 경우와 같은 MissingMethodException 예외가 발생할 수 있습니다.

  • 호출하는 애플리케이션 도메인이 인스턴스 형식 InvalidCastException 에 대한 초기 바인딩된 호출을 하는 경우 인스턴스를 캐스팅하려고 할 때 throw될 수 있습니다.

추가 정보

적용 대상