floydpink / CachedImage

A WPF control that wraps the Image control to enable file-system based caching
http://floydpink.github.io/CachedImage/
MIT License
69 stars 22 forks source link

Exception during using CachedImage item in an ItemTemplate inside a ListView of a UserControl #9

Closed touhiDroid closed 6 years ago

touhiDroid commented 6 years ago

I was using the cachedImage:Image element inside the DataTemplate of a ListView inside a UserControl. The direct builds, both in Debug & Release flavors, were working just fine - but when I generated the setup file using Inno-setup & installed that in other machines, the page started crashing with the following log:

Set property 'System.Windows.Controls.ItemsControl.ItemTemplate' threw an exception.
Stack Trace:    at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at MyApp.MyWindow.InitializeComponent() in E:\w_Development\DotNet\MyApp\MyWindow.xaml:line 1
   at MyApp.MyWindow..ctor(Window window) in E:\w_Development\DotNet\MyApp\MyWindow.xaml.cs:line 54
   at MyApp.MainWindow.<NavigateWithDelay>d__3.MoveNext() in E:\w_Development\DotNet\MyApp\MainWindow.xaml.cs:line 35
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<>c.<ThrowAsync>b__6_0(Object state)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.DispatcherOperation.InvokeImpl()
   at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state)
   at MS.Internal.CulturePreservingExecutionContext.CallbackWrapper(Object obj)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at MS.Internal.CulturePreservingExecutionContext.Run(CulturePreservingExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Windows.Threading.DispatcherOperation.Invoke()
   at System.Windows.Threading.Dispatcher.ProcessQueue()
   at System.Windows.Threading.Dispatcher.WndProcHook(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
   at MS.Win32.UnsafeNativeMethods.DispatchMessage(MSG& msg)
   at System.Windows.Threading.Dispatcher.PushFrameImpl(DispatcherFrame frame)
   at System.Windows.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at System.Windows.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at MyApp.App.Main()

The DataTemplate is like the following:

<DataTemplate x:Key="MyItemTemplate">
            <Grid Margin="8 4 8 4" Background="#7aBa23">
                <Grid Margin="2" Background="White">
                    <!--<Grid.Effect>
                    <DropShadowEffect BlurRadius="5" ShadowDepth="2"/>
                </Grid.Effect>-->
                    <Grid.RowDefinitions>
                        <RowDefinition Height="{Binding MY_TILE_H}" MaxHeight="240"/>
                        <RowDefinition Height="32"/>
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="{Binding MY_TILE_W1}" MaxWidth="256"/>
                        <ColumnDefinition Width="{Binding MY_TILE_W2}" MaxWidth="124"/>
                    </Grid.ColumnDefinitions>

                    <!--<Image Grid.Row="0" Grid.ColumnSpan="2"
                       Width="{Binding MY_TILE_W}" MaxWidth="380" 
                       Height="{Binding MY_TILE_H}" MaxHeight="240" 
                       Stretch="UniformToFill">
                        <Image.Source>
                            <BitmapImage UriCachePolicy="Revalidate"  
                                         UriSource="{Binding ImageUrl}" 
                                         CreateOptions="IgnoreImageCache"
                                         CacheOption="OnLoad"/>
                        </Image.Source>
                    </Image>-->
                    <cachedImage:Image Grid.Row="0" Grid.ColumnSpan="2"
                       Width="{Binding MY_TILE_W}" MaxWidth="380" 
                       Height="{Binding MY_TILE_H}" MaxHeight="240" 
                       Stretch="UniformToFill"
                       ImageUrl="{Binding ImageUrl}"/>
               ... ... ...
                </Grid>
            </Grid>
        </DataTemplate>

The custom UserControl, used under a TabControl in the MyWindow.xaml has the following skeleton:

<materialDesign:DialogHost x:Name="DialogProgress">
        <materialDesign:DialogHost.DialogContent>
            <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center" 
                        Height="64" Width="Auto" x:Name="StpProgContent"
                        Orientation="Horizontal" Background="#7ABA23">
                <ProgressBar Width="24" Height="24" Margin="16"
                    Foreground="White"
                    Style="{DynamicResource MaterialDesignCircularProgressBar}"
                    IsIndeterminate="True"
                    Value="33"/>
                <TextBlock x:Name="ProgMsg" Text="Posting your order ..." 
                           Padding="12 8 12 8" VerticalAlignment="Center" 
                           Foreground="White" FontWeight="DemiBold" FontSize="18"/>
            </StackPanel>
        </materialDesign:DialogHost.DialogContent>
        <Grid Background="#FaFaFa">
            <Grid.RowDefinitions>
                <RowDefinition Height="3*"/>
                <RowDefinition Height="2*"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="512"/>
            </Grid.ColumnDefinitions>

       ... ... ...

            <ListView x:Name="MyListView" Grid.Column="0" 
                      ScrollViewer.VerticalScrollBarVisibility="Visible"
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                      ItemTemplate="{DynamicResource MyItemTemplate}" 
                      Grid.RowSpan="2" Margin="0 60 0 0"
                      SelectionChanged="MyListView_SelectionChanged">
                <!--PreviewMouseDown="MyListView_MouseDown"-->
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <WrapPanel Orientation="Horizontal"/>
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
            </ListView>
        ... ... ...

        </Grid>
    </materialDesign:DialogHost>

I really like the result this library is delivering in the direct builds, but is there any kind of clash with InnoSetup or any other view in release-mode with the above codes that it's crashing?

I am not an expert in WPF or .Net - but any kind of help can allow me to explore & solve this issue in the right way.

Btw, thanks for the library.

touhiDroid commented 6 years ago

Damn it - I forgot to add the CachedImage.dll reference in my InnoSetup script! Sorry to bother.

floydpink commented 6 years ago

Glad to know the issue is resolved. 🙂