简体   繁体   中英

Calling PowerBuilder.NET Assembly From a C# Assembly Always Returns Null or Empty String

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

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.

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");
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM