mapaction / mapaction-toolbox

A collection of tools to help streamline the process of producing maps including data renaming and map exports.
GNU General Public License v3.0
3 stars 1 forks source link

PageLayoutProperties.getLayoutTextElements returning null values #142

Closed andrewphilipsmith closed 7 years ago

andrewphilipsmith commented 8 years ago

Using this commit: https://github.com/mapaction/mapaction-toolbox/commit/473cec9a91639078e265f2b32e032a313c4a8198

The FormLoad event for both the Layout tool and the Export tool fails with a System.NullReferenceException. In both cases exception occurs after a reference to MapAction.PageLayoutProperties.getLayoutTextElements(_pMxDoc, target_mapframe);

On FormLoad for the Layout tool

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at MapActionToolbars.frmLayoutMain.frmMain_Load(Object sender, EventArgs e) in c:\Program Files (x86)\Jenkins\jobs\MapExportTool\workspace\arcgis10_mapping_tools\MapActionToolbars\frmLayoutMain.cs:line 97
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

On FormLoad for the Export tool


just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
   at MapActionToolbars.FormValidationExport.validateMapTitle(Control control, ErrorProvider eprWarning, ErrorProvider eprError) in c:\Program Files (x86)\Jenkins\jobs\MapExportTool\workspace\arcgis10_mapping_tools\MapActionToolbars\FormValidationExport.cs:line 54
   at MapActionToolbars.frmExportMain.frmMain_Load(Object sender, EventArgs e) in c:\Program Files (x86)\Jenkins\jobs\MapExportTool\workspace\arcgis10_mapping_tools\MapActionToolbars\frmExportMain.cs:line 129
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)```
andrewphilipsmith commented 8 years ago

Having only had a brief look at this, a couple of observations:

andrewphilipsmith commented 8 years ago

I have reverted merge #132 from the master branch.

To re-merge file changes form this branch some point in the future will require "reverting-the-revert". ie

git revert 09cee17d0ac7b9993c0da83d9aff6290e4278b80

See http://www.christianengvall.se/undo-pushed-merge-git/

andrewphilipsmith commented 8 years ago

Doing this revert seems to have fixed this bug, based on the master branch. I've removed the "Critical" priority label as a result.

@kes1 , Is it possible/helpful to merge branch map-template-tests into one of your working branches as you continue to work on this?

andrewphilipsmith commented 7 years ago

Digging around this problem, it seems that this issue seems to be related to the presence of characters related to markup (but not used as markup) in the text. Known problematic characters are &<>, but this list is not exhaustive. See ArcObjects - Using text formatting tags for more details.

It may be possible to handle individual problem characters with something like: temp = System.Text.RegularExpressions.Regex.Replace(temp, "&(?!amp;)", "&amp;");

However we might want a more general string sanitation method. Also we should add tests to prevent regressions on this.

andrewphilipsmith commented 7 years ago

Closed by a93d764d87b7f1a01a332d6db32c52e8b1255bab