Visual Studio Developer Center > Visual Studio Forums > Visual Studio Extensibility > VSShell/Editor Package: Cancelling a designer resize action in IComponentChangeService.OnComponentChanging(...) causes a NullRefException in System.Design
Ask a questionAsk a question
 

QuestionVSShell/Editor Package: Cancelling a designer resize action in IComponentChangeService.OnComponentChanging(...) causes a NullRefException in System.Design

  • Tuesday, May 05, 2009 4:19 PMFBNitro Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    In my VsShell project, I have a DesignerWindowPane, which handles the IComponentChangeService.OnCompontentChanging() event. 
    According to the documentation on the MSDN, I'm supposed to throw an exception if I want to stop the Change from occuring.  http://msdn.microsoft.com/en-ca/library/system.componentmodel.design.componentchangingeventargs.aspx

    When this gets called (just like the ComponentAdding/Removing) I check if Source Control allows edits, which prompts the user, and if they cancel (or someone else has the file checked out etc) I throw an exception.  This exception works great for OnComponentAdding/Removing and for 99% of the ComponentChanging scenarios it works.  If I modify a property or drag a control that's on the form, it works correctly.  If I resize a control via the property box (size property), it cancels the change correctly. 

    But, if I try to resize the form using a control's resize container it throws an exception and crashes the Shell.  The stack is indicating this isn't a problem in my code (entire exception below).  Does anyone have any suggestions, or should I raise the issue for MS to investigate?

    The Exception I'm throwing in the ComponentChanging handler is InvalidOperationException("My text")

    Using:
    VsShell 1.1
    VS 2008 SP1
    Windows XP Prof

    Exception:
    System.NullReferenceException was unhandled
      Message="Object reference not set to an instance of an object."
      Source="System.Design"
      StackTrace:
           at System.Windows.Forms.Design.Behavior.BehaviorService.AdornerWindow.MouseHook.MouseHookProc(Int32 nCode, IntPtr wparam, IntPtr lparam)
      InnerException:


    • Edited byFBNitro Tuesday, May 05, 2009 5:16 PM
    • Edited byFBNitro Tuesday, May 05, 2009 4:21 PMtypo
    •  

All Replies

  • Wednesday, November 04, 2009 5:52 PMFBNitro Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Connect issue raised, reproduced the issue with a small change to the Iron Python code:
    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=489964#details