Skip to content

Commit

Permalink
fix: Don't fail on missing metadata updater (net5 support)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromelaban committed Nov 28, 2021
1 parent 7c261dd commit ab1c748
Showing 1 changed file with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Uno.UI.RemoteControl.HotReload
{
partial class ClientHotReloadProcessor : IRemoteControlProcessor
{
private const string MetadataUpdaterType = "System.Reflection.Metadata.MetadataUpdater";

private ApplyUpdateHandler _applyUpdate;
private bool _linkerEnabled;

Expand All @@ -37,7 +39,7 @@ partial void InitializeMetadataUpdater()

private string[] GetMetadataUpdateCapabilities()
{
if (Type.GetType("System.Reflection.Metadata.MetadataUpdater") is { } type)
if (Type.GetType(MetadataUpdaterType) is { } type)
{
if (type.GetMethod("GetCapabilities", BindingFlags.Static | BindingFlags.NonPublic) is { } getCapabilities)
{
Expand All @@ -52,18 +54,28 @@ private string[] GetMetadataUpdateCapabilities()
}
else
{
throw new NotSupportedException($"Invalid returned type for System.Reflection.Metadata.MetadataUpdater.GetCapabilities()");
if (this.Log().IsEnabled(LogLevel.Warning))
{
this.Log().Trace($"Runtime does not support Hot Reload (Invalid returned type for {MetadataUpdaterType}.GetCapabilities())");
}
}
}
else
{
throw new NotSupportedException($"Unable to find System.Reflection.Metadata.MetadataUpdater.GetCapabilities()");
if (this.Log().IsEnabled(LogLevel.Warning))
{
this.Log().Trace($"Runtime does not support Hot Reload (Unable to find method {MetadataUpdaterType}.GetCapabilities())");
}
}
}
else
{
throw new NotSupportedException($"Unable to find System.Reflection.Metadata.MetadataUpdater");
if (this.Log().IsEnabled(LogLevel.Warning))
{
this.Log().Trace($"Runtime does not support Hot Reload (Unable to find type {MetadataUpdaterType})");
}
}
return Array.Empty<string>();
}

private void AssemblyReload(AssemblyDeltaReload assemblyDeltaReload)
Expand Down Expand Up @@ -97,7 +109,7 @@ from m in a.Modules
#else
if (_applyUpdate == null)
{
if (Type.GetType("System.Reflection.Metadata.MetadataUpdater") is { } type)
if (Type.GetType(MetadataUpdaterType) is { } type)
{
if (type.GetMethod("ApplyUpdate") is { } applyUpdateMethod)
{
Expand All @@ -114,7 +126,10 @@ from m in a.Modules
}
}

_applyUpdate(assembly, metadataDelta, ilDeta, pdbDelta);
if (_applyUpdate is not null)
{
_applyUpdate(assembly, metadataDelta, ilDeta, pdbDelta);
}
#endif
}
else
Expand Down

0 comments on commit ab1c748

Please sign in to comment.