DotNet, The function call was ambiguous, no matching method was found.

Rodtmclean
Member Posts: 89
Hi,
I'm making use of DotNet within NAV, I have touched on it before but having issues as below. The DotNet library in use is System.Security.Cryptography.DSASignatureFormatter.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Many thanks, if there are any general pointers or articles that would be great.
I'm making use of DotNet within NAV, I have touched on it before but having issues as below. The DotNet library in use is System.Security.Cryptography.DSASignatureFormatter.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
Many thanks, if there are any general pointers or articles that would be great.

0
Best Answers
-
Thanks xStepa,
I'm struggling a bit with Generics/Reflection. I've experimented quite a bit and still getting errors regarding types. There are likely a few basic assumptions I've made, needing to learn cryptography concepts at the same time
The Error Message I'm having is
I've marked the code with ***** Important part below, hopefully someone can point me to the next part.
Many Thanks
Roddy// Arr := Arr.CreateInstance(GETDOTNETTYPE(Type),2); // Arr.SetValue(GETDOTNETTYPE(String),0); // Arr.SetValue(GETDOTNETTYPE(Int),1); // // Arr2 := Arr2.CreateInstance(GETDOTNETTYPE(Type),2); // Arr2.SetValue(GETDOTNETTYPE(String),0); // Arr2.SetValue(GETDOTNETTYPE(Int),1); // // Type := GETDOTNETTYPE(Dict); // Type := Type.MakeGenericType(Arr); // // Dict := Activator.CreateInstance(Type); // Dict.Add('test123',0); //Swapped to using Array of Bytes as above was the wrong type Arr := Arr.CreateInstance(GETDOTNETTYPE(Type),2); Arr.SetValue(GETDOTNETTYPE(Byte),0); Arr.SetValue(GETDOTNETTYPE(Int),1); Arr2 := Arr2.CreateInstance(GETDOTNETTYPE(Type),2); Arr2.SetValue(GETDOTNETTYPE(Byte),0); Arr2.SetValue(GETDOTNETTYPE(Int),1); Type := GETDOTNETTYPE(Dict); Type := Type.MakeGenericType(Arr); Dict := Activator.CreateInstance(Type); NavByte := 65; Dict.Add(0,NavByte); Dict.Add(1,NavByte); Dict.Add(2,NavByte); Dict.Add(3,NavByte); X509Cert2 := X509Cert2.X509Certificate2('C:\ros\rct\Castle_PIT1.p12', CertPassword); //MESSAGE('Issuer Name %1 \Issuer %2 \Private Key %3', X509Cert2.IssuerName, X509Cert2.Issuer, FORMAT(X509Cert2.HasPrivateKey)); PrivateKey := X509Cert2.PrivateKey; //MESSAGE(PrivateKey.ToString); RSASign := RSASign.RSAPKCS1SignatureFormatter(PrivateKey); RSASign.SetHashAlgorithm(X509Cert2.GetCertHashString); //***** Important part :smile: //value to be hashed gets passed in here in Arr, signed value is returned to Arr2 Arr2 := RSASign.CreateSignature(Arr); //Reflection/Generics - failed attempt // RSASignType := RSASign.GetType; // MethodInfo := RSASignType.GetMethod('CreateSignature'); // Parameters := Parameters.CreateInstance(GETDOTNETTYPE(RSASignType),0); // Parameters.SetValue(GETDOTNETTYPE(RSASign), 0); // // MethodInvoke := MethodInfo.MakeGenericMethod(Parameters); // Parameters := Parameters.CreateInstance(GETDOTNETTYPE(RSASign),1); // Parameters.SetValue(RSASign, 0); // SignedHashVal := MethodInvoke.Invoke(NullElement, parameters);
0 -
Hi Roddy,
it was just a sample of an heterogenous array (string & int). You have to use the requested type (Byte[]). So you can use one-dimensional Arr.CreateInstance(GETDOTNETTYPE(Byte), 1) orArr := Encoding.Default.GetBytes(PassOrWhatEver)
Regards
xStepa1
Answers
-
I would say you get this message because the CreateSignature()-function has 2 different options as parameter and you are passing a regular Text variable?
The parameter that is expected is either of type Byte[] or HashAlgorithm.
(https://msdn.microsoft.com/en-us/library/system.security.cryptography.dsasignatureformatter(v=vs.110).aspx)
The link also has an example in DotNet code.1 -
Thanks for the reply kdno_be.
I'm having a look at that link just now. Picking up DotNet as I progress this project. I am trying to pass in C/AL text, the code is C/AL rather that C#. I was using a Text variable, switched to type Byte in C/AL with the same result.
Regards
Roddy1 -
Byte is not a Byte[] type - use System.Array instead ...
vjeko.com/generics-in-net-interop-for-nav-2013/Regards
xStepa1 -
Thanks xStepa,
I'm struggling a bit with Generics/Reflection. I've experimented quite a bit and still getting errors regarding types. There are likely a few basic assumptions I've made, needing to learn cryptography concepts at the same time
The Error Message I'm having is
I've marked the code with ***** Important part below, hopefully someone can point me to the next part.
Many Thanks
Roddy// Arr := Arr.CreateInstance(GETDOTNETTYPE(Type),2); // Arr.SetValue(GETDOTNETTYPE(String),0); // Arr.SetValue(GETDOTNETTYPE(Int),1); // // Arr2 := Arr2.CreateInstance(GETDOTNETTYPE(Type),2); // Arr2.SetValue(GETDOTNETTYPE(String),0); // Arr2.SetValue(GETDOTNETTYPE(Int),1); // // Type := GETDOTNETTYPE(Dict); // Type := Type.MakeGenericType(Arr); // // Dict := Activator.CreateInstance(Type); // Dict.Add('test123',0); //Swapped to using Array of Bytes as above was the wrong type Arr := Arr.CreateInstance(GETDOTNETTYPE(Type),2); Arr.SetValue(GETDOTNETTYPE(Byte),0); Arr.SetValue(GETDOTNETTYPE(Int),1); Arr2 := Arr2.CreateInstance(GETDOTNETTYPE(Type),2); Arr2.SetValue(GETDOTNETTYPE(Byte),0); Arr2.SetValue(GETDOTNETTYPE(Int),1); Type := GETDOTNETTYPE(Dict); Type := Type.MakeGenericType(Arr); Dict := Activator.CreateInstance(Type); NavByte := 65; Dict.Add(0,NavByte); Dict.Add(1,NavByte); Dict.Add(2,NavByte); Dict.Add(3,NavByte); X509Cert2 := X509Cert2.X509Certificate2('C:\ros\rct\Castle_PIT1.p12', CertPassword); //MESSAGE('Issuer Name %1 \Issuer %2 \Private Key %3', X509Cert2.IssuerName, X509Cert2.Issuer, FORMAT(X509Cert2.HasPrivateKey)); PrivateKey := X509Cert2.PrivateKey; //MESSAGE(PrivateKey.ToString); RSASign := RSASign.RSAPKCS1SignatureFormatter(PrivateKey); RSASign.SetHashAlgorithm(X509Cert2.GetCertHashString); //***** Important part :smile: //value to be hashed gets passed in here in Arr, signed value is returned to Arr2 Arr2 := RSASign.CreateSignature(Arr); //Reflection/Generics - failed attempt // RSASignType := RSASign.GetType; // MethodInfo := RSASignType.GetMethod('CreateSignature'); // Parameters := Parameters.CreateInstance(GETDOTNETTYPE(RSASignType),0); // Parameters.SetValue(GETDOTNETTYPE(RSASign), 0); // // MethodInvoke := MethodInfo.MakeGenericMethod(Parameters); // Parameters := Parameters.CreateInstance(GETDOTNETTYPE(RSASign),1); // Parameters.SetValue(RSASign, 0); // SignedHashVal := MethodInvoke.Invoke(NullElement, parameters);
0 -
Hi Roddy,
it was just a sample of an heterogenous array (string & int). You have to use the requested type (Byte[]). So you can use one-dimensional Arr.CreateInstance(GETDOTNETTYPE(Byte), 1) orArr := Encoding.Default.GetBytes(PassOrWhatEver)
Regards
xStepa1 -
A big thanks xStepha,
I now have my digital signature. Which is good progress.
Best Regards
Roddy0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions