Question
Call Automation from C#.. Stuck with error: Exception thrown: 'System.NullReferenceException' in OpenSpan.Runtime.Core.dll Object reference not set to an instance of an object.
Hi,
I've been trying to experiment with calling an automation from C#, but am experiencing an nullReference error on creating new instance of the automation reference.. I used two articles to base my code on (https://pdn.pega.com/example-using-studio-adapters-c-project & https://pdn.pega.com/documents/creating-csharp-studio-project-references) Both suggest I can easily make the call, but I get a failure on the cca = new CcallingActivity.Project.CcallingActivity(); line of code. I've included all the pega references I could find, and the project compiles without error. Must be missing something.. But figure out what/where to look? this is Pega Robotics v8.0 with .net 4.6.1
The code I'm using is below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
using OpenSpan.Diagnostics;
namespace caCaller
{
class Program
{
public static CcallingActivity.Project.CcallingActivity cca;
public static CcallingActivity.simpleAdd sa;
static void Main(string[] args)
{
try
{
Diagnostic.Initialize();
Diagnostic.TraceError("Starting");
cca = new CcallingActivity.Project.CcallingActivity();
cca.Start();
}
catch (Exception err)
{
Debug.WriteLine(err.Message);
}
}
}
}
The exception being thrown may be indicating that your code is trying to access an object that either doesn't exist yet, or has already been destroyed. You may need to manipulate the build order so that everything for OpenSpan is already configured and ready to go before you start calling your own code.
http://help.openspan.com/80/Using_Studio/Solution_Property_Pages.htm