Error in "NDigitSign Full Test and Example"

5/6/2013 5:35:12 PM
Gravatar
Total Posts 7

Error in "NDigitSign Full Test and Example"

Hi

I just downloaded the latest NCryptoki v.1.5.4.2 full package. Running the included example FullTestNDigitSign returns an error when trying to sign a text (or a PDF):

###################################

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Users\stepcom\Documents\Visual Studio 2010\Projects\NDigitSign1.3.1.3\NDigitSign\bin\NCryptokiMngd.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format.
File name: 'file:///C:\Users\stepcom\Documents\Visual Studio 2010\Projects\NDigitSign1.3.1.3\NDigitSign\bin\NCryptokiMngd.dll'
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Cryptware.NCryptoki.Cryptoki.Attach(String cryptokilib)
at Cryptware.NCryptoki.Cryptoki..ctor(String cryptokilib)
at Cryptware.NDigitSign.DigitalSigner.Init(String cryptokiPath)
at FullTestNDigitSign.Form1.signTextButton_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

 

************** Loaded Assemblies **************
mscorlib
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4234 (VistaSP2GDR.050727-4200)
CodeBase: file:///C:/Windows/Microsoft.NET/Framework64/v2.0.50727/mscorlib.dll
----------------------------------------
FullTestNDigitSign
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/stepcom/Documents/Visual%20Studio%202010/Projects/NDigitSign1.3.1.3/NDigitSign/bin/FullTestNDigitSign.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4236 (VistaSP2GDR.050727-4200)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Windows.Forms/2.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4235 (VistaSP2GDR.050727-4200)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System/2.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
System.Drawing
Assembly Version: 2.0.0.0
Win32 Version: 2.0.50727.4235 (VistaSP2GDR.050727-4200)
CodeBase: file:///C:/Windows/assembly/GAC_MSIL/System.Drawing/2.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
NDigitSign
Assembly Version: 1.3.1.1
Win32 Version: 1.3.1.1
CodeBase: file:///C:/Users/stepcom/Documents/Visual%20Studio%202010/Projects/NDigitSign1.3.1.3/NDigitSign/bin/NDigitSign.DLL
----------------------------------------
NCryptoki
Assembly Version: 1.5.4.1
Win32 Version: 1.5.4.1
CodeBase: file:///C:/Users/stepcom/Documents/Visual%20Studio%202010/Projects/NDigitSign1.3.1.3/NDigitSign/bin/NCryptoki.DLL
----------------------------------------

************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.

###################################

 

When running in VS debugger I get an error at line

DigitalSigner dsign = new DigitalSigner(p11dll);

----------

Could not load file or assembly 'NCryptoki, Version=1.5.3.2, Culture=neutral, PublicKeyToken=6a3e54934ab72177' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

----------

 

Do you have any hint what I can do to get the example running?

Thanks.

 

 

 

5/7/2013 7:13:52 PM
Gravatar
Total Posts 300
Ugo Chirico http://www.ugochirico.com

Re: Error in "NDigitSign Full Test and Example"

Hi,

the problem appears because you are running FullTestDigitSign in a 64 bit OS using the 32bit version of NCryptoki.

See in the lib folder. You can find the 64bit version of NCryptoki dlls.

5/7/2013 10:08:48 PM
Gravatar
Total Posts 7

Re: Error in "NDigitSign Full Test and Example"

Yes, I'm on a 64bit 2008 server. I need a x86 application, so I compiled the sample for x86, referenced all 32bit dlls from the lib directory (which is also default in your sample) and called also a 32bit cryptoki.dll.

I'm still getting an error at line

DigitalSigner dsign = new DigitalSigner(p11dll);
----------
Could not load file or assembly 'NCryptoki, Version=1.5.3.2, Culture=neutral, PublicKeyToken=6a3e54934ab72177' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
----------

I do not understand why the program is trying to load v1.5.3.2 while v1.5.4.1 is referenced. But anyhow, adding an assembly binding in app.config resolved the conflict:

  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
   <dependentAssembly>
    <assemblyIdentity name="NCryptoki" publicKeyToken="6A3E54934AB72177" culture="neutral"/>
    <bindingRedirect oldVersion="0.0.0.0-1.5.4.1" newVersion="1.5.4.1"/>
   </dependentAssembly>
  </assemblyBinding>