MapInfo Pro Developers User Group

 View Only
  • 1.  Legacy tool throws Null Reference exception

    Posted 09-07-2020 09:04
    Hi there
    I am new in the field. I have been assigned a task to troubleshoot a legacy tool, failing to load in MapInfo 15.0.
    This tool was working properly with MapInfo 12.0 but not any more.
    Uses menus instead of Ribbon. My suspicion is there is some additional initialisation that needs to be added to the .mb file but his is only guessing as the tool has been developed by someone else and my experience in writing plugins is limited.

    The code called when the one menu item which loads the tool is clicked is trying to register a UserControl to a dock window. It succeeds but any attempt to access the resulting window, as in setting dock state, docking, floating or even setting the window title throws a NullReferenceException.

    This is a cut down version of the code in the static method of the Controller:class

    _miApp = InteropServices.MapInfoApplication
    _layerControlDlg = New TableManagerControl(New Controller())
    _dockWindow = _miApp.RegisterDockWindow(_layerControlDlg.Handle)

    The code succeeds, _dockWindow is not null but apparently some COM stuff is not initialised as anytime anyone attempts to access or use _dockWindow in any way there is a NullReferenceException coming from the interop.
    I even tried to use a dummy, empty user control instead of TableManagerControl to make sure it's not something the TableManagerControl is causing, no luck, same issues.

    As I said the concept of calling a static method from the menu may be the issue, but It's really a guess...

    Any insight would be very much appreciated

    Thanks
    Kostas Christodoulou

    ------------------------------
    Kostas Christodoulou
    Knowledge Community Shared Account
    ------------------------------


  • 2.  RE: Legacy tool throws Null Reference exception

    Employee
    Posted 09-08-2020 16:29
    Hi Kostas,

    First question to be clear, is are you running this in v15.0 32 bit or a 64 bit version?

    -Bob

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 3.  RE: Legacy tool throws Null Reference exception

    Posted 09-09-2020 04:07
    Good morning Bob
    Thank you finding the time to answer. It's 64-bit. If you need more info the legacy application is written in VB.NET. I tried building the plugin in x64 and AnyCpu with no luck, same behaviour. In my desperation I even tried x32 build but with no luck :-).
    Also, this window NullReferenceException issue seems to be the only issue with using the tool in MapInfo 15.0, at least as far as the tool goes before crashing. Logs to a database, loads maps and layers all successfully. But the tool window is invalid...
    Please let me know if you need any more information that might help.

    Kostas

    ------------------------------
    Kostas Christodoulou
    Knowledge Community Shared Account
    ------------------------------



  • 4.  RE: Legacy tool throws Null Reference exception
    Best Answer

    Employee
    Posted 09-09-2020 09:53
    Hi Kostas,

    First, the bad news: Starting with the 64 bit versions, our docking manager changed and we no longer supported the COM based docking APIs.
    Recently we have been bringing back some old COM functionality to assist people like you with older apps moving to 64 bit. I have filed a bug for us to investigate if it is possible to get COM docking working again. I am not sure yet if it will be possible and it would be in 2019.3 or later if we can do it.

    Now for the hopeful part -- since you are using .NET you could use the new docking manager apis for which we have samples. This does require an in process add-in built into an .mbx. Is your app an EXE or do you already have it built as an add-in mbx?

    If it is an EXE, maybe there is some hybrid approach with small add-in that your app could talk to.

    -Bob

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 5.  RE: Legacy tool throws Null Reference exception

    Posted 09-09-2020 10:12
    Hey Bob
    Thank you for all the insight.
    I was sure there would be bad news :-).
    The plugin is already building as .mbx.
    So sounds like, even if it COM functionality is supported in future versions (not sure if and when TfL is going to upgrade and I am quite sure they would not upgrade just for this :-)), your suggestion would be to port the tool to -practically- not being legacy anymore.
    Would it be possible to also point to the samples location? I need to provide an estimate for potential refactoring and having a sample would help putting my head around how much effort may be required, especially given that, I am not the author of the legacy code.

    Thank you once more for your support.

    ------------------------------
    Kostas Christodoulou
    Knowledge Community Shared Account
    ------------------------------



  • 6.  RE: Legacy tool throws Null Reference exception

    Employee
    Posted 09-09-2020 10:45

    Kostas,

    The samples are included with the mapbasic install under Samples\RibbonInterface\DotNet

    ProSampleAddin shows how to dock a windows forms control.
    There is also a docking manager sample and many others although in version 15 there would be less than we have now.
    You could probably keep most of you app the same except for the docking part if you wanted to.

    Here is the code from ProSampleAddin to dock a windows forms control:

    var properties = new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>("WindowName", "Reproject"), new KeyValuePair<string, string>("DockState", "Dock"), new KeyValuePair<string, string>("CanFloat", "True"), new KeyValuePair<string, string>("CanFloat", "True"), new KeyValuePair<string, string>("DesiredWidthInDockedMode", "200"), new KeyValuePair<string, string>("Dock", "Right"), new KeyValuePair<string, string>("Name", "ProSampleAddin__reproject"), new KeyValuePair<string, string>("SideInDockedMode", "Right") }; var window = new WindowsFormControl() { Name = "Reproject" }; SetWindowLong(window.Handle, GWL_STYLE, GetWindowLong(window.Handle, GWL_STYLE) | WS_CHILD); ReprojectWindow = _application.DockingManager.DockUserControl(window.Handle, "Reproject", properties); ​
    -Bob

    ------------------------------
    Bob Fortin
    Software Architect and Distinguished Engineer
    MapInfo Pro Development Team
    ------------------------------



  • 7.  RE: Legacy tool throws Null Reference exception

    Posted 09-10-2020 03:55
    Thank you very much for the support Bob. I will find the samples one way or another. Looks like it's a straightforward change, which it may need some additional changes but all in all seems to be simple.
    I have marked you answer as best reply, I may get back to you if I have any other strange issues. I promise it will have to be strange to bother you :-).

    ------------------------------
    Kostas Christodoulou
    Knowledge Community Shared Account
    ------------------------------