This is a migrated thread and some comments may be shown as answers.

"Object reference not set to an instance of an object" exception

1 Answer 39 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 01 Apr 2013, 09:45 AM
Hello.
1) I have WPF application with RadDiagram and RadDiagramToolbox components.
2) I create GalleryCollection with my owner shapes:
galleryCollection.Items.Add(new GalleryItem(geometryWrapper.Name, GetShape(geometryWrapper)));
galleryList.Add(
new GalleryWrapper(galleryCollection));
GallerySource =
new ObservableCollection<GalleryWrapper>(galleryList);

This is GetShape method:
private RadDiagramShapeBase GetShape(GeometryWrapper wrapper)
{
    
string data = wrapper.Data;
    Path shapePath = (Path)XamlReader.Parse(data);
    RadDiagramShape shape =
new RadDiagramShape { Geometry = shapePath.Data, Name = wrapper.Name.Replace(" ", "_") + "Shape" };
    
return shape;
}

 3) My shapes I get from database. There are samples of my shapes:

-Shape1:
<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Stroke='Black' StrokeThickness='1' Fill='#CCCCFF'>
  <
Path.Data>
    <
CombinedGeometry GeometryCombineMode='Exclude'>
      <
CombinedGeometry.Geometry1>
        <
EllipseGeometry RadiusX='50' RadiusY='50' Center='75,75' />
      </
CombinedGeometry.Geometry1>
      <
CombinedGeometry.Geometry2>
        <
EllipseGeometry RadiusX='50' RadiusY='50' Center='125,75' />
      </
CombinedGeometry.Geometry2>
    </
CombinedGeometry>
  </
Path.Data>
</
Path>

+Shape2:
<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Name='starPath' Fill='Gray' Data='M 9,0 L 7,6 L 0,6 L 6,11 L 4,17 L 9,12 L 14,17 L 12,11 L 18,6 L 11,6 L 9,0'>
  <
Path.LayoutTransform>
    <
ScaleTransform ScaleX='0.8' ScaleY='0.8' />
  </
Path.LayoutTransform>
</
Path>

+Shape3:
<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Stroke='Black' StrokeThickness='1'>
  <
Path.Data>
    <
PathGeometry>
      <
PathGeometry.Figures>
        <
PathFigureCollection>
          <
PathFigure StartPoint='10,100'>
            <
PathFigure.Segments>
              <
PathSegmentCollection>
                <
QuadraticBezierSegment Point1='200,200' Point2='300,100' />
              </
PathSegmentCollection>
            </
PathFigure.Segments>
          </
PathFigure>
        </
PathFigureCollection>
      </
PathGeometry.Figures>
    </
PathGeometry>
  </
Path.Data>
</
Path>

-Shape4:
<Path xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stroke="Black" StrokeThickness="3" Fill="Blue">
  <
Path.Data>
    <
GeometryGroup>
      <
LineGeometry StartPoint="20,200" EndPoint="300,200" />
      <
EllipseGeometry Center="80,150" RadiusX="50" RadiusY="50" />
      <
RectangleGeometry Rect="80,167 150 30"/>
    </
GeometryGroup>
  </
Path.Data>
</
Path>

+Shape5:
<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Data="M 100,200 C 100,25 400,350 400,175 H 280"/>

-Shaep6:
<Path xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' Stroke='Black' StrokeThickness='1' Fill='#CCCCFF'>
  <
Path.Data>
    <
CombinedGeometry GeometryCombineMode="Union">
      <
CombinedGeometry.Geometry1>
        <
EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </
CombinedGeometry.Geometry1>
      <
CombinedGeometry.Geometry2>
        <
EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </
CombinedGeometry.Geometry2>
    </
CombinedGeometry>
  </
Path.Data>
</
Path>

4) Then I binding GalleryCollection:
<telerik:RadDiagramToolbox Grid.Column="1" Grid.RowSpan="2" Name="tbxGallery" Header="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.Header}" 
                          Background="#FFE82A2A" HeaderBackground="#FFE82A2A" ItemTemplate="{StaticResource ToolboxTemplate}" ItemsSource="{Binding GallerySource}"
Title="Галерея" Width="300" />

5) When I run my application it's OK. My shapes showing into RadDiagramToolbox. When I try drug&drop Shape2 or Shape3 or Shape5 it's OK too. 
But when I try drug Shape1 or Shape4 or Shape6 I get exception (I get exception when Path tag has CombinedGeometry tag):

Object reference not set to an instance of an object.
  at Telerik.Windows.Controls.Diagrams.GeometryParser.ParseBack(PathGeometry geometry) in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Diagrams\Diagrams\Utilities\GeometryParser.cs:line 128
   at Telerik.Windows.Controls.Diagrams.GeometryParser.GetString(Geometry geometry)
in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Diagrams\Diagrams\Utilities\GeometryParser.cs:line 32
   at Telerik.Windows.Controls.RadDiagramShape.Serialize()
in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Diagrams\Diagrams\Visuals\RadDiagramShape.cs:line 65
   at Telerik.Windows.Diagrams.Core.SerializationService.SerializeShapes(IEnumerable`1 shapes)
in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Diagrams\Core\Services\SerializationService.cs:line 315
   at Telerik.Windows.Diagrams.Core.SerializationService.SerializeItems(IEnumerable`1 items)
in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Diagrams\Core\Services\SerializationService.cs:line 261
   at Telerik.Windows.Controls.Diagrams.Extensions.ToolboxDragService.OnDragInitialized(Object sender, DragInitializeEventArgs args)
in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Diagrams\Extensions\Toolbox\ToolboxDragService.cs:line 33
   at Telerik.Windows.DragDrop.DragInitializeEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDropManager\DragInitializeEventArgs.cs:line 103
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)<br>   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 Telerik.Windows.DragDrop.DragInitializer.StartDrag()
in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDropManager\DragInitializer.cs:line 285
   at Telerik.Windows.DragDrop.DragInitializer.StartDragPrivate(UIElement sender)
in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDropManager\DragInitializer.cs:line 246
   at Telerik.Windows.DragDrop.DragInitializer.DragSourceOnMouseMove(Object sender, MouseEventArgs e)
in c:\TB\135\WPF_Scrum\Release_WPF\Sources\Development\Core\Controls\DragDropManager\DragInitializer.cs:line 196
   at System.Windows.Input.MouseEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
   at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target)
   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.RaiseTrustedEvent(RoutedEventArgs args)
   at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted)
   at System.Windows.Input.InputManager.ProcessStagingArea()
   at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input)
   at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport)
   at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel)
   at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at System.Windows.Interop.HwndSource.InputFilterMessage(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.InvokeImpl(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.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at System.Windows.Application.Run()
   at Neolant.ND_Platform.WpfClient.App.Main()
in D:\Projects\ProductionPlatform\ND_Platform\ND_Platform\Neolant.ND_Platform.WpfClient\obj\x86\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.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.ThreadHelper.ThreadStart()

Do you have any ideas?

1 Answer, 1 is accepted

Sort by
0
Pavel R. Pavlov
Telerik team
answered on 03 Apr 2013, 12:11 PM
Hi Alexander,

I am not sure that I fully understand your scenario. This is why it would be best to create a sample solution and send it through our support ticketing system. This system allows our customers to attach and send their projects while guaranteeing confidentiality. This is why I will kindly ask you to submit a ticket and attach your project in it. This way we will be able to better understand your implementation and suggest the best approach for it.

Regards,
Pavel R. Pavlov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Diagram
Asked by
Alexander
Top achievements
Rank 1
Answers by
Pavel R. Pavlov
Telerik team
Share this question
or