Object Reference error in invoke code workflowinvoker.invoke method

I am trying to invoke log message activity in invoke code but getting object reference error at workflowinvoker.invoke method
Code inside invoke code:
Dim logMessage As UiPath.Core.Activities.LogMessage = New UiPath.Core.Activities.LogMessage()
logMessage.Level = New InArgument(Of LogLevel)(LogLevel.Error)
logMessage.Message = New InArgument(Of Object)(“abcd”)
Dim logInvoker As System.Activities.WorkflowInvoker = New System.Activities.WorkflowInvoker(logMessage)
logInvoker.Invoke()

1 Like

@Nirav_Gajera

Try changing lomessage variable to something else

Cheers

Object Reference not set to an instance of an object means the variable is not initialized (it’s null). This means your calling workflow does not have a value for that argument.

The same code is working fine inside the library but when I tried to use the same in the new project, it is throwing object reference error at invoke method. System.activities package is also same and imports are also matching so I am wandering what could be the issue here

@Nirav_Gajera

So are you trying to use that created log mesage method in the workflow?

If so it might not work as they are two different instances also

Cheers

No, I am using same pice of code but it works inside the library which is not connected to any of the project. Now I have to use it in entirely new project, so I did the same by dragging invoke code activity and writting same lines but it is not working in this new project. I am quite aware what object reference is and here object is initialised but somehow object reference error at invoke method.

Log message object is initialised and has all the arguments set up correctly, I am not sure why object reference error at invoke method. Also it is working fine in other independent Library so I am just wandering if it is import issue or something like that but not sure as imports are also matching and package is also matching with that library.

Check and see if you accidentally have a variable with the same name as the argument. I’ve done this and pulled my hair out for a while trying to find the problem.

Another problem may be that you have the default of a variable/argument that includes another variable/argument. For example:

That will cause an Object Reference error.

It is also not the case, I am sharing the code block that I am using inside Invoke code. Any suggestion is appreciated.

	Try 
		Dim logMessage1 As UiPath.Core.Activities.LogMessage = New UiPath.Core.Activities.LogMessage()
		logMessage1.Level = New InArgument(Of LogLevel)(LogLevel.Error)
		logMessage1.Message = New InArgument(Of Object)("ABC")
		Dim logInvoker As WorkflowInvoker = New WorkflowInvoker(logMessage1)
		logInvoker.Invoke()
	Catch e As Exception
		Console.WriteLine(e.Message)
	End Try

+1 - same problem here, Studio 2024.10.1, UiPath.System.Activities v24.10.3