Skip to content

Commit

Permalink
fix: Adjust desktop hot load under linux
Browse files Browse the repository at this point in the history
This change ensures that delta updates do not fail on missing assemblies
  • Loading branch information
jeromelaban authored Apr 29, 2024
1 parent a22090b commit 4e9ab3e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,26 +145,36 @@ private void LoadElementUpdateHandlerActions()
_elementHandlerActions.Clear();
foreach (var assembly in sortedAssemblies)
{
foreach (var attr in assembly.GetCustomAttributesData())
try
{
// Look up the attribute by name rather than by type. This would allow netstandard targeting libraries to
// define their own copy without having to cross-compile.
if (attr.AttributeType.FullName == "System.Reflection.Metadata.ElementMetadataUpdateHandlerAttribute")
foreach (var attr in assembly.GetCustomAttributesData())
{

var ctorArgs = attr.ConstructorArguments;
var elementType = ctorArgs.Count == 2 ? ctorArgs[0].Value as Type : typeof(object);
var handlerType = ctorArgs.Count == 2 ? ctorArgs[1].Value as Type :
ctorArgs.Count == 1 ? ctorArgs[0].Value as Type : default;
if (elementType is null || handlerType is null)
// Look up the attribute by name rather than by type. This would allow netstandard targeting libraries to
// define their own copy without having to cross-compile.
if (attr.AttributeType.FullName == "System.Reflection.Metadata.ElementMetadataUpdateHandlerAttribute")
{
_log($"'{attr}' found with invalid arguments. elementType '{elementType?.Name}', handlerType '{handlerType?.Name}'");
continue;
}

GetElementHandlerActions(elementType, handlerType);
var ctorArgs = attr.ConstructorArguments;
var elementType = ctorArgs.Count == 2 ? ctorArgs[0].Value as Type : typeof(object);
var handlerType = ctorArgs.Count == 2 ? ctorArgs[1].Value as Type :
ctorArgs.Count == 1 ? ctorArgs[0].Value as Type : default;
if (elementType is null || handlerType is null)
{
_log($"'{attr}' found with invalid arguments. elementType '{elementType?.Name}', handlerType '{handlerType?.Name}'");
continue;
}

GetElementHandlerActions(elementType, handlerType);
}
}
}
catch (Exception e)
{
// The handlers enumeration may fail for WPF assemblies that are part of the modified assemblies
// when building under linux, but which are loaded in that context. We can ignore those assemblies
// and continue the processing.
_log($"Failed to process assembly {assembly}, {e.Message}");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,34 @@ internal UpdateHandlerActions GetMetadataUpdateHandlerActions()
var handlerActions = new UpdateHandlerActions();
foreach (var assembly in sortedAssemblies)
{
foreach (var attr in assembly.GetCustomAttributesData())
try
{
// Look up the attribute by name rather than by type. This would allow netstandard targeting libraries to
// define their own copy without having to cross-compile.
if (attr.AttributeType.FullName != "System.Reflection.Metadata.MetadataUpdateHandlerAttribute")
foreach (var attr in assembly.GetCustomAttributesData())
{
continue;
// Look up the attribute by name rather than by type. This would allow netstandard targeting libraries to
// define their own copy without having to cross-compile.
if (attr.AttributeType.FullName != "System.Reflection.Metadata.MetadataUpdateHandlerAttribute")
{
continue;
}

IList<CustomAttributeTypedArgument> ctorArgs = attr.ConstructorArguments;
if (ctorArgs.Count != 1 ||
ctorArgs[0].Value is not Type handlerType)
{
_log($"'{attr}' found with invalid arguments.");
continue;
}

GetHandlerActions(handlerActions, handlerType);
}

IList<CustomAttributeTypedArgument> ctorArgs = attr.ConstructorArguments;
if (ctorArgs.Count != 1 ||
ctorArgs[0].Value is not Type handlerType)
{
_log($"'{attr}' found with invalid arguments.");
continue;
}

GetHandlerActions(handlerActions, handlerType);
}
catch (Exception e)
{
// The handlers enumeration may fail for WPF assemblies that are part of the modified assemblies
// when building under linux, but which are loaded in that context. We can ignore those assemblies
// and continue the processing.
_log($"Unable to process assembly {assembly}, ({e.Message})");
}
}

Expand Down

0 comments on commit 4e9ab3e

Please sign in to comment.