views:

379

answers:

3

I have a simple XAML page that load fine when it is loaded as part of any application within Visual Studio. However, when I deploy this application using ClickOnce, I get the following exception:

Type : System.Windows.Markup.XamlParseException, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
    Message :  Unable to cast object of type 'System.Windows.Controls.Grid' to type 'EMS.Controls.Dictionary.StatusBarControl'.  Error at object 'System.Windows.Controls.Grid' in markup file 'EMS.Controls.Dictionary;component/views/statusbarcontrol.xaml'.
Source : PresentationFramework
Help link : 
LineNumber : 0
LinePosition : 0
KeyContext : 
UidContext : 
NameContext : 
BaseUri : pack://application:,,,/EMS.Controls.Dictionary;component/views/statusbarcontrol.xaml
Data : System.Collections.ListDictionaryInternal
TargetSite : Void ThrowException(System.String, System.Exception, Int32, Int32, System.Uri, System.Windows.Markup.XamlObjectIds, System.Windows.Markup.XamlObjectIds, System.Type)
Stack Trace :    at System.Windows.Markup.XamlParseException.ThrowException(String message, Exception innerException, Int32 lineNumber, Int32 linePosition, Uri baseUri, XamlObjectIds currentXamlObjectIds, XamlObjectIds contextXamlObjectIds, Type objectType)
   at System.Windows.Markup.XamlParseException.ThrowException(ParserContext parserContext, Int32 lineNumber, Int32 linePosition, String message, Exception innerException)
   at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)
   at System.Windows.Markup.BamlRecordReader.Read(Boolean singleRecord)
   at System.Windows.Markup.TreeBuilderBamlTranslator.ParseFragment()
   at System.Windows.Markup.TreeBuilder.Parse()
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at EMS.Controls.Dictionary.StatusBarControl.InitializeComponent()
   at EMS.Controls.Dictionary.StatusBarControl..ctor(IDataView content)
   at OCC600.ReportManager.ReportPresenter.ShowQueryView(Object arg, Boolean bringForward, Type selectedDataType)
   at OCC600.ReportManager.ReportPresenter..ctor(IUnityContainer container)
   at OCC600.ReportManager.Module.Initialize()
   at Microsoft.Practices.Composite.Modularity.ModuleLoader.Initialize(ModuleInfo[] moduleInfos)

    Inner Exception
    ---------------
    Type : System.InvalidCastException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
    Message : Unable to cast object of type 'System.Windows.Controls.Grid' to type 'EMS.Controls.Dictionary.StatusBarControl'.
    Source : EMS.Controls.Dictionary
    Help link : 
    Data : System.Collections.ListDictionaryInternal
    TargetSite : Void System.Windows.Markup.IComponentConnector.Connect(Int32, System.Object)
    Stack Trace :    at EMS.Controls.Dictionary.StatusBarControl.System.Windows.Markup.IComponentConnector.Connect(Int32 connectionId, Object target)
       at System.Windows.Markup.BamlRecordReader.ReadConnectionId(BamlConnectionIdRecord bamlConnectionIdRecord)
       at System.Windows.Markup.BamlRecordReader.ReadRecord(BamlRecord bamlRecord)

The XAML page is given below:

<cdic:ResultSetControl 
    x:Class="EMS.Controls.Dictionary.StatusBarControl"
    xmlns:dc="clr-namespace:DevComponents.WpfRibbon;assembly=DevComponents.WpfRibbon"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"                          
    xmlns:cdic="clr-namespace:EMS.Controls.Dictionary.Primitives"
    xmlns:dicutil="clr-namespace:OCC600.Infrastructure.Dictionary.Utility;assembly=EMS.Infrastructure.Dictionary"
    Loaded="ResultSetControl_Loaded">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="../Resources/Styles.xaml"/>                
            </ResourceDictionary.MergedDictionaries>
            <BooleanToVisibilityConverter x:Key="BooToVisConv"/>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid Name="panel" >
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="21"/>
        </Grid.RowDefinitions>        
        <StatusBar Name="statusBar" Grid.Row="1">
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <DockPanel LastChildFill="False"/>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>

            <StatusBarItem Margin="10,0, 10, 0">                
                <TextBlock Text="{Binding CountText}" Padding="5,0"/>                
            </StatusBarItem>                       

            <StatusBarItem Margin="10,0">
                <TextBlock Text="{Binding MemoryUsageText}" Padding="5,0"/>
            </StatusBarItem>

            <StatusBarItem Margin="10,0" MaxWidth="400">
                <TextBlock  Text="{Binding StatusReport.Summary}" Padding="5,0" />
            </StatusBarItem>

            <ProgressBar Margin="20,0" Name="progBar" Width="150" Height="13" Visibility="Collapsed" >                
                <ProgressBar.ContextMenu>                   
                    <ContextMenu Name="ctxMenu" ItemsSource="{Binding ActiveWorkItems}" 
                                 Visibility="{Binding Path=ActiveWorkItems.HasItems, Converter={StaticResource BooToVisConv}}">                        
                        <ContextMenu.ItemContainerStyle>
                            <Style TargetType="{x:Type MenuItem}">                                
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="{x:Type MenuItem}">
                                            <StackPanel Height="20" Margin="10,0" Orientation="Horizontal" HorizontalAlignment="Left">
                                                <TextBlock Text="{Binding Path=Name, Mode=OneTime}" 
                                                           Foreground="Black" VerticalAlignment="Center" HorizontalAlignment="Left" />
                                                <ToggleButton  Style="{StaticResource vistaGoldenToggleButtonStyle}"
                                                         Padding="5,0" Content="Cancel" IsChecked="{Binding Cancel}"                                                         
                                                         Margin="10,0,0,0" >                                                    
                                                </ToggleButton>
                                            </StackPanel>                                                                                      
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </ContextMenu.ItemContainerStyle>                                                
                    </ContextMenu>
                </ProgressBar.ContextMenu>
            </ProgressBar>

            <StatusBarItem Margin="10,0" MaxWidth="400" HorizontalAlignment="Right">
                <StackPanel Orientation="Horizontal">
                    <TextBlock  Text="Last Update:" Padding="5,0" />
                    <TextBlock  Text="{Binding TimeStamp}" Padding="5,0" />                    
                </StackPanel>                
            </StatusBarItem>


            <!-- TODO:  Put checkmark if all is well, or error if connection failed-->
            <StatusBarItem Style="{DynamicResource {ComponentResourceKey 
                TypeInTargetAssembly=dc:Ribbon, ResourceId=StatusBarItemAlt}}" 
                           DockPanel.Dock="Right" Padding="6,0,32,0" >      

                    <cdic:SplitButton Margin="5,0" Padding="5,2"                             
                            Style="{DynamicResource {ComponentResourceKey 
                        TypeInTargetAssembly={x:Type cdic:SplitButtonResources}, ResourceId=vistaSplitButtonStyle}}" 
                                       Mode="Split">
                        <cdic:SplitButton.ContextMenu>
                            <ContextMenu >
                                <MenuItem Header="Refresh Now" Command="{Binding ToggleConnectivityCmd}"
                                          CommandParameter="false"/>
                                <MenuItem IsCheckable="True" 
                                          IsChecked="{Binding ConnectState, Converter={StaticResource isFailedConverter}}"
                                          CommandParameter="{Binding RelativeSource={x:Static RelativeSource.Self},
                                    Path=IsChecked}"
                                          Header="Work Offline" Command="{Binding ToggleConnectivityCmd}"/>
                        </ContextMenu>                            
                        </cdic:SplitButton.ContextMenu>
                    <cdic:SplitButton.Content>
                        <StackPanel Orientation="Horizontal">
                            <Image                             
                                x:Name="img"     
                                Source="{Binding ConnectState, Converter={StaticResource imageConverter}}"
                                Width="16" Height="16" HorizontalAlignment="Center" VerticalAlignment="Center"/>
                            <TextBlock Text="{Binding ConnectState}" Padding="3,0,0,0"/>                            
                        </StackPanel>                        
                    </cdic:SplitButton.Content>
                </cdic:SplitButton>                                        
            </StatusBarItem>            

        </StatusBar>
    </Grid>    
