Select to view content in your preferred language

ESRI Object in ResourceDictionary throwing errors

2784
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
JenniferNery
Esri Regular Contributor
I just tried your PictureMarkerSymbol on my SL app. I only updated the Image Source to point to my own image file. And I'm able to switch back and forth on XAML and Design page without errors thrown.

But when running the SL app, I get error because of this typo. I think you meant "RenderTransform" without the space 🙂

Storyboard.TargetProperty="(  UIElement.RenderTransf orm).(ScaleTransform.ScaleX)" From="1" To="10"  


I don't know if it would help to share what the my map contained:
  <esri:Map x:Name="MyMap" >
   <esri:ArcGISTiledMapServiceLayer Url="http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_StreetMap_World_2D/MapServer" />
   <esri:GraphicsLayer ID="MyGraphicsLayer">
    <esri:GraphicsLayer.Graphics>     
     <esri:Graphic Symbol="{StaticResource AddressSearchMarkerSymbol}">
      <esri:MapPoint X="-117.22672317423" Y="33.9176215942354"/>
     </esri:Graphic>
    </esri:GraphicsLayer.Graphics>
   </esri:GraphicsLayer>
  </esri:Map>
0 Kudos
AndyWright
Frequent Contributor
Thanks for the quick reply Jennifer.  Yeh the RenderTransform thing is fine in my code.  I guess something must have happened when I copy/pasted things into my forum post. 

So you guys haven't had anyone else report this type of behavior?  Can you send me the header of your resource file so I can make sure I have all the proper references included?  This has been a problem for us since day one even for very simple ESRI resources like fill symbols.  It's very frustrating.
0 Kudos
JenniferNery
Esri Regular Contributor
Sure. This was the code I copied from your post, except the image source is modified to point to my image.

   xmlns:esri="http://schemas.esri.com/arcgis/client/2009">

    <Grid x:Name="LayoutRoot" Background="White">
  <Grid.Resources>  
   <esri:PictureMarkerSymbol x:Key="AddressSearchMarkerSymbol" Source="Images/vehicles/policecarL.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="Images/vehicles/policecarL.png" Height="30" Width="30" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Left="-15" Canvas.Top="-15" />

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


BTW, what version are you using? I'm testing this against 2.1 RC.

Also looking at the error messages you posted, the StackTrace do not include ESRI methods. Maybe check your project references, maybe one of the .NET assemblies could not be resolved.

What you can also do is create a new SL app, with only this symbol resource and the map I had in my earlier post.  See if with minimal code, you are able to switch back and forth XAML and Design tab. Sometimes identifying the real problem means you have to isolate a lot of other things to get to the real issue.
0 Kudos
AndyWright
Frequent Contributor
Jennifer,

It looks like you aren't using a separate resource dictionary in your example.  You've got the resources at the top of a XAML page with UI in it.  We have a separate file for our resource dictionary and it is then referenced within the App.xaml file like this ....

<Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="Themes/SRPMO_ResourceDictionary.xaml"/>
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>       
    </Application.Resources>

Can you give it a test run one more time with the same setup as us and see what happens?  I will try your suggestions as well.  Thanks ...

Andy
0 Kudos
AndyWright
Frequent Contributor
Oh, and we are using the 2.0 API ...
0 Kudos
JenniferNery
Esri Regular Contributor
Based on this documentation about ResouceDictionaries http://msdn.microsoft.com/en-us/library/cc903952%28VS.95%29.aspx, a ResrouceDictionary must only contain shareable objects (see "Objects For ResourceDictionary Usage" section)

In trying to reproduce the issue, I got compile time error: "element is already the child of another element", which lead me to the documentation above. I got read of the compile time error by creating a Style for the Symbol instead setting it's Template property. However, I got run-time errors since Symbol does not have Style property.

What I suggest you do then, is to add PictureMarkerSymbol resource in your UserControl, instead of as ResourceDictionary.
0 Kudos
AndyWright
Frequent Contributor
Thanks for the response Jennifer.  We are using MVVM in our application, so your suggestion is easier said than done but I'll figure out a way to make it work.  At least I have an explanation for why ESRI objects don't work in our resource dictionary.  Thanks for all your help with this.
0 Kudos
DavidMarley
Frequent Contributor
Andy (or Esri),

I realize this is an old post, but did you ever find a workaround for this? We are having this same issue when we try to keep our resources in an external resource dictionary. Having the symbols defined inside the user control is not really an acceptable woarkaround - or at a minimum it is a hassle and poor design.

Any workarounds?  Or perhaps this was addressed with a later version of the Esri Silverlight API?

We are using the Esri API 2.2, Silverlight 4 and VS 2010.

Thanks in advance,

Dave
0 Kudos
AndyWright
Frequent Contributor
I agree with you that it is a hassle and probably poor design, but we had to resort to creating ESRI resources in the XAML of our user controls or in the code behind.  There may be a better way of doing it now, but we never figured it out and ran into this early on in our learning cycle so we really haven't revisited it.  Sorry I can't be of more help.  We just bit the bullet on this one.
0 Kudos