XamarinCommunityToolkit
XamarinCommunityToolkit copied to clipboard
[Bug] IOS FFImageLoading exception
Description
Starting from version 2.0.2 i have this exception just on IOS with library FFImageLoading. thanks
Stack Trace
Unhandled Exception: System.InvalidCastException: Specified cast is not valid. at Xamarin.CommunityToolkit.iOS.Effects.IconTintColorEffectRouter.ImageViewTintColorPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x0001d] in <4d8fe5c5405e44d08fa28bbb90fc91b0>:0 at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs) at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:266 at Xamarin.Forms.Element.OnPropertyChangefd (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:362 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attr ibutes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:510 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0004d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:374 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindablePropertyKey propertyKey, System.Object value) [0x0000e] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:356 at FFImageLoading.Forms.CachedImage.SetIsLoading (System.Boolean isLoading) [0x00000] in C:\projects\ffimageloading\source\FFImageLoading.Forms\CachedImage.cs:575 at FFImageLoading.Forms.Platform.CachedImageRenderer+<>c__DisplayCla ss13_0.<ImageLoadingSizeChanged>b__0 () [0x00029] in C:\projects\ffimageloading\source\FFImageLoading.Forms.Touch\CachedImageRenderer.cs:263 at FFImageLoading.Helpers.MainThreadDispatcher+<>c__DisplayClass2_0.<PostAsync>b__0 () [0x00000] in C:\projects\ffimageloading\source\FFImageLoading.Shared.IosMac\Helpers\MainThreadDispatcher.cs:60 --- End of stack trace from previous location where exception was thrown ---
at FFImageLoading.Forms.Platform.CachedImageRenderer.ImageLoadingSizeChanged (FFImageLoading.Forms.CachedImage element, System.Boolean isLoading) [0x00083] in C:\projects\ffimageloading\source\FFImageLoading.Forms.Touch\CachedImageRenderer.cs:255 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_1 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1037 at System.Threading.QueueUserWorkItemCallback.WaitCallback_Cont ext (System.Object state) [0x0000d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1370 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:968 at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:910 at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x00021] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1341 at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:899 at ObjCRuntime.Runtime.ThreadPoolDispatcher (System.Func`1[TResult] callback) [0x00006] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:327 at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00009] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1258
2022-07-21 13:17:37.096 TestApp.iOS[80201:5283741] Unhandled managed exception: Specified cast is not valid. (System.InvalidCastException) at Xamarin.CommunityToolkit.iOS.Effects.IconTintColorEffectRouter.ImageViewTintColorPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x0001d] in <4d8fe5c5405e44d08fa28bbb90fc91b0>:0 at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs) at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:266 at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Element.cs:362 at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFl ags attributes, System.Boolean silent) [0x00114] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:510 at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0004d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:374 at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindablePropertyKey propertyKey, System.Object value) [0x0000e] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:356 at FFImageLoading.Forms.CachedImage.SetIsLoading (System.Boolean isLoading) [0x00000] in C:\projects\ffimageloading\source\FFImageLoading.Forms\CachedImage.cs:575 at FFImageLoading.Forms.Platform.CachedImageRenderer+<>c__Di splayClass13_0.<ImageLoadingSizeChanged>b__0 () [0x00029] in C:\projects\ffimageloading\source\FFImageLoading.Forms.Touch\CachedImageRenderer.cs:263 at FFImageLoading.Helpers.MainThreadDispatcher+<>c__DisplayClass2_0.<PostAsync>b__0 () [0x00000] in C:\projects\ffimageloading\source\FFImageLoading.Shared.IosMac\Helpers\MainThreadDispatcher.cs:60 --- End of stack trace from previous location where exception was thrown ---
at FFImageLoading.Forms.Platform.CachedImageRenderer.ImageLoadingSizeChanged (FFImageLoading.Forms.CachedImage element, System.Boolean isLoading) [0x00083] in C:\projects\ffimageloading\source\FFImageLoading.Forms.Touch\CachedImageRenderer.cs:255 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_1 (System.Object state) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/AsyncMethodBuilder.cs:1037 at System.Threading.QueueUserWorkItemCallback.WaitCallb ack_Context (System.Object state) [0x0000d] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1370 at System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00071] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:968 at System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, System.Object state, System.Boolean preserveSyncCtx) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/executioncontext.cs:910 at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem () [0x0 0021] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1341 at System.Threading.ThreadPoolWorkQueue.Dispatch () [0x00074] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:899 at ObjCRuntime.Runtime.ThreadPoolDispatcher (System.Func`1[TResult] callback) [0x00006] in /Users/builder/azdo/_work/1/s/xamarin-macios/src/ObjCRuntime/Runtime.cs:327 at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback () [0x00009] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/threading/threadpool.cs:1258
Link to Reproduction Sample
Steps to Reproduce
Expected Behavior
Actual Behavior
Basic Information
- Version with issue: >=2.0.2
- Last known good version: 2.0.1
- IDE: Visual studio 2022
- Platform Target Frameworks:
- iOS: 15.5
- Android:
- UWP:
- Android Support Library Version:
- Nuget Packages:
- Affected Devices:
Workaround
Use old version 2.0.1
Reproduction imagery
@TheSundayDev can you please fill in the end parts on how you can reproduce this? Ideally with a reproduction sample for us
hi, i'm going to prepare a test project, thanks
hi all. the problem is this: xct:IconTintColorEffect.TintColor="#039BE5" when used with ffimageloading:CachedImage just need to have a page with this (the issue is only on ios, v2.0.5):
xmlns:ffimageloading="clr-namespace:FFImageLoading.Forms;assembly=FFImageLoading.Forms" xmlns:xct="http://xamarin.com/schemas/2020/toolkit"
<ContentPage.Content> <StackLayout> <ffimageloading:CachedImage DownsampleToViewSize="true" WidthRequest="30" HeightRequest="30" VerticalOptions="Center" HorizontalOptions="Center" Source="ok.png" xct:IconTintColorEffect.TintColor="#039BE5" ></ffimageloading:CachedImage>
</StackLayout>
</ContentPage.Content>
this instead works <Image WidthRequest="30" HeightRequest="30" VerticalOptions="Center" HorizontalOptions="Center" Source="ok.png" xct:IconTintColorEffect.TintColor="#039BE5"></Image>
I suspect it is because the FFImageLoading implementation is not of type Image as per this line https://github.com/xamarin/XamarinCommunityToolkit/blob/299fac61a991d5ed0aac925b07e404fcb22c6f3e/src/CommunityToolkit/Xamarin.CommunityToolkit/Effects/IconTintColor/IconTintColorEffectRouter.ios.cs#L92
The toolkit cannot know about specific things from another library. We could check to see if the Element is of type Image rather than casting but that won't mean the effect will work for you.
I do believe that FFImageLoading does support some level of image tinting itself which may be worth investigating
hi, FFImageLoading last version is dated 5/20/2019. Till version 2.0.1 of XCT everythink was working, so i suppose that something happen starting from version 2.0.2 of XCT. thanks
Hi guys, any news on this? thanks a lot for your help!
Can you please provide a repro?
Test.zip Try this, thanks
Thanks @TheSundayDev but we aren't downloading zip files. Can you push it to github and share the link?
done https://github.com/TheSundayDev/test
Thanks for the repro. I'll aim to take a look at this over the next week
hi, any news? thanks!
@TheSundayDev sorry for the delay. I checked your sample and the issue is that we can't cast FFImageLoading type to Image or IImageElement, even if the check is removed we can't make it work with the package.
Also our lib doesn't take any external dependency so we can't check for FFImageLoading types. I'm afraid to say that we can't do anything on our end.