Posted: 25 Oct 2018 14:28 EDT Last activity: 17 Feb 2021 10:12 EST
How to Use Custom Entities as Out Parameters in C# script methods
Using Visual Studio 2015, I have created a .NET project with a custom entity class for passing around data. I can successfully reference it with OpenSpan projects (plugin version 8.0.1103). I can also use it in automations' Execute parameters, as well as reference the class inside of C# script components. Everything builds, and seems to work fine... until...
The one deal breaker seems to be when trying to use the custom class as an out parameter in a C# script component public method (it works for a private method). The error message when validating indicates the assembly cannot be loaded. So it seems I am unable to pass this custom class to an automation via a script method's out parameter. As noted, I can reference the custom class just fine in an automation... just not via a script's out parameter.
Does anyone have a suggestion as to how to get around this problem?
I tried to do the same thing and it works fine for me. My solution is attached and MyCustomType.dll with custom type as well. Make sure the dll is placed into Pega Robotics Plug-In installation folder. Please try to run it and see if it works for you as well.
Thank you for trying to help Konstantin, and for providing example code. The error message was "Could not load type 'XYZ' from assembly". And whether it gives an error or not is literally a matter of making the method public versus private, as mention in my original post.
By the way, it is no longer be necessary to place DLL in installation folder with this version. It can be referenced where it is located, or the .NET class library project from which it comes can be referenced directly.
Although your simple example does indeed work, a more complex example does not work. I modified the code example you provided to use a custom entity class. I created a generic list of this entity (i.e. - List<MyEntityClass>) as an out parameter. I saw the same error as I saw before. Based on your example, it got me thinking, and I tried a simple generic List of integers (List<int>), and I was able to get that to work without issue. It seems the problem is that OpenSpan cannot handle generic lists of custom classes.
I have uploaded a modified version of your code example, in case you want to look further. However, I suspect I have run into an OpenSpan limitation, which is unfortunate.
I see what you are saying - I had troubles with generics few times too.
However, for this solution, I have changed access modifier of the method to public and it doesn't show an error for me. It assigns incorrect method name, though, so I had to move it to separate script to fix that. Eventually, I am able to build successfully and it shows me all Customer Names from List<MyDataStructure>.
As far as I can see, the only thing that differs for us is Pega Robotics version. I use 8.0.2009 while yours is 8.0.1103. Please try to upgrade and see if it helps.
I downloaded your latest solution, and edited the XML for the project file and automation file, so that it would open in my version. The error is still there unless I change the access modifier to "private". Unfortunately, we are not able to change versions that easy, as it requires matching QA and prod environments along with dev. But good to know it might work in a future version.