-1
I have a C# project that uses the Gov library to access data from a smartcard (citizen card), the Library is called pteidlib_dotnet, which you can find here
I need to create a feature that allows me to digitally sign pdf documents with the Citizen Card, and I think I have the correct code (as it is in the manual that comes with libraries, which can find here in pdf), the problem now, is that when I try to sign the library throws an exception which I can’t find the solution on the internet to solve.
I’ve done a lot of research and I think the problem is related to the init method library that does not recognize the name of my smartcard Reader, but still can not solve (init function I think is called internally, so in my code I do not call it.)
I wanted to come here so ask for help if anyone knows why the exception.
Inner Exception - in en.portugal.Eid.pteidlib_dotNetPINVOKE.SWIGExceptionHelper.. ctor() in en.portugal.Eid.pteidlib_dotNetPINVOKE.. cctor()
Message - The type initializer for en.portugal.Eid.pteidlib_dotNetPINVOKE triggered an exception.
Stacktrace - in en.portugal.Eid.pteidlib_dotNetPINVOKE.Pteid_readerset_instance() in en.portugal.Eid.Pteid_readerset.instance()
Code:
private static void AssinarFicheiros(string[] ficheiros)
{
ficheiros[0] = @"c:\teste\fich1.pdf";
//ficheiros[1] = @"c:\teste\fich2.pdf";
if (ficheiros is null)
return;
string destino = Directory.GetCurrentDirectory() + @"\ficheiros_assinados.zip";
string localizacao = "local";
string razao = "razao";
int pagina = 1;
int sector = 2;
bool isLandscape = false; // TODO: Pode não estar correcto para todos os casos, visto que não conseguimos indentificar se os documentos estão na horizontal.
try
{
using (PTEID_ReaderSet readerSet = PTEID_ReaderSet.instance())
{
for (int i = 0; i < readerSet.readerCount(); i++)
{
using (PTEID_ReaderContext context = readerSet.getReaderByNum(unchecked((uint)i)))
{
if (context.isCardPresent())
{
using (PTEID_EIDCard card = context.getEIDCard())
{
using (PTEID_PDFSignature signature = new PTEID_PDFSignature())
{
if (ficheiros.Length == 1)
{
signature.addToBatchSigning(@"c:\teste\fich1.pdf");
signature.enableSmallSignatureFormat();
signature.enableTimestamp();
// Aqui lança a exceção CSharp_EIDMW_ERR_PINREF_NOT_FOUND_get quando tenta executar esta linha de código.
card.SignPDF(signature, pagina, sector, isLandscape, localizacao, razao, destino);
}
else
{
//card.SignPDF(destino, ficheiros, unchecked((uint)ficheiros.Length));
}
}
}
}
}
}
}
}
catch (Exception exc)
{
MessageBox.Show(exc.ToString());
}
}
If anyone can guide me in the direction where I can find the solution it would help enough.
Thank you in advance for any reply.
Also add the exception details such as message, stacktrace and Inner Exception.
– tvdias
The post has been updated, thank you!
– BarrosKing
It’s not related to your
destino
? The file exists and it will, in fact, be able to include the signed document within a.zip
?– Leandro Angelo
It worked! Thank you very much, I saw that the manual "Middleware, contained an error! The destination must be a folder and not a file!
– BarrosKing