I am getting a “Null Reference” exception in many places in the code.that I am testing. However, the exception generated seems to have an invalid message. That is, I believe an exception should be generated, but it should be generated as a different type and not a Null Reference exception
Simple test: If I do not trap the error I receive the error as shown in screen shot 1
Test 2: If I trap the error, capture it and throw a an exception (with a known message) I still get the null reference exception even though I should get the custom message. See Screen Shot 2 for sample output
The following is additional information regarding screenshot 2
The blue arrow is my custom message (shown here using a “Log Message” activity)
The red arrow is the actual exception message (shown using “Log Message”)
After the code generating the text with the red arrow I issue a “Throw” using a system exception with the same custom message as shown with the blue arrow
The black arrow is the message generated by UiPath (corresponding to the message displayed in the pop-up dialog box). This message should be the same as what was stated in the throw activity
The relevant code for test 2 is shown as screenshot 3
The big problem is that the sample above is just an illustration of the issue. For the actual code being tested the problem is occurring in possibly several places in the code, but I am not able to find it since the failing code is not being highlighted and the error message is meaningless.
I suggest you debbug your code an run it step by step to find the problem.
In the Debugger panel you can monitor the value of your variables, somewhere in the process you may think there is a value, but there is not.
Please check if the objects mentioned indeed exist and are populated.
Hello William, makes sense, but had already tried it. As mentioned it seems to happen in several places. In the example above Here is relevant code. (I have revised it to try a few things)
I tried several attempts in debug for it to highlight the correct offending code: the “Throw” statement . and I captured the debug log and local windows as well. (the local window is blank at this point. However, if you take a close log at the log output it is saying the “Throw” action failed to which, I am assuming, it generates the null reference exception. Why?
From what I can tell all information is populated correctly in the THROW properties. The strErrorMessage was used in a previous log statement that was displayed correctly in the log output, so why is the throw having an issue with a null reference? Is it because it is inside a catch block?
If that is the reason, I would have to try to find other failing code and see if this is too the reason, but as previously stated, tracking them down is not an easy task.
AS an additional note: This code is in a subroutine (separate workflow module). If I run the subroutine code by itself it correctly reports the correct exception"could not find an asset…" . However, if I invoke this workflow from some other routine the code fails as noted in above posts. I have checked that all Input and output arguments populated and I ensure that this workflow sets default return values for all output arguments before any of the main portion of this routine is run.
So somehow, the use of the invoke workflow activity is contributing to this issue. At this point I can only think that the .xaml module is somehow corrupted in a way that makes the code appear OK to UiPath, but causes it to fail during execution, when the error condition (asset not found) is encountered.
Is there something else that may contribute to the behaviour?
Thank you