Bug 28996 - In a ScrollViewRenderer, using reflection to get the hScrollView field returns null in OnElementChanged
Summary: In a ScrollViewRenderer, using reflection to get the hScrollView field return...
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 1.4.1
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-04-10 15:33 UTC by Jon Goldberger [MSFT]
Modified: 2015-05-22 19:50 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jon Goldberger [MSFT] 2015-04-10 15:33:26 UTC
## Description

The following app, https://github.com/FireflyLogic/couchbase-connect-14, retrieves a reference to the HorizontalScrollView in a ScollViewRenderer.OnElementChanged method successfully using code:

>_scrollView = (HorizontalScrollView)typeof(ScrollViewRenderer)
>               .GetField ("hScrollView", BindingFlags.NonPublic | BindingFlags.Instance)
>               .GetValue (this);

The project is using Forms version 1.2.2. If you update the Forms version to 1.4.1, the above code no longer works to get a reference to the HorizontalScrollView and returns null. You can use the above code in an OnDraw override in Forms 1.4.1, but does not work in OnElementChanged.

## Steps to reproduce.

1. Download the couches connect Forms app: https://github.com/FireflyLogic/couchbase-connect-14 , unzip and open CouchbaseConnect2014.sln in your IDE.

2. Open Renderers/CarouselLayoutrenderer.cs file in the CouchbaseConnect2014.Android project.

3. Place a breakpoint on line 41:
_scrollView.HorizontalScrollBarEnabled = false;

4. Deploy the Android app to Simulator/Device

5. When the breakpoint is hit, note that you have a reference to the HorizontalScrollView in _scrollView variable

6. Update the Forms packages in CouchbaseConnect2014.Android project to 1.4.1

7. Deploy the Android app again

Expected result: When breakpoint is hit, _scrollView will not be null and will have a reference to HorizontalScrollView.

Actual result: _scrollView is null.

## My environment:

=== Xamarin Studio ===

Version 5.8.2 (build 7)
Installation UUID: 2dc9022f-f9a8-424f-8284-bf224cbbfde0
	Mono 3.12.1 ((detached/0849ec7)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312010003

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.Mac ===

Version: (Business Edition)

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 981acb3
Build date: 2015-03-25 14:21:05-0400

=== Build Information ===

Release ID: 508020007
Git revision: 067ed06873402cf780f8a0899bb332c2a1c0af22
Build date: 2015-03-27 14:17:13-04
Xamarin addins: 02510c4990dee3475c282b3182d588975a63ff07

=== Operating System ===

Mac OS X 10.10.3
Darwin Jons-iMac.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 1 Jon Goldberger [MSFT] 2015-04-10 15:36:56 UTC
Note: A workaround exists by using the code snippet above in OnDraw instead of OnElementChanged in the ScrollViewRenderer