2013-11-18 3 views
0

Я пытаюсь загрузить и отобразить документ GraphML с помощью Graph# library for C#, и я получаю NullReferenceException на линии, которая, кажется, не имеет смысла:NullReferenceException на (по-видимому) полностью инициализируются объекты

private void load(string fileName) { 
    var graph = new CompoundGraph<object, IEdge<object>>(); 

    //open the file of the graph 
    var reader = XmlReader.Create(fileName); 

    //create the serializer 
    var serializer = new GraphMLDeserializer<object, 
     IEdge<object>, 
     CompoundGraph<object, IEdge<object>>>(); 

    //deserialize the graph 
    serializer.Deserialize(reader, graph, 
     id => id, (source, target, id) => new Edge<object>(source, target) 
     ); 

    Console.WriteLine(graph);    // okay 
    Console.WriteLine(graphLayout.Graph); // okay 

    this.graphLayout.Graph = graph;   // crashes 
    this.graphLayout.UpdateLayout(); 
} 

Я проверил значения объекта с помощью отладчика, и все, кажется, в порядке. Что еще может быть не так? Почему я получаю NullReferenceException для объектов, которые были инициализированы?

Если вы предпочитаете просматривать весь источник (или скомпилировать его самостоятельно, если вы так склонны, вы более чем рады), я делаю проект доступным на GitHub в течение некоторого времени. Я добавил a commit, что воспроизводит проблему.

Полный трассировки стека:

System.NullReferenceException was unhandled 
    HResult=-2147467261 
    Message=Object reference not set to an instance of an object. 
    Source=GraphSharp.Controls 
    StackTrace: 
     at GraphSharp.Controls.GraphLayout`3.Layout(Boolean continueLayout) 
     at GraphSharp.Controls.GraphLayout`3.Relayout() 
     at GraphSharp.Controls.GraphLayout`3.OnRelayoutInduction(Boolean tryKeepControls) 
     at GraphSharp.Controls.GraphLayout`3.Graph_PropertyChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e) 
     at System.Windows.DependencyObject.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
     at System.Windows.FrameworkElement.OnPropertyChanged(DependencyPropertyChangedEventArgs e) 
     at System.Windows.DependencyObject.NotifyPropertyChange(DependencyPropertyChangedEventArgs args) 
     at System.Windows.DependencyObject.UpdateEffectiveValue(EntryIndex entryIndex, DependencyProperty dp, PropertyMetadata metadata, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType) 
     at System.Windows.DependencyObject.SetValueCommon(DependencyProperty dp, Object value, PropertyMetadata metadata, Boolean coerceWithDeferredReference, Boolean coerceWithCurrentValue, OperationType operationType, Boolean isInternal) 
     at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value) 
     at GraphSharp.Controls.GraphLayout`3.set_Graph(TGraph value) 
     at SMP.MainWindow.load(String fileName) in t:\#_\Programming\GitHub\SMP\SMP\Simulator.xaml.cs:line 61 
     at SMP.MainWindow.Load_GMX_Graph(Object sender, RoutedEventArgs e) in t:\#_\Programming\GitHub\SMP\SMP\Simulator.xaml.cs:line 38 
     at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
     at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
     at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
     at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) 
     at System.Windows.Controls.MenuItem.InvokeClickAfterRender(Object arg) 
     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) 
     at System.Windows.Threading.DispatcherOperation.InvokeImpl() 
     at System.Windows.Threading.DispatcherOperation.InvokeInSecurityContext(Object state) 
     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 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 MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, 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.Threading.Dispatcher.Run() 
     at System.Windows.Application.RunDispatcher(Object ignore) 
     at System.Windows.Application.RunInternal(Window window) 
     at System.Windows.Application.Run(Window window) 
     at System.Windows.Application.Run() 
     at SMP.App.Main() in t:\#_\Programming\GitHub\SMP\SMP\obj\Debug\App.g.cs:line 0 
     at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args) 
     at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) 
     at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 
     at System.Threading.ThreadHelper.ThreadStart_Context(Object state) 
     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 System.Threading.ThreadHelper.ThreadStart() 
    InnerException: 
+0

Можете ли вы опубликовать полную трассировку стека на Ошибка? – NotMe

+0

Готово. Но могу ли я спросить, если вы знаете, каково значение обратного хода в трассировке стека на некоторых линиях? –

+2

@SeanAllred: backtick указывает, что класс является общим классом с 3-мя генерическими параметрами. – siride

ответ

0

проверить файл Simulator.xaml.cs на линии 61. Ваш последний код есть до того, как было брошено исключение ...

Смежные вопросы