1. Alfredo Santibanez
  2. PowerBuilder
  3. Monday, 4 September 2023 17:52 PM UTC


I have been using an Oleobject to use a C# DLL that signs XMLs required in Latin America, for invoicing.  In the specific case using XADES-EPES.

The PB code looks like: li_rc = loo.ConnectToNewObject("CFeldan_FE.ClassMain").  With the try catch, etc.

That DLL contains functions to sign an XML and make the correspoding POST for the invoice, BUT requieres to use regasm on all client computers.

Looking to avoid the last, I started testing the .DDL import.  With the new 2022R2.

The DLL is imported, I can call the functions, but it does not sign.  Does anyone has an idea or similar cases for possible solutions?

I will try to detail the case bellow and the error:


C# requires references to BouncyCastle.dll and FirmaXadesNet.dll, both public

Code is: (bold is the line that returns the error only if the .DLL es imported in PB)

        public void FirmaXML_Xades(string pathXML, string archivo_firmado, string certificado, string pin ,string NumeroReceptor)

        {   try

            {     X509Certificate2 cert = new X509Certificate2(@certificado,pin);

                XadesService xadesService = new XadesService();

               SignatureParameters parametros = new SignatureParameters();

                 parametros.SignaturePolicyInfo = new SignaturePolicyInfo();

                parametros.SignaturePolicyInfo.PolicyIdentifier = "https://tribunet.hacienda.go.cr/docs/esquemas/2016/v4.1/Resolucion_Comprobantes_Electronicos_DGT-R-48-2016.pdf";

                parametros.SignaturePolicyInfo.PolicyHash = "Ohixl6upD6av8N7pEvDABhEL6hM=";

                parametros.SignaturePackaging = SignaturePackaging.ENVELOPED;

                parametros.DataFormat = new DataFormat();

                parametros.Signer = new FirmaXadesNet.Crypto.Signer(cert);

                 FileStream fs = new FileStream(pathXML, FileMode.Open);

                FirmaXadesNet.Signature.SignatureDocument docFirmado = xadesService.Sign(fs, parametros);



                docFirmado = null;


            catch (Exception ex)

            {  _firma.WriteToFile("error xades" + ex.Message);





Error returned is:

Unable to cast object of type 'System.Security.Cryptography.RSACng' to type 'System.Security.Cryptography.RSACryptoServiceProvider'.


As mentioned above, if called as on OleObject, no error is returned.  The result signed file is created. Even with .dll registered with regasm.  With all Dlls copied on the same folder as the PB app.

I did not find a way to try to sign from pb Code, that might be another option.  But have no idea of PB code to achieve it.

I can send the ddl source if needed and some test values for signing.


Best Regards

Alfredo Santibáñez























Miguel Leeuwe Accepted Answer Pending Moderation
  1. Friday, 8 September 2023 05:57 AM UTC
  2. PowerBuilder
  3. # 1


He probado con tu Helper3, que es una solución .Net 6. El error que recibes cuando se ejecuta "parametros.Signer = new FirmaXadesNet.Crypto.Signer(cert);" no es por culpa de Powerbuilder.
En visual studio, hice una pequeña ventana (windows form .Net6) con un botón que llama a la función firmar(), y cuando llama esa línea de código da el mismo error que describes en la Q&A.
El problema está en que "FirmaXadesNet.dll" y "Microsoft.Xades", ambos archivos están hechas en ".Net framework 4.5".
No soy un experto para nada, pero me parece que .Net6 y .Net Frameworks no funcionan en conjunto.
He mirado si existe una versión .Net6 en https://administracionelectronica.gob.es/ctt/verPestanaDescargas.htm?idIniciativa=firmaxadesnet pero me parece que no hay.
Por lo tanto, la solución para tu problema es quedarte con .Net Framework (helper2) y en tu PB nvo, después  de haber importado tu DLL, en of_createOnDemand() hacer esta modificación:

// Modified by MiguelL:
//ll_status = lnv_assembly.LoadWithDotNet(This.is_AssemblyPath)
ll_status = lnv_assembly.LoadWithDotNetFramework(This.is_AssemblyPath)

En PB2022 R2, HAY que hacer esa modificación, aunque habrá gente que dicen que no hace falta, si no, recibirás otra vez el error que has descrito.



There are no comments made yet.
Bruce Armstrong Accepted Answer Pending Moderation
  1. Wednesday, 6 September 2023 19:25 PM UTC
  2. PowerBuilder
  3. # 2

>>That DLL contains functions to sign an XML and make the correspoding POST for the invoice, BUT requieres to use regasm on all client computers.

You can create a manifest file that contains the registry entries in question and deploy that with your application.  Windows will use that if it finds it rather that looking in the registry.

Creating the manifest file is a bit of work to do manually, but there are tools like http://www.mazecomputer.com/ that can create it for you.





  1. Miguel Leeuwe
  2. Friday, 8 September 2023 05:54 AM UTC
Will try that out for sure, will make life (installations) so much easier !!
  1. Helpful
There are no comments made yet.
Miguel Leeuwe Accepted Answer Pending Moderation
  1. Monday, 4 September 2023 21:26 PM UTC
  2. PowerBuilder
  3. # 3


If you want, I can try and have a look.

  • Is your PB application 32 / 64 bit?
  • Do I need anything else in addition to the single DLL ?
  • Is it a ".Net Standard" or ".Net Framework ..." or ".Net 6 or 7 DLL"?
  • Can you export the nvo that the DLL Importer has generated?


If you don't want to post things here, contact me on https://www.pb.miguell.work/contact and I'll respond to your via email.



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.