Skip to content

Commit

Permalink
Fix for WireUpControls throws exception (#3795)
Browse files Browse the repository at this point in the history
<!-- 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**:
  • Loading branch information
ChrisPulman committed Apr 26, 2024
1 parent 75d0899 commit 0e318b9
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions src/ReactiveUI/Platforms/android/ControlFetcherMixin.cs
Expand Up @@ -227,16 +227,19 @@ private static int GetControlIdByName(Assembly assembly, string? name)
assembly,
currentAssembly =>
{
var resources = currentAssembly.GetModules().SelectMany(x => x.GetTypes()).First(x => x.Name == "Resource");
var idType = resources.GetNestedType("Id");
if (idType is null)
{
throw new InvalidOperationException("Id is not a valid nested type in the resources.");
}
return idType.GetFields()
#if NET8_0_OR_GREATER
var resources = Assembly.Load(currentAssembly
.GetReferencedAssemblies()
.First(an => an.FullName.StartsWith("_Microsoft.Android.Resource.Designer")).ToString())
.GetModules()
.SelectMany(x => x.GetTypes())
.First(x => x.Name == "ResourceConstant");
#else
var resources = currentAssembly.GetModules().SelectMany(x => x.GetTypes()).First(x => x.Name == "Resource");
#endif
var idType = resources.GetNestedType("Id") ?? throw new InvalidOperationException("Id is not a valid nested type in the resources.");
return idType.GetFields()
.Where(x => x.FieldType == typeof(int))
.ToDictionary(k => k.Name, v => ((int?)v.GetRawConstantValue()) ?? 0, StringComparer.InvariantCultureIgnoreCase);
});
Expand Down

0 comments on commit 0e318b9

Please sign in to comment.