SlideShare a Scribd company logo
.NET CLR Hosting API
Evgen Napryaglo
Intetics
1. Runtime Customizations
Runtime
Assembly
Loading
Policy
Management
Host
Protection
Memory
Management
Garbage
Collection
I/O
Completion
CLR
Events
Task
Management
Synchronization
Management
Thread Pool
Management
Application Host – Native Environment
.NET Application Environment
Objectives
• Monitoring
• Diagnostics
• Customization
• Restriction
• Integration
• Extensibility
Development Operations
Product Development
Enterprise Integration
2. Execution & State Monitoring
Profiling
API
Debugging
API
CLR Hosting
Host
Runtime
.NET Codemscoree
ICLRRuntimeHost
CorBindToRuntimeEx
ICLRControlIHostControl
Assembly
Initialization Flow
:Host :mscoree :Runtime
CorBindToRuntimeEx
ICLRRuntimeHost
SetHostControl
Start
Initialization
ICLRControl
Status
GetCLRControl
ICLRControl
ExecuteInDefaultAppDomain
Assembly Loading
ICLRAssemblyReferenceList
ICLRAssemblyIdentityManager
• The location from which assemblies are loaded
• The way versions are managed
• The formats from which assemblies can be loaded
Customize
IHostAssemblyManager
IHostAssemblyStore
Synchronization Management
IHostSyncManager ICLRSyncManager
Enables the host to implement its own synchronization primitives for
the runtime to use.
Custom
Events IHostManualEvent, IHostAutoEvent
Critical Section
Semaphore IHostSemaphore
IHostCrst
Policy Management
ICLRPolicyManager IHostPolicyManager
Enables the host to specify the way program failures are handled, to
support different reliability requirements.
NoAction
ThrowException
AbortThread
RudeAbortThread
UnloadAppDomain
RudeUnloadAppDomain
ExitProcess
FastExitProcess
RudeExitProcess
DisableRuntime
NonCriticalResource
CriticalResource
FatalRuntime
OrphanedLock
StackOverflow
ThreadAbort
ThreadRudeAbortInNonCriticalRegion
ThreadRudeAbortInCriticalRegion
AppDomainUnload
AppDomainRudeUnload
ProcessExit
FinalizerRun
ActionsFailures
Events
Host Protection
Enables the host to enforce its own programming model, by
preventing the use of specified types or members.
ICLRHostProtectionManager
Reflection
Licensing
Synchronization
UI Components
Thread Pool Management
Enables the host to implement its own thread pool for the runtime
to use.
IHostThreadPoolManager
GetAvailableThreads
GetMaxThreads
GetMinThreads
QueueUserWorkItem
SetMaxThreads
SetMinThreads
I/O Completion
IHostIoCompletionManager
Enables the host to implement its own implementation of
asynchronous input/output.
ICLRIoCompletionManager
CLR
Host
IHostIoCompletionManager
ICLRIoCompletionManager
IO Operations Calls
Results & Feedback
Profiling
• Class loading and unloading
events.
• Thread creation and destruction
events.
• Function entry and exit events.
• Exceptions.
• Transitions between different
runtime contexts.
• Information about runtime
suspensions.
• Information about the runtime
memory heap and garbage
collection activity.
Application
For
Profiling
CLR
HOST IPC Transport
Profiler
User
Interface
Profile Target Profiler
ICorProfilerInfo
ICorProfilerCallback
Debugging
Application
For
Debugging
CLR
HOST IPC Transport
Debugger
User
Interface
Profile Target Debugger
ICorDebug
ICorDebugManagedCallback
• Accessing Call Stacks and
Variables
• Accessing IL Code and Native
Code
• On-the-Fly Data and Code
modifications
• Runtime Expressions Evaluation
• IL Code Injections
• Custom Breakpoints
• Step by Step Execution
Practical Case
Architecture
Domestic Area
New Architecture
Printer
Domestic Area
Internet
Windows User Mode Driver Framework
Virtual Printer Driver
CLR Host
.NET Data
Converter
.NET Data
Converter
.NET Data
Converter
Native
Native
Native
CLR Hosting vs COM Integration
Simple Programming Model
Fully Managed
Good Performance
Flexible Programming Model
High Reliability
Tailored Integration with Native Services
Native Programming Environment
Low Reliability
COM Infrastructure Availability
Complex Diagnostics
Strange Errors
THANK YOU

More Related Content

Евгений Напрягло ".NET Framework Hosting API Overview"