Select to view content in your preferred language

ESRI Object in ResourceDictionary throwing errors

3182
12
11-08-2010 12:39 PM
AndyWright
Frequent Contributor
I created an ESRI PictureMarkerSymbol resource (shown below) in the Resource Dictionary file that my application uses.  Whenever that or any ESRI resource is in that Resource Dictionary my MainPage.xaml cannot be viewed in design mode.  I get a nasty error page in its place, which contains 3 different exceptions.  The minute I take the ESRI stuff out of my Resource Dictionary and rebuild the app, everything is fine back in the MainPage.xaml.  Has anyone had similar problems or know of a workaround to this issue?  Thanks in advance for any help you can provide ...

Andy

Here is the resource XAML ...

<esri:PictureMarkerSymbol x:Key="AddressSearchMarkerSymbol" Source="/SRPMO;component/Images/Tools/address_search.png" Height="30" Width="30">
        <esri:PictureMarkerSymbol.ControlTemplate>
            <ControlTemplate>
                <Canvas>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup x:Name="CommonStates">
                            <VisualState x:Name="MouseOver">
                                <Storyboard RepeatBehavior="ForEver">
                                    <DoubleAnimation BeginTime="0" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" From="1" To="10" Duration="00:00:01" />
                                    <DoubleAnimation BeginTime="0" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" From="1" To="10" Duration="00:00:01" />
                                    <DoubleAnimation BeginTime="0" Storyboard.TargetName="ellipse" Storyboard.TargetProperty="(UIElement.Opacity)" From="1" To="0" Duration="00:00:01" />
                                </Storyboard>
                            </VisualState>
                            <VisualState x:Name="Normal" />
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>

                    <Ellipse Height="10" Width="10" Canvas.Left="-5" Canvas.Top="-5" RenderTransformOrigin="0.5,0.5" x:Name="ellipse" IsHitTestVisible="False">
                        <Ellipse.RenderTransform>
                            <ScaleTransform />
                        </Ellipse.RenderTransform>
                        <Ellipse.Fill>
                            <RadialGradientBrush>
                                <GradientStop Color="#00FF0000" />
                                <GradientStop Color="#FFFF0000" Offset="0.25"/>
                                <GradientStop Color="#00FF0000" Offset="0.5"/>
                                <GradientStop Color="#FFFF0000" Offset="0.75"/>
                                <GradientStop Color="#00FF0000" Offset="1"/>
                            </RadialGradientBrush>
                        </Ellipse.Fill>
                    </Ellipse>
                    <Image x:Name="image" Source="/SRPMO;component/Images/Tools/address_search.png" Height="30" Width="30" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Left="-15" Canvas.Top="-15" />

                </Canvas>
            </ControlTemplate>
        </esri:PictureMarkerSymbol.ControlTemplate>
    </esri:PictureMarkerSymbol>



Here are the errors I am getting ...


ERROR 1:

System.Reflection.TargetInvocationException
Exception has been thrown by the target of an invocation.
   at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.RuntimeMethodHandle.InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, Signature sig, MethodAttributes methodAttributes, RuntimeType typeOwner)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)


ERROR 2:

