-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MissingFieldException in fragment and activity #1231
Comments
Seems likely that this was brought about by #1217. Perhaps @Qonstrukt has some thoughts on this? |
I'll try and reproduce this today. |
So, this bug got introduced by #1217 but I'd like some ideas on how we might fix this, because I see a couple of options. @reactiveui/reviewers-android Do you guys think it's necessary to add a parameter to WireUpControls to triggers warnings instead of exceptions, or could we make this the default behaviour? Or do you think we shouldn't touch this at all and just revert #1217? |
I could not quite understand the changes made in #1217 but here is what I suggest: public static void WireUpControls(this Activity This, bool viewWithsubClass = false)
{
IEnumerable<PropertyInfo> members;
if (viewWithsubClass)
{
members = This.GetType().GetRuntimeProperties()
.Where(m => typeof(View).IsAssignableFrom(m.PropertyType));
}
else
{
members = This.GetType().GetRuntimeProperties()
.Where(m => m.PropertyType.IsSubclassOf(typeof(View)));
}... reset of the method is same. We can do the same for all methods. @Qonstrukt Can you please share some code where you need IsAssignableFrom(), that will help me understand the benefit of it? Kind regards, |
The change in #1217 was purely made to allow View properties to be wired up. I didn't run into this exception because we were already catching the Looking at how this works, it's kind of a bare-bones implementation anyway. We had our own solution before using RxUI which depended on Property attributes to define that a property had to be wired up automatically. |
Cool thanks for the detailed reply, I definitely agree that it requires better way of doing this but I believe we should avoid try/catch as not everyone need to pay the performance cost in regular scenarios. I will be happy to test your changes to make sure it cover regular scenarios. Thanks, |
I'll try and propose a code change this weekend and will reference you, so you can have a look. |
IMHO I don't see the need of wiring up controls of type Failing silently just because of a corner case does not feel like the right solution. I feel like it would somehow break the convention and I would not get an immediate exception if I did some typo or did some refactoring. Failing silently or even logging warnings would just postpone the exception to a NullReferenceException when trying to access the View property. I would disagree that
@Qonstrukt I do not really understand the issue can you maybe provide an example to clearify the use case? |
Thank you for pointing out the use in An example is very easy, say you have a property in a base Fragment representing a Toolbar for example:
This Toolbar is dynamically created, it's not in the layout, but created in Sure you can work around this by falling back to One option would be to have it find only View descendants in it's own class and not the classes it's inheriting from. This would be a rather simple improvement, adding an attribute to |
This is fixed in 7.2.0 with #1250. Thanks @binoypatel and @orzech85 for reporting, and others for thinking on a solution. |
Just so I clear 😕 , On an Any other strategy/attribute combo results in the Thanks. |
I haven't encountered this in my own projects, but I'm assuming you're referring to the |
@Qonstrukt Thanks for the quick reply. (yes, I am referring to Ah... said the now caffeinated brain... after adding the rxUI source, I realized that I refactored a couple activities to use Implicit or ExplicitOptIn where removing all the view properties was not worth it and re-did a handful of Views (were Forms-based), solved a ton of Forms' bugs and speed problems in at least those refactored views. (The |
Hi
After upgrading to rx 7.1, I am getting following exception when WireUpControls called:
In fragment:
System.MissingFieldException: Failed to wire up the Property View to a View in your layout with a corresponding identifier
In activity:
System.MissingFieldException: Failed to wire up the Property CurrentFocus to a View in your layout with a corresponding identifier
As you can see that "View" and "CurrentFocus" both are type of Android.Views.View properties and I believe it should not be in the collection in ControlFetcherMixin.WireUpControls. You can reproduce this issue in Playground-Android. Let me know if I am doing something wrong? I have attached MainActivity.cs from Playground-Android for your reference:
MainActivity.txt
Thanks,
Binoy
The text was updated successfully, but these errors were encountered: