WPF

2011-07-25 11 views
21

içinde cilt hata ayıklama nasıl yapılır VS2008, C# WPF, Excel AddIn; Bazı durumlarda altında, My eklentiWPF

A first chance exception of type 'System.InvalidOperationException' occurred in PresentationFramework.dll 
A first chance exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll 

gibi istisna atar ancak istisna nereden geldiğini bulamadı. B/c veri bağlama olduğunu biliyorum. ama nerede olduğunu bulamıyor. Her adımda, VS, o/o hatayı yürüten bir yönteme izler, sonra, istisna atar ve hangi kod satırı hakkında bir ipucu yoktur.

Günler boyunca bununla mücadele ediyorum ve biraz ilerleme kaydedemedim. Pls yardımcı oluyor. teşekkürler

Düzenleme, yorum eklemek için çok uzun. Ben de buraya xaml dosyasını koydum. istisna atar @ xmal dosyası. Burada yığını olan iz

Adı: NullReferenceException Mesaj: değil bir nesnenin örneğine set Nesne başvurusu Bu durum

<UserControl x:Class="View.BasketView" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit" > 
    <UserControl.Resources> 
     <sharedC:FunctionToHiddenVisibility x:Key="enumSRToVis"/> 
     <sharedC:FunctionToHiddenVisibility x:Key="enumCSToVis"/> 
     <Style x:Key="DataGridRowStyle" TargetType="{x:Type dg:DataGridRow}"> 
      <Style.Triggers> 
       <Trigger Property="AlternationIndex" Value="1" > 
        <Setter Property="Background" Value="Beige" /> 
       </Trigger> 
      </Style.Triggers> 
      <Setter Property="AllowDrop" Value="True" /> 
      <Setter Property="Margin" Value="0 2 0 2" />    
     </Style> 
     <Style x:Key="DataGridStyle" TargetType="{x:Type dg:DataGrid}"> 
      <Setter Property="AlternationCount" Value="2" /> 
      <Setter Property="RowStyle" Value="{StaticResource DataGridRowStyle}" /> 
     </Style> 
     <Style TargetType="{x:Type MenuItem}"> 
      <Style.Triggers> 
       <Trigger Property="MenuItem.IsHighlighted" Value="True" > 
        <Setter Property="BorderBrush" > 
         <Setter.Value> 
          <SolidColorBrush Color="Gray"></SolidColorBrush> 
         </Setter.Value> 
        </Setter> 
        <Setter Property="BorderThickness" Value="1"/> 
       </Trigger> 
      </Style.Triggers> 
     </Style>   
    </UserControl.Resources> 
    <GroupBox> 
     <GroupBox.Header> 
      <TextBlock FontSize="14" FontFamily="Verdana" Text="{Binding Header,Mode=OneWay}"></TextBlock> 
     </GroupBox.Header> 

     <Grid> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="33"></RowDefinition> 
       <RowDefinition Height="*" ></RowDefinition> 
       <RowDefinition Height="Auto"></RowDefinition> 
      </Grid.RowDefinitions> 

      <Border Margin="2 2 2 0"> 
       <Grid> 

        <Menu Background="Transparent"> 
         <Menu.Resources> 
          <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Transparent" /> 
         </Menu.Resources> 
         <MenuItem IsEnabled="{Binding IsItemSelected}" Click="EditClick" ToolTip="Edit Relation(s)" Background="Transparent"> 
          <MenuItem.Header> 
           <Image Width="16" Height="16" Source="{Binding EditImageFilePath}"/> 
          </MenuItem.Header> 
         </MenuItem> 
         <MenuItem IsEnabled="{Binding IsItemSelected}" Click="DeleteClick" ToolTip="Delete Relation(s)" Background="Transparent"> 
          <MenuItem.Header> 
           <Image Width="16" Height="16" Source="{Binding DeleteImageFilePath}"/> 
          </MenuItem.Header> 
         </MenuItem> 
        </Menu>        
       </Grid> 
      </Border> 

      <dg:DataGrid Grid.Row="1" x:Name="basketDG" Margin="5 0 5 0" Background="White" 
        AutoGenerateColumns="False" 
        Style="{StaticResource DataGridStyle}" 
        SelectionMode="Extended" 
        GridLinesVisibility="None" 
        HeadersVisibility="Column" RowDetailsVisibilityMode="VisibleWhenSelected" 
        ItemsSource="{Binding BasketItems, Mode=OneWay}" CanUserAddRows="False" CanUserDeleteRows="False" 
        SelectionUnit="FullRow" SelectedItem="{Binding SelectedRelComplete}" 
        VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled" 
        SelectionChanged="BasketDgSelectionChanged"     
        Drop="DataGridDrop" 
        DragEnter="DataGridDragEnter" 
        AllowDrop="True" 
       > 

       <!-- Column definition --> 
       <dg:DataGrid.Columns> 
        <dg:DataGridTextColumn IsReadOnly="True" Width="100" Header="Symbol" Binding="{Binding Name}" > 
         <dg:DataGridTextColumn.ElementStyle> 
          <Style TargetType="{x:Type TextBlock}"> 
           <Setter Property="TextWrapping" Value="Wrap" /> 
          </Style> 
         </dg:DataGridTextColumn.ElementStyle> 
        </dg:DataGridTextColumn>    

        <dg:DataGridTextColumn IsReadOnly="True" Width="*" Header="Symbol Description" Binding="{Binding Desc}" > 
         <dg:DataGridTextColumn.ElementStyle> 
          <Style TargetType="{x:Type TextBlock}"> 
           <Setter Property="TextTrimming" Value="WordEllipsis" /> 
          </Style> 
         </dg:DataGridTextColumn.ElementStyle> 
        </dg:DataGridTextColumn> 

        <dg:DataGridComboBoxColumn Width="200" Header="Column" 
         SelectedValueBinding="{Binding Path=RelParams.ColumnName, UpdateSourceTrigger=PropertyChanged}" 
         DisplayMemberPath="cName" 
         SelectedValuePath="cName"> 
         <dg:DataGridComboBoxColumn.ElementStyle> 
          <Style TargetType="ComboBox"> 
           <Setter Property="ItemsSource" Value="{Binding RelInfo.Columns}" /> 
          </Style> 
         </dg:DataGridComboBoxColumn.ElementStyle> 
         <dg:DataGridComboBoxColumn.EditingElementStyle> 
          <Style TargetType="ComboBox"> 
           <Setter Property="ItemsSource" Value="{Binding RelInfo.Columns}" /> 
          </Style> 
         </dg:DataGridComboBoxColumn.EditingElementStyle> 
        </dg:DataGridComboBoxColumn> 

       </dg:DataGrid.Columns>    

      </dg:DataGrid> 

      <Grid Grid.Row="2" Margin="0 5 0 0"> 
       <Grid.ColumnDefinitions> 
        <ColumnDefinition Width="*" ></ColumnDefinition> 
        <ColumnDefinition Width="Auto" ></ColumnDefinition> 
        <ColumnDefinition Width="5" ></ColumnDefinition> 
        <ColumnDefinition Width="Auto" ></ColumnDefinition> 
       </Grid.ColumnDefinitions> 
       <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Grid.Column="0"> 
        <Button Name="BtnSR" Visibility="{Binding SelectedFunction, Converter={StaticResource enumSRToVis}}" IsEnabled="{Binding ItemsExist}" Margin="2" Click="ShowBasketSettings">Basket Settings</Button> 
       </StackPanel> 
       <StackPanel HorizontalAlignment="Left" Orientation="Horizontal" Grid.Column="0"> 
        <Button Name="BtnCS" Visibility="{Binding SelectedFunction, Converter={StaticResource enumCSToVis}}" IsEnabled="{Binding OnlyOneFutureItemExist}" Margin="2" Click="ShowCreateCurve">Curve Settings</Button> 
       </StackPanel> 
       <StackPanel Grid.Column="1"> 
        <Button Width="50" Name ="BtnClear" ToolTip="Clear Basket" Margin="2" IsEnabled="{Binding ItemsExist}" 
          Click="BtnClear_Click">Clear</Button> 
       </StackPanel> 
       <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Grid.Column="3">     
        <Button Visibility ="{Binding ElementName=BtnSR, Path=Visibility}" 
          ToolTip="Send Series Data to Table" 
          Name="SendToTable" Margin="2" Command="{Binding SendToTableCommand}" 
          CommandParameter="{Binding ElementName=SendToTable}">Send to Table</Button> 
       </StackPanel> 
       <StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Grid.Column="3"> 
        <Button Visibility="{Binding ElementName=BtnCS, Path=Visibility}" 
          Name="CreateCurveSurface" Margin="2"        
          ToolTip="Send Curve Surface to Table" 
          IsEnabled="{Binding OnlyOneFutureItemExist}" 
          Click="CreateCurveSurfaceClick" 
        >Send to Table</Button> 
       </StackPanel> 
      </Grid> 
     </Grid> 
    </GroupBox> 
</UserControl> 

Düzenleme atar DataGridComboBoxColumn olduğunu. Hedef: Void RestoreAttachedItemValue (System.Windows.DependencyObject, System.Windows.DependencyProperty) Yığın: Microsoft.Windows.Controls.DataGridRow de Microsoft.Windows.Controls.DataGridRow.RestoreAttachedItemValue (DependencyObject objectWithProperty, DependencyProperty özelliği). System.Windows de Microsoft.Windows.Controls.DataGrid.PrepareContainerForItemOverride (DependencyObject eleman, Nesne öğesi) de Microsoft.Windows.Controls.DataGridRow.PrepareRow (Object öğesi, DataGrid owningDataGrid) de SyncProperties (Boolean forcePrepareCells). Controls.ItemsControl.MS.Internal.Controls.IGeneratorHost.PrepareItemContainer (DependencyObject System.Windows.Controls.VirtualizingStackPanel.InsertContainer (Int32 childIndex, UIElement konteyner de System.Windows.Controls.ItemContainerGenerator.System.Windows.Controls.Primitives.IItemContainerGenerator.PrepareItemContainer (DependencyObject konteyner) dekonteyner, Nesne öğesi) Microsoft.Windows.Controls de System.Windows.Controls.VirtualizingStackPanel.BringIndexIntoView en System.Windows.Controls.VirtualizingStackPanel.AddContainerFromGenerator de, Boole isRecycled) (Int32 childIndex, UIElement çocuk, Boole newlyRealized) (Int32 endeksi). Microsoft.Windows.Controls DataGrid.ScrollRowIntoView (Nesne öğesi)
. DataGrid.OnScrollIntoView (Obje arg) System.Windows.Threading.ExceptionWrapper.InternalRealCall de
(Yetkili geri arama, bağımsız değişken Nesne, ınt32 numArgs) de MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen (Obje kaynağı, temsilci bir yöntem, nesne args, Int32 numArgs, Sisteminde System.Windows.Threading.DispatcherOperation.InvokeImpl() at System.Windows.Threading.Dispatcher.WrappedInvoke (Delege geri arama, Nesne args, Int32 numArgs, Delege catchHandler) de Delegesi catchHandler) System.Threading.ExecutionContext.runTryCode öğesinde .Windows.Threading.DispatcherOperation.InvokeInSecurityContext (Object durumu) (Object kullanıcı Veri) System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup (ExecutionContext ExecutionContext, ContextCallback geri arama durumu Nesne) System.Threading.ExecutionContext.RunInternal de (TryCode kod CleanupCode backoutCode, userData Nesne) System.Threading.ExecutionContext.Run (ExecutionContext ExecutionContext, ContextCallback geri arama, nesne de devlet, System.Windows.Threading.Dispatcher.ProcessQueue de System.Windows.Threading.DispatcherOperation.Invoke() at System.Threading.ExecutionContext.Run (ExecutionContext ExecutionContext, ContextCallback geri arama, devlet Nesne) de Boole ignoreSyncCtx)() at System.Windows.Threading.Dispatcher.WndProcHook (IntPtr hwnd, Int32 Msg, ıntptr WParam, ıntptr LParam, Boole & MS.Win32.HwndSubclass.DispatcherCallbackOperation ele MS.Win32.HwndWrapper.WndProc (ıntptr HWND, ınt32 mesaj, ıntptr wParamın, ıntptr lParamda, Boolean &) (en) ele System.Windows.Threading.ExceptionWrapper.InternalRealCall (temsilci geri arama nesne o), MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen ( kaynağı, temsilci yöntemi Nesne de bağımsız değişken, Int32 numArgs) nesne bağımsız değişken, Int32 numArgs Nesne Delege catchHandler) System.Windows.Threading.Dispatcher.WrappedInvoke (Delege geri arama, Nesne satırları, Int32 numArgs, Delegate ca System.Windows.Threading.Dispatcher.InvokeImpl (DispatcherPriority öncelikte tchHandler), ZamanGeçişi zaman aşımı, temsilci bir yöntem, MS.Win32.HwndSubclass.SubclassWndProc (ıntptr HWND, ınt32 mesaj, ıntptr wParamın de bağımsız değişken, Int32 numArgs) Nesne System.Windows.Threading.Dispatcher.PushFrame de System.Windows.Threading.Dispatcher.PushFrameImpl (DispatcherFrame çerçeve) MS.Win32.UnsafeNativeMethods.DispatchMessage (mSG & mSG) de ıntptr lParam) (DispatcherFrame çerçeve)
System.Windows.Window.ShowHelper (Object booleanBox) at System.Windows.Window.Show() at System.Windows.Window.ShowDialog()

cevap

8

Wpf, bağlayıcı kural dışı durumları yakalar; böylece normalde hata ayıklayıcısını kırmayacaklardır. Onları her zaman VS'deki Debug \ Exceptions menü komutunu kullanarak yapabilirsiniz, Bul'u tıklatın, gördüğünüz özel durumu yazın (ör. System.InvalidOperationException). Tamam'a tıklayın ve iletişim kutusu bu istisnayla aşağı inmelidir. "Thrown" sütunundaki onay kutusunu işaretleyin ve VS hata ayıklama yaparken hangi kod satırını özgün istisna atıyorsa kırın.

Bu türdeki tüm özel durumları yakalayacaktır - hatta bir Try Catch bloğunda açıkça yakaladığınız bile olsa, hata ayıklama işlemi tamamlandığında bu kutuyu kaldırmayı unutmayın veya VS'nin neden özel durumları kaçırdığını merak edersiniz. Yakalanmak.

+0

Çok teşekkür ederim, fular. Şimdi bunu anlıyorum, ama yine de doğru bir kod satırına işaret etmiyor. Yani Window.ShowDialog() istisna atar ve pencerede hangi bölüm olduğunu biliyorum, bir içerik (usercontrol) istisnayı atar, ama xaml veya xaml.cs veya viewModel nedenleri hangi satırı bulabilirim? istisnası – toosensitive

