1. Roland Smith
  2. PowerBuilder
  3. Monday, 24 January 2022 20:56 PM UTC

I'm investigating using a .Net Assembly that our C# based web app uses, within our PowerBuilder desktop app. I am getting the following message from the CreateInstance function:

Constructor on type 'OfficeOpenXml.ExcelPackage' not found.

This code is the vendor's simple Hello World example:

// var file = new FileInfo(@"c:\temp\myWorkbook.xlsx");
// using(var package = new ExcelPackage(file))
// {
// var sheet = package.Workbook.Worksheets.Add("My Sheet");
// sheet.Cells["A1"].Value = "Hello World!";
//
// // Save to file
// package.Save();
// }

I tried using the .Net Importer and regular script as seen below and got the same error. I got the classname from the generated object. I am passing the file name as an argument to CreateInstance just like the C# snippet does. What do I need to do differently?

DotNetAssembly ldn_Assembly
DotNetObject ldn_Package
Long ll_return
String ls_dllfile, ls_classname

ls_dllfile = "C:\PBSource\PB2021\EPPlus\EPPlus.dll"
ls_classname = "OfficeOpenXml.ExcelPackage"

ldn_Assembly = Create DotNetAssembly

ll_return = ldn_Assembly.LoadWithDotNetFrameWork(ls_dllfile)
If ll_return < 0 Then
Messagebox("Load Assembly Failed", ldn_assembly.ErrorText, StopSign!)
Return
End If

ldn_Package = Create DotNetObject

ll_return = ldn_Assembly.CreateInstance(ls_classname, ldn_Package, ls_dllfile)
If ll_return < 0 Then
Messagebox("Create Instance Failed", ldn_assembly.ErrorText, StopSign!)
Return
End If

Destroy ldn_Assembly
Destroy ldn_Package

Francisco Martinez @Appeon Accepted Answer Pending Moderation
  1. Monday, 24 January 2022 21:23 PM UTC
  2. PowerBuilder
  3. # 1

Hi Roland,

The CreateInstance function's 3rd argument is not the path to the binary. You can refer to the documentation here. The third argument is used to pass arguments to the constructor of the object you're instancing. By passing it that 3rd argument, PowerBuilder tries to look for a constructor with a String-type argument, which does not exist. Hence the error. To solve this, remove the 3rd parameter.

Hope this helps.

Regards,
Francisco

Comment
  1. Roland Smith
  2. Monday, 24 January 2022 22:06 PM UTC
You are right, it wants the Excel file name. I checked the documentation and it has 14 different constructors. One of them takes a string. I still get the same error.
  1. Helpful
  1. Roland Smith
  2. Monday, 24 January 2022 22:10 PM UTC
  1. Helpful
  1. Francisco Martinez @Appeon
  2. Monday, 24 January 2022 23:11 PM UTC
I can instantiate objects with constructors with parameters without issue. The issue might lie somewhere else. Is the version of the documentation the same as the binary? Can you verify that the class contains the specific constructor by using tools such as ILSpy (https://github.com/icsharpcode/AvaloniaILSpy)?
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.