EldoS | Feel safer!

Software components for data protection, secure storage and transfer

TypeLoadException on .NET CF 2.0

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#29811
Posted: 06/16/2014 11:56:30
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

Good, day. Im trying to do a basic XML signature on a Windows Mobile 6.1 device (Is a CN50 Intermec device). I have already wrote a working solution for a desktop computer, so i was trying to move the code to the mobile device, however I'm getting a error on the very first lines of code, when trying to read the unsigned XML file:

using System.Collections;
using SBXMLAdESIntf;
using SBXMLSig;
using SBXMLCore;
using SBXMLSec;
using SBXMLTransform;
using SBX509;
...
...
...
public static void SigxXmlFile4(string FileName, string SignedFileName, string vCertificado, string vClave)
{
TElXAdESSigner XAdESSigner = new TElXAdESSigner();
TElXMLSigner Signer = new TElXMLSigner();
try
{
TElXMLDOMDocument XMLDocument = new TElXMLDOMDocument();
XMLDocument.LoadFromFile(FileName); //HERE IS THE PROBLEM
....
}catch{...}
}

//Im calling the function with the following line

SigxXmlFile4(@"\TemplateVacioBlackBox.xml", "\\FirmaBlackBox.xml", "\\CERTIFICATE.pfx", "11111");

When the TElXMLDOMDocument.LoadFromFile method gets called, im getting a TypeLoadException error.



Of course the empty file and the certificate are both located on the "\\" folder of the device.

The stacktrace shows the following

