-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix 15052 NullReferenceException when returning null from DataTemplateSelector #15074
Conversation
…edPage.ItemTemplate Not sure what other controls this picks up but it's a start.
Awesome stuff @bakerhillpins thanks so much for your help here! Feel free to ping me when you think this is good to go or you need anything :) |
@jfversluis LOL... you asked for it. Might not be the right place but I can't continue testing/fixing without getting this to work and I've spent a bunch of time on it already: I can't get my local xamarin.forms build (windows machine) of the UAP dll to build/execute in a test project. Android/iOS work fine. When I use a released version of Xamarin.Forms (5.0.0.2291) my UWP project runs with no problems. When I update to my locally built NuGet I get the following Warning:
Which follows up with a bunch of these errors:
After a bit of poking around it seems that my local build has a dependency built into it that the production Xamarin.Forms.Platform.UAP.dll does not: Which is in the project but I can't seem to figure out where it comes from??? UPDATE - wish I would have stumbled upon this before I pinged you but I seem to have found a way around it...Short story:
For those of you that arrive here via search... If you add the following two properties to the Xamarin.Forms.Platform.UAP project you can build with VS.. These properties were extracted from the build.cake file
|
Haha glad you figured it out! :D |
UPDATE: I'm not sure what I was doing when I was seeing this problem but it is an issue ONLY on UWP.@jfversluis I'm testing my changes and have a question for you about Search isn't coming up with a bug. Threw me for a loop when I was testing since the DataTemplate wasn't working and it's in the default samples.
The code that's responsible for the application of the EmptyViewTemplate for UAP is here. And it's coded to completely ignore the DataTemplate unless the EmptyView is of a type other than
|
This code is never used because the protected members are never set, thus !null test is never true, and the class has not been specialized. (Cut out and compile with no errors).
@jfversluis Sorry for the earlier distractions. I'm at the point where I think I've got it all completed. Few things:
See below, I updated the default template for the empty page After further review, this appears to be a UWP only issue. At the moment that's it. Any comments? Should I move this out of draft? |
@jfversluis - I think It's time to get this into review. What do you say?
Ok, For the above I changed the default template in these cases to carry simple label content bound to the object to get something visual on the page (object.ToString). This way when folks drop a template something's displayed rather than just blank. At the moment I'm unable to resolve what's going on in this method:
I think this is what the method really should be:
|
Bindable Layout EmptyDataTemplate fixed but found #15093 @jfversluis - I've not heard from you with regard to my questions so I'm just going to put this into review. |
I've corrected the logic so it can handle a null from a DataTemplateSelector, but I've not corrected the logic that's using the template as a parameter for template selection.
I'd like to understand how to validate platform tests before I commit them. |
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
Not sure what you mean by this? I ran the build and all the unit tests seem green? :) |
@jfversluis Sorry for the confusion. I did put in some Xamarin.Forms.Core.UnitTests which can be run on windows. I also authored one or two tests in the Platform.UnitTests space (e.g. Xamarin.Forms.Platform.Android.UnitTests) since I figured you'd prefer to have some included. Just a few to test the process, but I didn't commit them because I don't have instructions on how to execute the Platform based tests => The runner fails because I don't have Mono Android. This isn't surprising as I'm on a windows box but I wasn't sure if there was a way to do this besides checking them in and hoping that the Azure Pipelines don't fail. |
I see the new and old tests popping up here and succeeding: https://dev.azure.com/xamarin/public/_build/results?buildId=53229&view=ms.vss-test-web.build-test-results-tab |
I'm sorry, I'm not doing a good job of explaining myself I guess. Is there any way to run Platform tests locally on my laptop? |
Ah sorry about that! :) I think they are being ran as part of the UI tests. In the UITest project for Android you can see the PlatformUnitTest project is referenced. You can run them locally, but it might be easier to just commit them and see what it does in the pipeline :) |
Now that we're so close to the sunsetting of Xamarin.Forms unfortunately we won't be able to take this in anymore, we're really sorry about that. Nevertheless, thank you so much for your time and effort that you have put into this PR. Please have a look at the evolution of Xamarin.Forms, .NET MAUI. A lot of development has been going on there. Hopefully this issue was already fixed in that codebase. If not, feel free to port this over to there. Again, thank you so much for being a contributor and Xamarin.Forms user! |
Description of Change
Allows DataTemplateSelector implementations to return null from
DataTemplateSelector.OnSelectTemplate(object item, BindableObject container)
. This will result in the display of the item/element as if the related DataTemplate were not assigned at all/is null.Issues Resolved
API Changes
None
Platforms Affected
Behavioral/Visual Changes
None
Before/After Screenshots
Not applicable
Testing Procedure
I've attempted to add some simple tests to the Core.UnitTests project.
I've also been executing various xamarin_forms_samples projects where I've altered the code so that DataTemplateSelector implementations return null. I'll add those projects as I clean them up.
NOTE: I've needed to run with Microsoft.NETCore.UniversalWindowsPlatform 6.2.13 on my UWP test apps or I'll get
ExecutionEngineException
s when null is returned from the selectors. Once I upgrade that NuGet my changes seem to correct the remaining problems.Test Projects: (NOTE: these currently reference released Xamarin.Forms and as such will fail)
Selector.zip
FlyoutTest.zip
groupingSampleListView.zip
CollectionViewDemos.zip
TabbedPageDemo.zip
PR Checklist