XamlAnimatedGif/WpfAnimatedGif

Exception from F# WPF

giuliohome opened this issue · 6 comments

I'm getting this exception

Cannot set unknown member '{http://wpfanimatedgif.codeplex.com}ImageBehavior.AnimatedSource'."}
	System.Exception {System.Xaml.XamlObjectWriterException}

I'm in F# App.fs at startup

[<STAThread>]
[<EntryPoint>]
let main argv =
    try
        if SynchronizationContext.Current = null then
            DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher)
            |> SynchronizationContext.SetSynchronizationContext

and the xaml is the standard

xmlns:gif="http://wpfanimatedgif.codeplex.com"
...
<Image gif:ImageBehavior.AnimatedSource="gif\spinner1.gif"  ...

Solved by using a C# User Control (then imported into the F# WPF project)

I can close the issue with my simple workaround. I think the root cause is due to some event handling inside this project that is not compatible with the more limited xaml functionalities in FsXaml for F#.
If anyone is willing to get a deeper insight and to reenginer this package for direct use in such a F# project, then welcome and feel free to reopen...

Hi @giuliohome,

Thanks for reporting this. I have no idea what in the library could be causing this. I suspect it's related to how XAML is handled in F# project, but I have no experience with this. As another workaround, you could set AnimatedSource in code behind (ImageBehavior.SetAnimatedSource(imageControl, image))

Thank you very much for your suggestion. I will try soon and I think it will work. It is exactly what I also wanted to try. I'll let you know.

__ start of edit

BTW I suspect that this (look at the exception in the bottom) should be reopen as a memory leak somewhere when used in some sort of page transition or similar

So I am definetely switching from my initial C# user control workaround to XamlAnimatedGif (which is also entirely in F#)

AnimationBehavior.SetSourceUri(mainPage.wait1, (new Uri("pack://application:,,,/spinner1.gif")))
AnimationBehavior.SetSourceUri(mainPage.wait2, (new Uri("pack://application:,,,/giphy.gif")))

__ end of edit

Well no, the code behind gives more or less the same result (see below more details about the exception), but I have to add that this exception happens in my case when the image is encapsulated in another user UserControl in a PageTransition and not when the image is simply in the main window (so I'm not sure which is the root cause).

But there is another good news, your other project XamlAnimatedGif works fine

xmlns:gif2="clr-namespace:XamlAnimatedGif;assembly=XamlAnimatedGif"
...
<Image gif2:AnimationBehavior.SourceUri="C:\...\giphy.gif" 

the exc that I mention, just fyi, but again now I have two solutions, so no real problem for me.
In conclusion thank you so much again for having open sourced these cool wpf gif decoders!

Exception thrown: 'System.Runtime.InteropServices.COMException' in PresentationCore.dll
System.Runtime.InteropServices.COMException (0x88980003): Eccezione da HRESULT: 0x88980003
   in System.Windows.Media.Imaging.WriteableBitmap.InitFromBitmapSource(BitmapSource source)
   in System.Windows.Media.Imaging.WriteableBitmap.CopyCommon(WriteableBitmap sourceBitmap)
   in System.Windows.Media.Imaging.WriteableBitmap.CloneCurrentValueCore(Freezable sourceFreezable)
   in System.Windows.Freezable.CloneCoreCommon(Freezable sourceFreezable, Boolean useCurrentValue, Boolean cloneFrozenValues)
   in System.Windows.Freezable.CloneCurrentValueCore(Freezable sourceFreezable)
   in System.Windows.Freezable.CloneCurrentValue()
   in System.Windows.Media.Animation.ObjectKeyFrameCollection.CloneCurrentValueCore(Freezable sourceFreezable)
   in System.Windows.Freezable.CloneCurrentValue()
   in System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames.CopyCommon(ObjectAnimationUsingKeyFrames sourceAnimation, Boolean isCurrentValueClone)
   in System.Windows.Media.Animation.ObjectAnimationUsingKeyFrames.GetCurrentValueAsFrozenCore(Freezable source)
   in System.Windows.Freezable.GetCurrentValueAsFrozen()
   in System.Windows.Media.Animation.Clock..ctor(Timeline timeline)
   in System.Windows.Media.Animation.AnimationTimeline.AllocateClock()
   in System.Windows.Media.Animation.Clock.AllocateClock(Timeline timeline, Boolean hasControllableRoot)
   in System.Windows.Media.Animation.Clock.BuildClockTreeFromTimeline(Timeline rootTimeline, Boolean hasControllableRoot)
   in WpfAnimatedGif.ImageAnimationController..ctor(Image image, ObjectAnimationUsingKeyFrames animation, Boolean autoStart)
   in WpfAnimatedGif.ImageBehavior.InitAnimationOrImage(Image imageControl)
   in WpfAnimatedGif.ImageBehavior.ImageControlLoaded(Object sender, RoutedEventArgs e)
   in System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs)

It doesn't seem to be the same problem. A COMException usually indicates a problem at a pretty low level, and honestly, it's so deep into WPF code that I have no idea what could be causing it...

Anyway, I'm glad you were able to use XamlAnimatedGif instead