Xamarin.forms: [Previewer] `SetDefaultActionBarTitleTextColor` prevents the Android previewer from working

Created on 15 Dec 2017  路  15Comments  路  Source: xamarin/Xamarin.Forms

Description

The SetDefaultActionBarTitleTextColor method (or any method for that matter) should not make assumption about a context being an Activity (that is never do ((Activity)_context)).

It should use the as operator and null-check the result instead (or ?. operator).

Steps to Reproduce

  1. Open a ContentPage xaml file with master Forms Previewer.
  2. Exception happens.

Expected Behavior

Works

Actual Behavior

Exception:

ERROR: : AndroidXamlRenderer had a rendering error: System.InvalidCastException: Specified cast is not valid.
at Xamarin.Forms.Platform.Android.Platform.SetDefaultActionBarTitleTextColor () in D:\agent\_work\1\s\Xamarin.Forms.Platform.Android\Platform.cs:924
at Xamarin.Forms.Platform.Android.Platform..ctor (Android.Content.Context context, System.Boolean embedded) in D:\agent\_work\1\s\Xamarin.Forms.Platform.Android\Platform.cs:64
at Xamarin.Forms.Platform.Android.Platform..ctor (Android.Content.Context context) in D:\agent\_work\1\s\Xamarin.Forms.Platform.Android\Platform.cs:1087

Basic Information

Screenshots

N/A

Reproduction Link

N/A

regression Android bug

All 15 comments

/cc @jassmith :)

Hey - this is a critical issue and we should be rolling out a fix at the earliest convenience. These unsafe casts are breaking the forms previewer in ways we cannot work around.

Just for bookkeeping, a quick git grep "(Activity)" has 27 hits which means we have at least 27 places to review/change. There could be more though.

while we're at it, SetDefaultActionBarTitleColor() isn't setting anything and should be renamed

@jassmith @davidortinau What's the ETA on fixing this? Ideally we'd have this fixed, tested and hotfixed before the end of the week as it is triggering a critical breakage in the previewer

Fix is underway. As soon as we know an ETA I'll share with you @alanmcgovern.

is this issue fixed ?

I've updated Xamarin and everything and tried countless folk remedies I've encountered on the net and I'm still encountering this exact issue.

@ctrexler Which version of Visual Studio are you running? Which version of Xamarin.Forms are you currently using?

@hartez : in my case, i am using Visual Studio 2017 community edition, Xamarin.Form 3.1.0.583944.

i tried by downgrading its different versions, no help.

@jlahare And you're getting the exact error message posted above? An InvalidCastException when calling SetDefaultActionBarTitleTextColor ()?

Are you on Mac or Windows?

i am using Xamarin.Form in Microsoft Visual Studio Community edition over Windows 10 O.S.

@hartez I'm also using Visual Studio 17 commutiy with the latest Xamarin 3.1 and yes I'm receiving the exact error message of an invalid cast for SetDefaultActionBarTitleTextColor (). Also, I'm on Windows 10, and it's a preview build to be honest.

I might've figured something out though. I found out that my project is a Portable Class Library which went obsolete about a year ago. I'm going to copy everything over to a new Standard Class Library today. Could that by chance cause the issue? I'll let you know what happens after I make the transition if I don't hear from you sooner.

Thanks for the quick response and sorry for my slow one. I just now saw the notification.

I still have this issue happening:

=== Visual Studio Community 2017 for Mac ===

Version 7.5.3 (build 7)
Installation UUID: f7b64361-98d4-4657-8a94-567d94b6c785
Runtime:
Mono 5.10.1.57 (2017-12/ea8a24b1bbf) (64-bit)
GTK+ 2.24.23 (Raleigh theme)
Xamarin.Mac 4.4.1.178 (master / eeaeb7e6)

Package version: 510010057

=== NuGet ===

Version: 4.3.1.4445

=== .NET Core ===

Runtime: Not installed
SDK: Not installed
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/msbuild/15.0/bin/Sdks

=== Xamarin.Profiler ===

Version: 1.6.2
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.2.1 (11766.1)
Build 8C1002

=== Xamarin.Mac ===

Version: 4.4.1.193 (Visual Studio Community)

=== Xamarin.Android ===

Version: 8.3.3.2 (Visual Studio Community)
Android SDK: /Users/Mattia/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
2.3 (API level 10)
4.4 (API level 19)
5.1 (API level 22)
7.1 (API level 25)
8.0 (API level 26)
8.1 (API level 27)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 28.0.0
SDK Build Tools Version: 27.0.3

Java SDK: /usr
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Inspector ===

Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1

=== Xamarin.iOS ===

Version: 11.12.0.4 (Visual Studio Community)
Hash: 64fece5f
Branch: d15-7
Build date: 2018-05-29 20:00:44-0400

=== Build Information ===

Release ID: 705030007
Git revision: 13cecd02aceddf29a1ed57b86f81c02994df1483
Build date: 2018-06-14 15:48:08-04
Xamarin addins: 7065de97cf22c9038fdc39dd627f2c30790fd8af
Build lane: monodevelop-lion-d15-7

=== Operating System ===

Mac OS X 10.11.6
Darwin 15.6.0 Darwin Kernel Version 15.6.0
Tue Jan 9 20:12:05 PST 2018
root:xnu-3248.73.5~1/RELEASE_X86_64 x86_64

To update my last post, after moving everything over to a new Standard Class Library, the Xamarin.Forms previewer started working immediately. I don't know if having a PCL was the route cause, I'm just following up with my experience regarding this issue.

Was this page helpful?
0 / 5 - 0 ratings