1

I have a C# assembly that is calling a PowerBuilder.NET(12.1 Build 7217) assembly. The PowerBuilder source code is contained below, you can see it is a rather simple true/false evaluation of a string.

When the PB.NET assembly is called by a Window in C#, it returns the expected result of "true". When the same code is called by a C# assembly, the code returns "", or an empty string.

I have managed to narrow the problem down to the DataStore interactions in the PB.NET assembly. If the PB.NET assembly is called from another assembly, the DataStore always has 0 rows and contains only empty strings. Has anyone seen or dealt with this before?

// Create instance of Datastore
ldsExpression = CREATE DataStore

// Set data object
ldsExpression.DataObject = "d_condition_expression"

//// Setting datawindow expression
lsExpression = 'condition_expression.expression = ~"' + asConditionExpression + '~"'

//// Apply Expression
lsError = ldsExpression.Modify(lsExpression)

IF len(lsError) = 0 THEN
    ldsExpression.InsertRow(0)

    //get the result
    lsResult = ldsExpression.GetItemString(1,"condition_expression") 
ELSE
    lsResult = lsError
END IF

// Destroy instance of ldsExpression
DESTROY(ldsExpression)

RETURN lsResult
Fatal Zio
  • 11
  • 1
  • 2

2 Answers2

0

I see you are dynamically assigning a dataobject and I wonder if it is being included in the final assembly-- this is just a guess. This is similar to the problem that used to occur in a standard PB program when compiling to PBD's but not adding dynamically assigned dataobjects in the PBR file.

Another thing that I'd look at is 'use dot net nullable types" setting in .NET Assembly Target Properties-- another guess. Here is the documentation from Sybase.

http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.help.pb.12.5/title.htm

I think it has something to do with the dataobject not being built into the assembly as you describe it as never having any rows.

Rich Bianco
  • 4,141
  • 3
  • 29
  • 48
  • The dataobject is included in the PowerBuilder assembly. The problem is that it cannot be called by another assembly (which I need to do for my application). PowerBuilder.NET assemblies can only be called by a Window or a Windows Service it seems. As soon as I change the Output Type to Library in Visual Studio, the calls to PB.NET don't work anymore. I posted the workaround I found below. – Fatal Zio Jul 23 '13 at 19:54
0

I actually found a work-around for this. It really looks like a PowerBuilder.NET bug that should be addressed in future versions. Calling the PowerBuilder.NET assembly works when called by a Window or a Service but does not work if called by regular DLL assembly.

I found ONE exception to the rule. A PowerBuilder.NET assembly CAN be called by a C# assembly IF it is called by a Window or Service first within the same application. I'm thinking this is because the object remains in memory after the first call and gets reused from there.

Luckily my application consists of a Service that launches several threads contained in a C# assembly. I added this call to the Main method of my Service, and all of the subsequent calls to EvaluateExpression work perfectly regardless of where they are called from.

Here is the link to my Sybase/SAP thread on the issue. http://scn.sap.com/thread/3391198

    private static string Evaluate(string expression)
    {
        var blah = new PowerBuilderAssembly();

        return blah.EvaluateExpression(expression);
    }

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main(string[] args)
    {

        var result = Evaluate("1 = 1");
    }
Fatal Zio
  • 11
  • 1
  • 2