Defining NodePort connections in XAML throws null reference exception

I am having an issue defining connectors to  NodePortViewModels. 

The gist of my code is as follows:
<sf:NodeViewModel ID="Node1">
    <sf:NodeViewModel.Ports>
          <local:PortCollection>
               <sf:NodePortViewModel ID="Port1" UnitHeight="0" UnitWidth="0" NodeOffsetX=".125" NodeOffsetY="0"/>
          </local:PortCollection>
      </sf:NodeViewModel.Ports>
</sf:NodeViewModel>

<sf:NodeViewModel ID="Node2">
    <sf:NodeViewModel.Ports>
          <local:PortCollection>
               <sf:NodePortViewModel ID="Port2" UnitHeight="0" UnitWidth="0" NodeOffsetX=".125" NodeOffsetY="0"/>
          </local:PortCollection>
      </sf:NodeViewModel.Ports>
</sf:NodeViewModel>
<sf:SfDiagram.Connectors>
     <sf:ConnectorCollection>
          <sf:ConnectorViewModel SourcePortID="Port1" TargetPortID="Port2" />
     </sf:ConnectorCollection>
</sf:SfDiagram.Connectors>

The constructor of this control throws a NullReferenceException with the following StackTrace:
   at Syncfusion.UI.Xaml.Diagram.ConnectorWrapper.SourcePortIDChanged()
   at Syncfusion.UI.Xaml.Diagram.ConnectorWrapper.OnGraphChanged()
   at Syncfusion.UI.Xaml.Diagram.GroupableWrapper.Init(Object source)
   at Syncfusion.UI.Xaml.Diagram.SfDiagramWrapper.GetConnectorWrapper(Object source, Boolean canCreate)
   at Syncfusion.UI.Xaml.Diagram.ObservableElements`2..ctor(Object source, ElementType type, SourceType srcType, EventAggregartor aggregator, Func`3 wrapper)
   at Syncfusion.UI.Xaml.Diagram.SfDiagramWrapper.OnConnectorsChanged()
   at Syncfusion.UI.Xaml.Diagram.SfDiagramWrapper.OnPropertyChanged(String propertyName)
   at Syncfusion.UI.Xaml.Diagram.WrapperBase.KnownSource_PropertyChanged(Object sender, PropertyChangedEventArgs e)
   at Syncfusion.UI.Xaml.Diagram.SfDiagram.OnPropertyChanged(String name)
   at Syncfusion.UI.Xaml.Diagram.SfDiagram.OnConnectorsChanged(DependencyObject d, 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.Baml2006.WpfMemberInvoker.SetValue(Object instance, Object value)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(XamlMember member, Object obj, Object value)
   at MS.Internal.Xaml.Runtime.ClrObjectRuntime.SetValue(Object inst, XamlMember property, Object value)
   at MS.Internal.Xaml.Runtime.PartialTrustTolerantRuntime.SetValue(Object obj, XamlMember property, Object value)
   at System.Xaml.XamlObjectWriter.Logic_ApplyPropertyValue(ObjectWriterContext ctx, XamlMember prop, Object value, Boolean onParent)
   at System.Xaml.XamlObjectWriter.Logic_DoAssignmentToParentProperty(ObjectWriterContext ctx)
   at System.Xaml.XamlObjectWriter.WriteEndObject()
   at System.Xaml.XamlWriter.WriteNode(XamlReader reader)
   at System.Windows.Markup.WpfXamlLoader.TransformNodes(XamlReader xamlReader, XamlObjectWriter xamlWriter, Boolean onlyLoadOneNode, Boolean skipJournaledProperties, Boolean shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, XamlContextStack`1 stack, IStyleConnector styleConnector)
   at System.Windows.Markup.WpfXamlLoader.Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, Boolean skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
   at System.Windows.Markup.WpfXamlLoader.LoadBaml(XamlReader xamlReader, Boolean skipJournaledProperties, Object rootObject, XamlAccessLevel accessLevel, Uri baseUri)
   at System.Windows.Markup.XamlReader.LoadBaml(Stream stream, ParserContext parserContext, Object parent, Boolean closeStream)
   at System.Windows.Application.LoadComponent(Object component, Uri resourceLocator)
   at OPMG.SystemControls.Oneline.InitializeComponent() in D:\svn\OPMG Client\OPMG\SystemControls\Oneline.xaml:line 1
   at OPMG.SystemControls.Oneline..ctor(IOnelineVM vm, IAssetService assetService) in D:\path\<MyControl>.xaml.cs:line 47
   at lambda_method(Closure , IBuilderContext )
   at Microsoft.Practices.ObjectBuilder2.DynamicBuildPlanGenerationContext.<>c__DisplayClass1.<GetBuildMethod>b__0(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.DynamicMethodBuildPlan.BuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.BuildPlanStrategy.PreBuildUp(IBuilderContext context)
   at Microsoft.Practices.ObjectBuilder2.StrategyChain.ExecuteBuildUp(IBuilderContext context)


If I comment out the connector that uses the node ports the code runs fine (granted without the connector that I want), so it is obviously the source of the issue. If I live edit the XAML and add the connector while the control is running it creates and renders the connector just fine, but then when I restart my app and reload the control I get the same error.

Syncfusion.SfDiagram.WPF is v15.1460.0.41

I should note that this issue is not limited to Port-Port connection, anytime I try to define connectors to NodePorts in XAML I encounter this issue. I had to implement an algorithm that iterates through nodes with Ports at start up and manually create the connectors in code behind myself. So this seems to be an issue with the order in which things are initialized by your control. This is just the first case where my custom logic is getting out of hand to provide functionality that your library should already offer.

This is currently blocking development on a time sensitive project, so a prompt response is much appreciated.


3 Replies

KR Karkuvel Rajan Shanmugavel Syncfusion Team March 14, 2018 10:48 AM UTC

Hi Andrew, 

We have analysed your reported issue. The Reported issue is resolved in our release 15.2.0.40 and also in further releases. Please upgrade to latest version to resolve this issue. 

Regards, 
Karkuvel Rajan.S 



AW Andrew Westerman March 14, 2018 04:51 PM UTC

Awesome, thank you for the quick reply!


KR Karkuvel Rajan Shanmugavel Syncfusion Team March 15, 2018 09:13 AM UTC

Hi Andrew, 
 
please let us know whether you need any further assistance . 
 
Regards, 
Karkuvel Rajan.S 


Loader.
Up arrow icon