none
RemoveHandler throws NullReferenceException when there's no handler registered and ExcelLocale1033 is set to false RRS feed

  • Question

  • Although documentation is not clear about RemoveHandler Statement behavior ( http://msdn.microsoft.com/en-us/library/3xz97kac(v=VS.90).aspx ), some other similar RemoveHandler methods (like UIElement.RemoveHandler Method http://msdn.microsoft.com/en-us/library/system.windows.uielement.removehandler(v=VS.90).aspx) state that

    "Calling this method has no effect if there were no handlers registered with criteria that matches the input parameters for the method call."

    However, if I set ExcelLocale1033(False) in AssemblyInfo.vb I get NullReferenceException when I call RemoveHandler to a workbook which has no handlers for SheetFollowHyperlink event:

    RemoveHandler workbook.SheetFollowHyperlink, AddressOf FollowHyperlinkEventHandler

    On the other hand, I get no exceptions when ExcelLocale1033 is set to True. (I ran into this while I was, and I am still, trying to solve the LCID problem, and that's why I'm messing up with ExcelLocale1033)

    Tuesday, May 3, 2011 12:58 AM

Answers

  • Hi FerchoArg,

    What's the version of your Office application and your PIA?

    >>On the other hand, I get no exceptions when ExcelLocale1033 is set to True.

     As far as I know, the ExcelLocale1033 attribute controls the locale that is passed to the Excel object model. Setting ExcelLocale1033 to true causes the Excel object model to act the same in all locales, which matches the behavior of Visual Basic for Applications. Setting ExcelLocale1033 to false causes the Excel object model to act differently when users have different locale settings, which matches the behavior of Visual Studio Tools for Office, Version 2003. This can cause unexpected results in locale-sensitive information. So, I suggestion you set it to true to avoid unexpected exceptions.

    Hope this can give you the hint.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Bruce Song Tuesday, May 10, 2011 8:25 AM
    Thursday, May 5, 2011 4:56 AM