+0

System.NullReferenceException oluştu Message = "Nesne başvurusu bir nesnenin örneğine ayarlanmadı." = "WPFToolkit" StackTrace Kaynak: Microsoft.Windows.Controls.DataGridRow.RestoreAttachedItemValue de Microsoft.Windows.Controls en Microsoft.Windows.Controls.DataGridRow.SyncProperties de (DependencyObject objectWithProperty, DependencyProperty mülkiyet) (Boolean forcePrepareCells) . DataGridRow.PrepareRow (Nesne öğesi, DataGrid owningDataGrid) , Microsoft.Windows.Controls.DataGrid.PrepareContainerForItemOverride (DependencyObject öğesi, Nesne öğesi) .... – toosensitive

+0

Wpf DataGrid istisna atıyor gibi görünüyor. Bunun kaynağı mevcut gibi görünmüyor, bu yüzden muhtemelen sorunu daraltmaya çalışmayı bırakmış olursunuz - sütunları kaldırmanızı/sorunlu bölgeyi Xaml'i denemenizi ve sorun bölgesini kesinleştirmenizi öneririm. Izgara şablonunuzda ekli mülk kullanıyor musunuz? Xaml'inizi bu kontrol için gönderebilecek misiniz? – fubaar

9

Ben senin sorunun nedeni hakkında emin değilim ama burada WPF bağlamaları hata ayıklama Nasıl bazı bağlantılar - WPF bağlamaları hata ayıklama nasıl

? http://www.zagstudio.com/blog/486 (WayBackLink) bir WPF veya Silverlight Başvurusu http://blogs.msdn.com/b/wpfsldesigner/archive/2010/06/30/debugging-data-bindings-in-a-wpf-or-silverlight-application.aspx (WayBackLink)

WPF Pasaj içinde

Hata Veri bağlanma - bağlama hatalar
http://www.switchonthecode.com/tutorials/wpf-snippet-detecting-binding-errors (WayBackLink) algılama

ayıklama veri bağlama Sorunlar WPF
http://www.wpftutorial.net/DebugDataBinding.html

+0

hmm, dönüştürücü denendi, PresentationTraceSources.TraceLevel = Yüksek, ne işe yaramıyor. – toosensitive

+0

ilk 3 bağlantı şimdiye kadar öldü, ve sonuncusu da çalışmıyor. Bu yüzden her zaman önemli parçaları cevabınıza kopyalamanız gerekir. –

+0

@ Rico-E Bunu işaret ettiğin için teşekkürler Rico; internet üzerinde hiç bir şey kaybolmadığı için, geri dönüş makinesine bağlantılar eklendi :) – akjoshi