System.InvalidOperationException
An unhandled exception was encountered while trying to render the current silverlight project on the design surface. To diagnose this failure, please try to run the project in a regular browser using the silverlight developer runtime.
   at Microsoft.Windows.Design.Platform.SilverlightViewProducer.OnUnhandledException(Object sender, ViewUnhandledExceptionEventArgs e)
   at Microsoft.Windows.Design.Platform.SilverlightViewProducer.SilverlightContentHost.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Designer.ZoomableViewPresenter.DesignerBackground.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Decorator.MeasureOverride(Size constraint)
   at Microsoft.Windows.Design.Interaction.DesignerView.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Designer.Viewport.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ScrollContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureCell(Int32 cell, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureCellsGroup(Int32 cellsHead, Size referenceSize, Boolean ignoreDesiredSizeU, Boolean forceInfinityV)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.ScrollViewer.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Grid.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at MS.Internal.Helper.MeasureElementWithSingleChild(UIElement element, Size constraint)
   at System.Windows.Controls.ContentPresenter.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Controls.Control.MeasureOverride(Size constraint)
   at System.Windows.FrameworkElement.MeasureCore(Size availableSize)
   at System.Windows.UIElement.Measure(Size availableSize)
   at System.Windows.Interop.HwndSource.SetLayoutSize()
   at System.Windows.Interop.HwndSource.set_RootVisualInternal(Visual value)
   at System.Windows.Interop.HwndSource.set_RootVisual(Visual value)
   at MS.Internal.DeferredHwndSource.ProcessQueue(Object sender, EventArgs e)


ERROR 3:

System.Exception
Error HRESULT E_FAIL has been returned from a call to a COM component.
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.XcpImports.FrameworkElement_MeasureOverride(FrameworkElement element, Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(Size availableSize)
   at System.Windows.FrameworkElement.MeasureOverride(IntPtr nativeTarget, Single inWidth, Single inHeight, Single& outWidth, Single& outHeight)
0 Kudos
12 Replies
DavidMarley
Frequent Contributor
Andy - Thanks for the quick reply.  We'll do the same, at least for now.  I'll post if I do ever find a work-around for this.

Dave
0 Kudos
DavidMarley
Frequent Contributor
I know this is an old thread, but at the Dev Summit I worked with an Esri developer to come up with a fix for this, and just today had the opportunity to apply it to my project. The fix/workaround for the error is to load the resource file from the code-behind rather than via XAML.  So here is the code snippet for my case, placed in the constructor of the control:

public Result()
{
    InitializeComponent();
    
    ResourceDictionary dict = new ResourceDictionary();
    dict.Source = new Uri("/SMART;component/Symbols/EsriSymbols.xaml", UriKind.Relative);
    LayoutRoot.Resources.MergedDictionaries.Add(dict);

    // . . . rest of contructor code...

}


Note that the syntax is very particular here about a couple of things:


  1. The Uri path - the first part ("/SMART") is the name of your XAP package that gets created on build (which is your project name unless you explicitely changed it).  the second part ("component/Symbols/EsriSymbols.xaml") must be the correct path including any subfolder that your style file is in.


  2. You must reference the resource dictionary correctly in the appropriate level of your view hierarchy (control vs. LayoutRoot vs. other) so in my case I am adding the resource to a Merged Dictionary that is part of LayoutRoot's resources.  You may need to modify this code to work for your particular situation.

For the sake of completeness, here is the corresponding XAML that establishes the Resource Dictionary that this additional source is added to:

    <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.Resources>
            <ResourceDictionary x:Key="MergedDictionaries">
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="/SMART;component/Style/Style.xaml"/>
                    <!-- Adding ResourceDictionary in this way results in 'Element is already the child of another element' error -->
                    <!-- <ResourceDictionary Source="/SMART;component/Symbols/EsriSymbols.xaml" /> -->
                </ResourceDictionary.MergedDictionaries>
            </ResourceDictionary>
RobHalko
Deactivated User

This was extremely helpful, thanks David.

I just wanted to add an additional bit of info. I had to add the dictionary to my entire application's resources, so they would be available when the main layout initializes - here is the slight variation in code-behind:

Application.Current.Resources.MergedDictionaries.Add(dict);

For the sake of completeness, here is the corresponding XAML that establishes the Resource Dictionary that this additional source is added to:

    <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Grid.Resources>
            <ResourceDictionary x:Key="MergedDictionaries">
                <ResourceDictionary.MergedDictionaries>
                    <ResourceDictionary Source="/SMART;component/Style/Style.xaml"/>
                    <!-- Adding ResourceDictionary in this way results in 'Element is already the child of another element' error -->
                    <!-- <ResourceDictionary Source="/SMART;component/Symbols/EsriSymbols.xaml" /> -->
                </ResourceDictionary.MergedDictionaries>
            </ResourceDicti

0 Kudos