at System.Reflection.Module.GetTypes()
at System.Reflection.Assembly.GetTypes()
at SBChSConvCharsets.__Global.Initialize()
at SBXMLCharsets.TElXMLCodec..cctor()
at SBXMLCharsets.TElXMLUTF8Codec..ctor(Stream aStream)
at SBXMLCharsets.TElXMLUTF8Codec..ctor()
at SBXMLCore.TElXMLDOMDocument.LoadFromStream(Stream aStream, String DefaultEncoding, Boolean NormalizeNEL)
at SBXMLCore.TElXMLDOMDocument.LoadFromFile(String aFileName, String DefaultEncoding, Boolean NormalizeNEL)
at SBXMLCore.TElXMLDOMDocument.LoadFromFile(String aFileName)
at FirmaXMLDemo1.Form1.SigxXmlFile4(String FileName, String SignedFileName, String vCertificado, String vClave)
at FirmaXMLDemo1.Form1.button2_Click_1(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at FirmaXMLDemo1.Program.Main()


I added references to the assemblies: SecureBlackbox,SecureBlackbox.XML and SecureBlackbox.XmlSecurity

What I'm doing wrong?

We are interested in buying the licence to the library, but we need to see it working first. Thanks!
#29812
Posted: 06/16/2014 12:03:33
by Eugene Mayevski (EldoS Corp.)

This must have been fixed in build 11.0.252, which is on the site. Please do us a favor and check the exact build version in your installation. This can be done by checking versioninfo on SecureBlackbox assemblies *being loaded* (which can be non-trivial). Alternatively read the value of SBUtils.Unit.SBB_VERSION_NUMBER constant. It must be 11.0.252 (not 250).


Sincerely yours
Eugene Mayevski
#29815
Posted: 06/16/2014 13:19:14
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

I just downloaded the installer past friday.

Checking the properties of the assembly it says:

Version: 12.0.253.0


I could not read the value of SBUtils.Unit.SBB_VERSION_NUMBER (i was unable of finding the right call).

I'm downloading the v.11.X...
#29816
Posted: 06/16/2014 13:53:05
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

Ok, downloaded the 11.0.252.0 installer and installed it. I ran the app and encountered a different error on the very same line. This time the shows after several seconds (5 or 6 seconds when debugging the line) error is:

Invalid program exception

Stack trace:
at SBXMLCharsets.TElXMLCodec.NextBlock()
at SBXMLCharsets.TElXMLCodec.NextChar()
at SBXMLCore.TElXMLParser.NextChar()
at SBXMLCore.TElXMLParser.CheckFor(String aArg, Boolean Recall)
at SBXMLCore.TElXMLDOMDocument.ParseFromStream@0()
at SBXMLCore.TElXMLDOMDocument.ParseFromStream(Int16 Mode, Boolean aReload)
at SBXMLCore.TElXMLDOMNode.SafeParseFromStream(Int16 Mode, Boolean aReload)
at SBXMLCore.TElXMLDOMDocument.LoadFromStream(Stream aStream, String DefaultEncoding, Boolean NormalizeNEL)
at SBXMLCore.TElXMLDOMDocument.LoadFromFile(String aFileName, String DefaultEncoding, Boolean NormalizeNEL)
at SBXMLCore.TElXMLDOMDocument.LoadFromFile(String aFileName)
at FirmaXMLDemo1.Form1.SigxXmlFile4(String FileName, String SignedFileName, String vCertificado, String vClave)
at FirmaXMLDemo1.Form1.button2_Click_1(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.ButtonBase.WnProc(WM wm, Int32 wParam, Int32 lParam)
at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
at System.Windows.Forms.Application.Run(Form fm)
at FirmaXMLDemo1.Program.Main()
#29817
Posted: 06/16/2014 14:06:22
by Eugene Mayevski (EldoS Corp.)

Both problems seem to have the same root. Are you running the code on some device or on emulator? If it's a device, does it have a pre-built Windows CE (as shipped by Microsoft) or you build one from sources?


Sincerely yours
Eugene Mayevski
#29818
Posted: 06/16/2014 14:16:05
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

Im developing with an emulator (Windows phone 6 Classic), however i will try running on other emulator and the real device too.

FYI The device CN%= (http://www.intermec.com/products/cmptrcn50/index.aspx) comes shipped with (i have not installed or modified anything on the device):

windows mobile 6.1 Professional
CE OS 5.2.20774 (Build 20774.1.4.8)
#29819
Posted: 06/16/2014 14:24:24
by Eugene Mayevski (EldoS Corp.)

The problem is that we are trying on the emulator and both versions 11 and 12 work.

Regarding SBB_VERSION_NUMBER - you need to add SecureBlackbox.dll assembly to the list of references and SBUtils to uses list. The constant is just a string literal which you can assign to a string variable.

I think that maybe I know the reason ... We have different assembly sets for various flavors of .NET - be it .NET Desktop, CF, Windows Phone etc.
Desktop assemblies are installed to the GAC and sometimes they are picked by the deployment tools instead of proper mobile assemblies. This is especially likely if you don't have references to all required assemblies (SecureBlackbox.dll, SecureBlackbox.XML.dll) in your project.


Sincerely yours
Eugene Mayevski
#29820
Posted: 06/16/2014 14:34:41
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

Im attaching a screenshot of the assemblies referenced where you can see the version, also the included (using) references on the project. Maybe you can spot something that points to where the problem is.

besides, part of the project im using (you can see the assemblies being used, taken from %PROGRAM_FILES%\EldoS\SecureBlackbox.NET\Assemblies\NET_CF20\ )


<Reference Include="crypto, Version=1.7.5275.27588, Culture=neutral, processorArchitecture=MSIL">
False
<HintPath>\\10.1.2.150\c$\Users\mauricio.ahumada\Documents\Visual Studio 2008\Projects\BouncyCastleCompile\csharp\crypto\bin\Release\crypto.dll</HintPath>
</Reference>
<Reference Include="mscorlib" />
<Reference Include="SecureBlackbox, Version=11.0.252.0, Culture=neutral, PublicKeyToken=374a3a73ff9ebc6a, processorArchitecture=MSIL">
False
<HintPath>..\..\..\..\..\Archivos de programa\EldoS\SecureBlackbox.NET\Assemblies\NET_CF20\SecureBlackbox.dll</HintPath>
</Reference>
<Reference Include="SecureBlackbox.XML, Version=11.0.252.0, Culture=neutral, PublicKeyToken=374a3a73ff9ebc6a, processorArchitecture=MSIL">
False
<HintPath>..\..\..\..\..\Archivos de programa\EldoS\SecureBlackbox.NET\Assemblies\NET_CF20\SecureBlackbox.XML.dll</HintPath>
</Reference>
<Reference Include="SecureBlackbox.XMLSecurity, Version=11.0.252.0, Culture=neutral, PublicKeyToken=374a3a73ff9ebc6a, processorArchitecture=MSIL">
False
<HintPath>..\..\..\..\..\Archivos de programa\EldoS\SecureBlackbox.NET\Assemblies\NET_CF20\SecureBlackbox.XMLSecurity.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />


#29821
Posted: 06/16/2014 14:49:04
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

On the CN50 physical device i also got the exact same error.

One thing i found strange is that when i developed the initial solution as a desktop proyect the references were added using the .NET tab (on the references dialog) , however on the virtual machine where I'm developing the mobile solution the references didn't appear on that tab. Instead of that i had to look for them on the Folder C:\Archivos de programa\EldoS\SecureBlackbox.NET\Assemblies\NET_CF20

Is that normal?
#29822
Posted: 06/17/2014 01:16:20
by Eugene Mayevski (EldoS Corp.)

Desktop assemblies are installed in the GAC and registered in registry. All other assemblies are not.

We will try to reproduce the issue locally today, though I still think that the problem is related to deployment rather than the code itself.


Sincerely yours
Eugene Mayevski
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 1540 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!