Search code examples
wpfformsvisual-studiovisual-studio-2019ironpython

"System.ArgumentNullException Value cannot be null. Parameter name: source" - Visual Studio IronPython WPF


I'm trying to create an IronPython WPF form on Visual Studio 2019. However, when I try using the XAML Designer to edit the text of my button, I get this error saying "System.ArgumentNullException Value cannot be null. Parameter name: source." It allows me to reload the designer, but then the error simply occurs again when I attempt to edit the text. You can find the full error and my .XAML file below.

Error:

System.ArgumentNullException
Value cannot be null.
Parameter name: source
   at System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.Contains[TSource](IEnumerable`1 source, TSource value)
   at Microsoft.PythonTools.XamlDesignerSupport.WpfEventBindingProvider.CreateUniqueMethodName(String objectName, EventDescription eventDescription)
   at Microsoft.VisualStudio.DesignTools.XamlDesignerHost.Code.DesignerContextCodeContext.Microsoft.VisualStudio.DesignTools.DesignerContract.IHostCodeContext.CreateUniqueMethodName(String objectName, IHostCodeEvent codeEvent, Boolean shouldCapitalizeMethodName)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.RemoteHostCodeContext.<>c__DisplayClass17_0.<Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.IRemoteHostCodeContext.CreateUniqueMethodName>b__0()
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.ThreadMarshaler.<>c__DisplayClass48_0`1.<MarshalIn>b__0()
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()

System.ArgumentNullException
Value cannot be null.
Parameter name: source

Server stack trace: 
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.STAMarshaler.WaitForCompletion(NestedCallContext nestedCallContext, BlockingCall call, WaitHandle timeoutSignal)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.STAMarshaler.MarshalInSynchronous(Action action, Int32 targetApartmentId, CancellationToken cancelToken, CallModality callModality, String methodName, String filePath, Int32 lineNumber)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.STAMarshaler.MarshalIn(Action action, Int32 targetApartmentId, CancellationToken cancelToken, CallSynchronizationMode syncMode, CallModality callModality, String methodName, String filePath, Int32 lineNumber)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.ThreadMarshaler.MarshalIn(IRemoteObject targetObject, Action action, CallSynchronizationMode syncMode, CallModality callModality, ApartmentState apartmentState, String memberName, String filePath, Int32 lineNumber)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.ThreadMarshaler.MarshalIn[TResult](IRemoteObject targetObject, Func`1 func, CallModality callModality, ApartmentState apartmentState, String memberName, String filePath, Int32 lineNumber)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.RemoteHostCodeContext.Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.IRemoteHostCodeContext.CreateUniqueMethodName(String objectName, String eventName, RemoteHostParameter[] parameters, String returnType)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.IRemoteHostCodeContext.CreateUniqueMethodName(String objectName, String eventName, RemoteHostParameter[] parameters, String returnType)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.LocalHostCodeContext.<>c__DisplayClass18_0.<Microsoft.VisualStudio.DesignTools.DesignerContract.IHostCodeContext.CreateUniqueMethodName>b__0(IRemoteHostCodeContext cxt)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.ThreadMarshaler.<>c__DisplayClass32_0`2.<MarshalOut>b__0()
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()

System.ArgumentNullException
Value cannot be null.
Parameter name: source
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.STAMarshaler.WaitForCompletion(NestedCallContext nestedCallContext, BlockingCall call, WaitHandle timeoutSignal)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.STAMarshaler.MarshalOutSynchronous(Action action, Int32 targetApartmentId, WaitHandle aborted, WaitHandle timeoutSignal, CancellationToken cancelToken, String methodName, String filePath, Int32 lineNumber)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.STAMarshaler.MarshalOut(Action action, Int32 targetApartmentId, WaitHandle aborted, CancellationToken cancelToken, CallSynchronizationMode syncMode, WaitHandle timeoutSignal, String methodName, String filePath, Int32 lineNumber)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.ThreadMarshaler.MarshalOut[TValue](RemoteHandle`1 targetObject, Action action, CallSynchronizationMode syncMode, ApartmentState apartmentState, String methodName, String filePath, Int32 lineNumber)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.ThreadMarshaler.MarshalOut[TResult,TValue](RemoteHandle`1 targetObject, Func`2 func, CallSynchronizationMode syncMode, ApartmentState apartmentState, String methodName, String filePath, Int32 lineNumber)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.Remoting.LocalHostCodeContext.Microsoft.VisualStudio.DesignTools.DesignerContract.IHostCodeContext.CreateUniqueMethodName(String objectName, IHostCodeEvent codeEvent, Boolean shouldCapitalizeMethodName)
   at Microsoft.VisualStudio.DesignTools.Designer.UI.PropertyInspector.CodeContext.CreateUniqueMethodName(ISourceItemContext item, String typeName, String objectName, IEvent eventKey)
   at Microsoft.VisualStudio.DesignTools.Designer.UI.PropertyInspector.EventHandlerProvider.CreateUniqueMethodName(String objectName, IEvent eventKey)
   at Microsoft.VisualStudio.DesignTools.Designer.UI.PropertyInspector.EventHandlerModel.GenerateMethodName()
   at Microsoft.VisualStudio.DesignTools.Designer.UI.PropertyInspector.EventHandlerModel.GenerateAndCommit()
   at Microsoft.VisualStudio.DesignTools.Designer.Tools.Selection.ElementEditorBehavior.ProcessDoubleClick(Boolean setDefaultHandler, SceneNode clickedElement)
   at Microsoft.VisualStudio.DesignTools.XamlDesigner.Tools.XamlElementEditorBehavior.ProcessDoubleClick(Boolean setDefaultHandler, SceneNode clickedElement)
   at Microsoft.VisualStudio.DesignTools.Designer.Tools.Selection.ElementEditorBehavior.OnClickEnd(Point pointerPosition, Int32 clickCount)
   at Microsoft.VisualStudio.DesignTools.Designer.Tools.EventRouter.ScopeElement_MouseUp(Object sender, MouseButtonEventArgs args)
   at System.Windows.Input.MouseButtonEventArgs.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 System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, 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.Application.RunDispatcher(Object ignore)
   at System.Windows.Application.RunInternal(Window window)
   at System.Windows.Application.Run(Window window)
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.DesignerProcess.RunApplication()
   at Microsoft.VisualStudio.DesignTools.DesignerContract.Isolation.DesignerProcess.<>c__DisplayClass3_0.<Main>b__0()
   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()

My XAML File:

<Window 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       Title="Closest Neighbor" Height="300" Width="300"> 
       <Grid>
        <TextBox HorizontalAlignment="Left" Height="23" Margin="85,102,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="110,150,0,0" VerticalAlignment="Top" Width="75"/>
    </Grid>
</Window> 

Solution

  • You're missing the reference to the partial class associated with that window which is 'x:Class=[ClassName]' in the Window header.

    <Window x:Class="MyClass"
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       Title="Closest Neighbor" Height="300" Width="300"> 
       <Grid>
        <TextBox HorizontalAlignment="Left" Height="23" Margin="85,102,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
        <Button Content="Button" HorizontalAlignment="Left" Margin="110,150,0,0" VerticalAlignment="Top" Width="75"/>
    </Grid>