</cdic:ResultSetControl>

The error just seems to have come out of no where. Any ideas?

TIA.

A: 

Guys, problem has been narrowed down to my .proj file. If I manually publish the application using ClickOnce, it executes no problem. However, if I publish the application using the .proj file given below, application throws XAML parsing exception upon startup.

<?xml version="1.0" encoding="utf-8"?>
<Project InitialTargets="GetDefaults;SetDefaults;DoBuild"
         DefaultTargets="DoPublish" 
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003" 
         ToolsVersion="3.5">      

  <PropertyGroup Condition="!Exists('$(BuildMode)')">  
    <BuildMode>Release</BuildMode>
  </PropertyGroup>

  <!-- Set default version in case text file is corrupt.-->
  <PropertyGroup>            
    <MajorVersion>1</MajorVersion>
    <MinorVersion>0</MinorVersion>
    <BuildNumber>0</BuildNumber>
    <Revision>0</Revision>
  </PropertyGroup>
  <PropertyGroup>
    <Version>$(MajorVersion).$(MinorVersion).$(BuildNumber).$(Revision)</Version>        
    <ClickOnceInstallDirectory>C:\Inetpub\wwwroot\OCC600\</ClickOnceInstallDirectory>
    <VersionFilePath>C:\Inetpub\wwwroot\OCC600\Version.txt</VersionFilePath>
  </PropertyGroup>

  <!-- Grab previous version from file-->
  <!-- Alternate versioning 
        VersionFile="Version.txt" 
        BuildType="Automatic" 
        RevisionType="Increment"
        StartDate="September 5, 2009"
  -->
  <Target Name="GetDefaults" >
    <MSBuild.Community.Tasks.Version 
      VersionFile="$(VersionFilePath)" 
      BuildType="None" 
      RevisionType="Increment"
      StartDate="September 5, 2009">
      <Output TaskParameter="Major" PropertyName="Major" />
      <Output TaskParameter="Minor" PropertyName="Minor" />
      <Output TaskParameter="Build" PropertyName="Build" />
      <Output TaskParameter="Revision" PropertyName="Revision" />
    </MSBuild.Community.Tasks.Version>
    <CreateProperty Value="$(Major).$(Minor).$(Build).$(Revision)">
      <Output TaskParameter="Value" PropertyName="PreviousVersion" />
    </CreateProperty>
    <Message Text="Previous version from file = $(PreviousVersion)"/>
    <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="Major" Value="$(Major)" />
    <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="Minor" Value="$(Minor)" />
    <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="Build" Value="$(Build)" />
    <MSBuild.ExtensionPack.Computer.EnvironmentVariable TaskAction="Set" Variable="Revision" Value="$(Revision)" />
