[HTML Comments] Unhandled `TargetInvocationException` when clicking on converted RTF task links Topic is solved

Moderator: abstr

Locked
fjeronimo
Posts: 43
Joined: Sat Oct 12, 2019 3:14 pm

[HTML Comments] Unhandled `TargetInvocationException` when clicking on converted RTF task links

Post by fjeronimo » Sun Oct 25, 2020 11:53 am

Hi Dan,

ToDoList version: 8.0.9.0

I've been playing with the now built-in ConvertRTFToHTML tool and came across the following issue when converting tasks with links to other RTF tasks.

Steps to reproduce:

Code: Select all

1. Create new tasklist
2. Add a RTF task.
3. Add second RTF task.
4. Add any content to the second task (a single character will do).
5. Right click the second RTF task and copy it as a task link.
6. Paste link in the first task.
7. Save tasklist and use RTFToHTMLConverter.
Outcome:

Clicking the link of the first task on the converted tasklist leads to the following .NET Framework unhandled exception (although the link still gets followed):
UnhandledTargetInvocationException.png
UnhandledTargetInvocationException.png (10.88 KiB) Viewed 1720 times

The stack trace is:

Code: Select all

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: Value does not fall within the expected range.
   at MSHTML.IHTMLTxtRange.moveToElementText(IHTMLElement element)
   at MSDN.Html.Editor.HtmlEditorControl.SelectElement(HtmlElement element)
   at HTMLContentControl.TDLHtmlEditorControl.OnDocumentMouseUp(Object sender, HtmlElementEventArgs e)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Windows.Forms.HtmlShim.FireEvent(Object key, EventArgs e)
The outcome is the same whether we use MS Word or not for the conversion.

I've attached an input tasklist created by following the above steps (RTFTaskLinks-WithContent.tdl), alongside with the result of the conversion (CONVERTED_RTFTaskLinks-WithContent.tdl).

What's quite interesting is that the entire converted tasklist seems to have HTML task links messed up from then on. If you create a new HTML task and try to create new links to and from it, they will all fail with the above error (which does not happen for RTF links nor does it happen on a fresh new tasklist).

Other scenarios

* If you omit step 4 and don't add any content to the second task (RTFTaskLinks-WithoutContent.tdl), then the problem does not occur (CONVERTED_RTFTaskLinks-WithoutContent.tdl). I also noticed that the second task still remains as an RTF task after conversion which might explain why this happens.
* This is a minor one, but if you have RTF task links wrapped in parenthesis -- e.g. (tdl://2) -- they will not be converted as links in HTML but instead plain text.
Attachments
CONVERTED_RTFTaskLinks-WithoutContent.tdl
(3.23 KiB) Downloaded 173 times
RTFTaskLinks-WithoutContent.tdl
(3.41 KiB) Downloaded 186 times
CONVERTED_RTFTaskLinks-WithContent.tdl
(3.98 KiB) Downloaded 183 times
RTFTaskLinks-WithContent.tdl
(4.3 KiB) Downloaded 182 times

User avatar
abstr
Site Admin
Posts: 370
Joined: Sun Jul 28, 2019 12:22 pm

Re: [ConvertRTFToHTML] Unhandled `TargetInvocationException` when clicking on converted RTF task links

Post by abstr » Mon Oct 26, 2020 9:26 am

Thx Frederico, I really appreciate the extra mile that you go.

[Update] I was completely lost until I happened to notice that the converted task WITHOUT the 'g' comments was still in RTF format, presumably because I avoid the conversion if the comments are empty (I'll fix this later).

Then I tried changing the converted task WITH the 'g' comments back to RTF and the exception stopped. Which suggests that it's not the clicking of the link that is causing the exception it's the switching to the second task...

Furthermore, as an optimisation I reuse the comments field when switching tasks if the comments type has not changed.

So what I'm imagining is: At the moment I replace the content of the first task (tdl://2) with the content of the second task (g), something internally is still 'holding on' to the content of first task which unfortunately is now 'dead' and this causes an exception.

And the test that 'proves' this is to create a new tasklist manually, having the same tasks both of which have HTML comments, then watch the exception occur.

User avatar
abstr
Site Admin
Posts: 370
Joined: Sun Jul 28, 2019 12:22 pm

Re: [HTML Comments] Unhandled `TargetInvocationException` when clicking on converted RTF task links

Post by abstr » Sun Nov 01, 2020 1:54 am

Fixed in 8.0.10

Locked