@@ -753,18 +753,62 @@ private void GenerateResourceLoader(IndentedStringBuilder writer)
753
753
754
754
private void BuildResourceLoaderFromAssembly ( IndentedStringBuilder writer , IAssemblySymbol assembly )
755
755
{
756
- var hasUnoHasLocalizationResources = assembly . GetAttributes ( ) . Any ( a =>
756
+ var unoHasLocalizationResourcesAttribute = assembly . GetAttributes ( ) . FirstOrDefault ( a =>
757
757
SymbolEqualityComparer . Default . Equals ( a . AttributeClass , _assemblyMetadataSymbol )
758
758
&& a . ConstructorArguments . Length == 2
759
- && a . ConstructorArguments [ 0 ] . Value is "UnoHasLocalizationResources"
760
- && ( a . ConstructorArguments [ 1 ] . Value ? . ToString ( ) . Equals ( "True" , StringComparison . OrdinalIgnoreCase ) ?? false ) ) ;
761
-
759
+ && a . ConstructorArguments [ 0 ] . Value is "UnoHasLocalizationResources" ) ;
760
+ var unoHasLocalizationResourcesAttributeDefined = unoHasLocalizationResourcesAttribute is not null ;
761
+
762
+ var hasUnoHasLocalizationResourcesAttributeEnabled = unoHasLocalizationResourcesAttribute
763
+ ? . ConstructorArguments [ 1 ]
764
+ . Value
765
+ ? . ToString ( )
766
+ . Equals ( "True" , StringComparison . OrdinalIgnoreCase ) ?? false ;
767
+
762
768
// Legacy behavior relying on the fact that GlobalStaticResources is generated using the default namespace.
763
- var hasGlobalStaticResources = assembly . GetTypeByMetadataName ( assembly . Name + ".GlobalStaticResources" ) is not null ;
769
+ var globalStaticResourcesSymbol = assembly . GetTypeByMetadataName ( assembly . Name + ".GlobalStaticResources" ) ;
770
+
771
+ if (
772
+ // The assembly contains resources to be used
773
+ hasUnoHasLocalizationResourcesAttributeEnabled
764
774
765
- if ( hasUnoHasLocalizationResources || hasGlobalStaticResources )
775
+ // The assembly does not have the UnoHasLocalizationResources attribute defined, but
776
+ // may still contain resources as it may have been built with a previous version of Uno.
777
+ || ( ! unoHasLocalizationResourcesAttributeDefined && globalStaticResourcesSymbol is not null )
778
+ )
766
779
{
767
- writer . AppendLineIndented ( $ "global::Windows.ApplicationModel.Resources.ResourceLoader.AddLookupAssembly(global::System.Reflection.Assembly.Load(\" { assembly . Name } \" ));") ;
780
+ if ( _isWasm )
781
+ {
782
+ var anchorType = globalStaticResourcesSymbol
783
+ ?? assembly
784
+ . Modules
785
+ . First ( )
786
+ . GlobalNamespace
787
+ . GetNamespaceTypes ( )
788
+ . FirstOrDefault ( s => s . IsLocallyPublic ( _metadataHelper . Compilation . Assembly . Modules . First ( ) ) ) ;
789
+
790
+ if ( anchorType is INamedTypeSymbol namedSymbol )
791
+ {
792
+ // Use a public type to get the assembly to work around a WASM assembly loading issue
793
+ writer . AppendLineIndented (
794
+ $ "global::Windows.ApplicationModel.Resources.ResourceLoader" +
795
+ $ ".AddLookupAssembly(typeof(global::{ namedSymbol . GetFullMetadataName ( ) } ).Assembly);"
796
+ #if DEBUG
797
+ + $ " /* { assembly . Name } , hasUnoHasLocalizationResourcesAttributeEnabled:{ hasUnoHasLocalizationResourcesAttributeEnabled } , unoHasLocalizationResourcesAttributeDefined:{ unoHasLocalizationResourcesAttributeDefined } */"
798
+ #endif
799
+ ) ;
800
+ }
801
+ else
802
+ {
803
+ #if DEBUG
804
+ writer . AppendLineIndented ( $ "/* No anchor type for reference { assembly . Name } */") ;
805
+ #endif
806
+ }
807
+ }
808
+ else
809
+ {
810
+ writer . AppendLineIndented ( $ "global::Windows.ApplicationModel.Resources.ResourceLoader.AddLookupAssembly(global::System.Reflection.Assembly.Load(\" { assembly . Name } \" ));") ;
811
+ }
768
812
}
769
813
else
770
814
{
0 commit comments