</Target>

  <!-- TODO:  impose additional condition to validate version copied-->
  <Target Name="SetDefaults" Condition="$(PreviousVersion) != ''">
    <CreateProperty Value="$(PreviousVersion)">
      <Output TaskParameter="Value" PropertyName="Version" />
    </CreateProperty>    
    <Message Text="Default version set to $(Version)"/>
  </Target>

  <!-- Build occ600 and get CurrentBuildVersion environment variable set by Infrastructure.Shell.csproj-->
  <Target Name="DoBuild" >
    <Message Text="Building occ600 in $(BuildMode) mode"/>
    <!--<Exec Command="CALL vsvars32.bat"
         Condition="'$(DevEnvDir)' == ''"
          WorkingDirectory="$(VS90COMNTOOLS)" />-->

    <!--Build and version EMS.Controls.Dictionary-->
    <MSBuild Projects="..\..\Source\Libraries\ControlsDictionary\EMS.Controls.Dictionary.csproj" Targets="Clean;Build"
           Properties="ApplicationVersion=$(Version);Configuration=$(BuildMode)" />
    <Message Text="Built EMS.Controls.Dictionary version = $(Version) in $(BuildMode) mode"/>

    <!--Build and version EMS ControlsLibrary-->
    <MSBuild Projects="..\..\Source\Libraries\ControlsLibrary\ControlsLibrary.csproj" Targets="Clean;Build"
           Properties="ApplicationVersion=$(Version);Configuration=$(BuildMode)" />
    <Message Text="Built EMS ControlsLibrary version = $(Version) in $(BuildMode) mode"/>

    <!--Build and version EMS.ArcGISLibary using ArcGIS Engine-->
    <MSBuild Projects="..\..\Source\GIS\Modules\ArcGIS\Winforms\EMS.ArcGIS.Engine.csproj" Targets="Clean;Build"
           Properties="ApplicationVersion=$(Version);Configuration=$(BuildMode)" />
    <Message Text="Built EMS ArcGISLibrary version = $(Version) in $(BuildMode) mode"/>

    <!--Build and version EMS.ArcGIS.WPF Libary using ArcGIS API for WPF-->
    <MSBuild Projects="..\..\Source\GIS\Modules\ArcGIS\WPF\EMS.ArcGIS.WPF.csproj" Targets="Clean;Build"
           Properties="ApplicationVersion=$(Version);Configuration=$(BuildMode)" />
    <Message Text="Built EMS.ArcGIS.WPF version = $(Version) in $(BuildMode) mode"/>

    <!--Build and version EMS.GoogleEarthLibrary-->
    <MSBuild Projects="..\..\Source\GIS\Modules\GoogleEarth\EMS.GoogleEarthLibrary.csproj" Targets="Clean;Build"
           Properties="ApplicationVersion=$(Version);Configuration=$(BuildMode)" />
    <Message Text="Built EMS GoogleEarthLibrary version = $(Version) in $(BuildMode) mode"/>

    <!--Build and version EMS.OGC.WFS-->
    <MSBuild Projects="..\..\Source\Extensions\OGC_WFS\EMS.OGC.WFS\EMS.OGC.Web.csproj" Targets="Clean;Build"
           Properties="ApplicationVersion=$(Version);Configuration=$(BuildMode)" />
    <Message Text="Built EMS OGC Web plugin = $(Version) in $(BuildMode) mode"/>

    <!--Build and version OCC 600 OI-->
    <MSBuild Projects="..\..\Source\OCC600Release.sln" Targets="Clean;Build" 
             Properties="ApplicationVersion=$(Version);Configuration=$(BuildMode)" />   
    <Message Text="Built occ600 version = $(Version) in $(BuildMode) mode"/>
  </Target>   

  <!-- Publish app using this version-->
  <Target Name="DoPublish">
    <!--<Exec Command="CALL vsvars32.bat" 
          Condition="'$(DevEnvDir)' == ''"
           WorkingDirectory="$(VS90COMNTOOLS)"  />-->

    <Message Text="Publising occ600 Version $(Version)"/>    
    <MSBuild Projects="..\..\Source\Infrastructure\Infrastructure.Shell\Infrastructure.Shell.csproj" Targets="Publish"
             Properties="ApplicationVersion=$(Version);Configuration=$(BuildMode);PublishDir=$(ClickOnceInstallDirectory)" />

    <Message Text="Done publishing application version $(Version). Updating publish.htm"/>
    <FileUpdate
      Files="publish.htm" 
      Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
      ReplacementText="$(Version)"
      Condition="'$(BuildMode)' == 'Release'"  />
    <Message Text="Done updating publish.htm"/>
    <FileUpdate
     Files="Version.txt"
     Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
     ReplacementText="$(Version)"
     Condition="'$(BuildMode)' == 'Release'"  />
    <Message Text="Done updating version.txt"/>

    <Copy SourceFiles="publish.htm" DestinationFiles="$(ClickOnceInstallDirectory)\publish.htm" />    
  </Target>

  <Import Project="..\..\Source\Infrastructure\Infrastructure.Shell\Infrastructure.Shell.csproj"/>
  <Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets"/>
  <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.VersionNumber.targets" />
  <Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks" />


</Project>
e28Makaveli
A: 

Have this problem been solved? I met the same problem. I try to comment out any thing to figure the root problem. Now I just know if I add any event handler to that object, then it will fail.

ChrisTorng
A: 

BUMP

I've encountered almost EXACTLY the same issue. Anyone out there have a solution to this?

Russ