Skip to content

Commit 0e318b9

Browse files
authored
Fix for WireUpControls throws exception (#3795)
<!-- Please be sure to read the [Contribute](https://github.com/reactiveui/reactiveui#contribute) section of the README --> **What kind of change does this PR introduce?** <!-- Bug fix, feature, docs update, ... --> Fix for #3714 **What is the current behavior?** <!-- You can also link to an open issue here. --> WireUpControls throws exception with .Net 8.0 Android **What is the new behavior?** <!-- If this is a feature change --> WireUpControls works with .Net 8.0 Android **What might this PR break?** none expected **Please check if the PR fulfills these requirements** - [ ] Tests for the changes have been added (for bug fixes / features) - [ ] Docs have been added / updated (for bug fixes / features) **Other information**:
1 parent 75d0899 commit 0e318b9

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/ReactiveUI/Platforms/android/ControlFetcherMixin.cs

+13-10
Original file line numberDiff line numberDiff line change
@@ -227,16 +227,19 @@ private static int GetControlIdByName(Assembly assembly, string? name)
227227
assembly,
228228
currentAssembly =>
229229
{
230-
var resources = currentAssembly.GetModules().SelectMany(x => x.GetTypes()).First(x => x.Name == "Resource");
231-
232-
var idType = resources.GetNestedType("Id");
233-
234-
if (idType is null)
235-
{
236-
throw new InvalidOperationException("Id is not a valid nested type in the resources.");
237-
}
238-
239-
return idType.GetFields()
230+
#if NET8_0_OR_GREATER
231+
var resources = Assembly.Load(currentAssembly
232+
.GetReferencedAssemblies()
233+
.First(an => an.FullName.StartsWith("_Microsoft.Android.Resource.Designer")).ToString())
234+
.GetModules()
235+
.SelectMany(x => x.GetTypes())
236+
.First(x => x.Name == "ResourceConstant");
237+
#else
238+
var resources = currentAssembly.GetModules().SelectMany(x => x.GetTypes()).First(x => x.Name == "Resource");
239+
#endif
240+
241+
var idType = resources.GetNestedType("Id") ?? throw new InvalidOperationException("Id is not a valid nested type in the resources.");
242+
return idType.GetFields()
240243
.Where(x => x.FieldType == typeof(int))
241244
.ToDictionary(k => k.Name, v => ((int?)v.GetRawConstantValue()) ?? 0, StringComparer.InvariantCultureIgnoreCase);
242245
});

0 commit comments

Comments
 (0)