Skip to content

Commit

Permalink
Handle ReflectionTypeLoadException in Composer.GetExportedValues
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanoRaggi committed Oct 24, 2019
1 parent ee07baa commit 39c1b22
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions Common/Util/Composer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,21 +258,33 @@ public T GetExportedValueByTypeName<T>(string typeName)
/// </summary>
public IEnumerable<T> GetExportedValues<T>()
{
lock (_exportedValuesLockObject)
try
{
IEnumerable values;
if (_exportedValues.TryGetValue(typeof (T), out values))
lock (_exportedValuesLockObject)
{
IEnumerable values;
if (_exportedValues.TryGetValue(typeof (T), out values))
{
return values.OfType<T>();
}

if (!_composableParts.IsCompleted)
{
_composableParts.Wait();
}
values = _compositionContainer.GetExportedValues<T>().ToList();
_exportedValues[typeof (T)] = values;
return values.OfType<T>();
}

if (!_composableParts.IsCompleted)
}
catch (ReflectionTypeLoadException err)
{
foreach (var exception in err.LoaderExceptions)
{
_composableParts.Wait();
Log.Error(exception);
}
values = _compositionContainer.GetExportedValues<T>().ToList();
_exportedValues[typeof (T)] = values;
return values.OfType<T>();

throw;
}
}

Expand Down

0 comments on commit 39c1b22

Please sign in to comment.