private readonly ClrInfo _clrInfo;
private readonly ISymbolService _symbolService;
private Version _runtimeVersion;
+ private ClrRuntime _clrRuntime;
private string _dacFilePath;
private string _dbiFilePath;
void IDisposable.Dispose()
{
- if (_serviceContainer.TryGetCachedService(typeof(ClrRuntime), out object service))
- {
- // The DataTarget created in the RuntimeProvider is disposed here. The ClrRuntime
- // instance is disposed below in DisposeServices().
- ((ClrRuntime)service).DataTarget.Dispose();
- }
+ // The DataTarget created in the RuntimeProvider is disposed here. The ClrRuntime
+ // instance is disposed below in DisposeServices().
+ _clrRuntime?.DataTarget.Dispose();
+ _clrRuntime = null;
_serviceContainer.RemoveService(typeof(IRuntime));
_serviceContainer.DisposeServices();
}
{
// Ignore the DAC version mismatch that can happen because the clrmd ELF dump reader
// returns 0.0.0.0 for the runtime module that the DAC is matched against.
- return _clrInfo.CreateRuntime(dacFilePath, ignoreMismatch: true);
+ return _clrRuntime = _clrInfo.CreateRuntime(dacFilePath, ignoreMismatch: true);
}
catch (Exception ex) when
(ex is DllNotFoundException or
}
/// <summary>
- /// Get the cached/instantiated service instance if one exists. Don't call the factory or parent to create.
+ /// Returns the instance of the service or returns null if service doesn't exist
/// </summary>
/// <param name="type">service type</param>
- /// <param name="service">service instance (can be null)</param>
- /// <returns>if true, found service</returns>
- public bool TryGetCachedService(Type type, out object service)
+ /// <returns>service instance or null</returns>
+ public object GetService(Type type)
{
Debug.Assert(type != null);
if (type == typeof(IServiceProvider))
{
- service = this;
- return true;
+ return this;
}
- return _instances.TryGetValue(type, out service);
- }
-
- /// <summary>
- /// Returns the instance of the service or returns null if service doesn't exist
- /// </summary>
- /// <param name="type">service type</param>
- /// <returns>service instance or null</returns>
- public object GetService(Type type)
- {
- if (TryGetCachedService(type, out object service))
+ if (_instances.TryGetValue(type, out object service))
{
return service;
}