Fix: Leadtools.Forms.Ocr.OcrException. Image file create error.

If the Leadtools OCR engine is not started with the correct parameters, the exception "Image file create error" will be thrown. To fix this problem, make sure you start the OCR engine by executing the function Startup with parameter startupParameters set to the installation folder of Leadtools, like:

 

IOcrEngine ocrEngine = OcrEngineManager.CreateEngine(OcrEngineType.Plus, useThunkServer: false);
ocrEngine.Startup(null, null, "C:\Program Files (x86)\LeadTools\OCR Engine");

Fix: Exception "Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information.", when code is executed in a Microsoft Visual Studio 2012 test project.

When using an old version of LeadTools I encountered an exception during the execution of a Microsoft Visual Studio 2012 test. Mixed mode assembly is built against version ‘v2.0.50727’ of the runtime and cannot be loaded in the 4.0 runtime without additional configuration information. This error was fixed following the steps on http://blog.kristandyson.com/2012/05/encountering-systemiofileloadexception.html.

 

  1. Close Microsoft Visual Studio 2012 (and IIS express)
  2. On Windows 8, start Notepad.exe as an administrator
  3. Open the file [C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.executionengine.x86.exe.config]
  4. Add and save:

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <legacyUnhandledExceptionPolicy enabled="1"/>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="Extensions" />     
    </assemblyBinding>
  </runtime>
  <system.diagnostics>
    <switches>
      <add name="TpTraceLevel" value="0" />
    </switches>
  </system.diagnostics>
  <appSettings>
    <!–<add key="ExecutionThreadApartmentState" value ="MTA"/>–>
    <!–<add key="TraceLogMaxFileSizeInKb" value ="10240"/>–> 

    <!– MsTest Adapter Specific AppSettings –>
    <add key="TestProjectRetargetTo35Allowed" value="true" />
   </appSettings>
   <startup useLegacyV2RuntimeActivationPolicy="true">
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
   </startup>

</configuration>

How to copy data from Microsoft SQL Server 2012 localdb to Windows Azure.

I used the Export data wizard found in Microsoft SQL Server Management Studio, to copy data from a Microsoft SQL Server 2012 localdb database to Windows Azure.

  • Connect Microsoft SQL Server Management Studio to your localdb databse.
  • Right click database > Tasks > Export Data…
  • In the source dialog, choose
    • [.Net Framework Data Provider for SqlServer]
    • [Integrated Security = True]
    • [Data Source = (localdb)\V11.0]
    • [Initial Catalog = Your_Database]
    • [User Instance = True]
  • In the destination dialog, choose:
    • [.Net Framework Data Provider for SqlServer]
    • [Integrated Security = False]
    • [Data Source = yourdatabaseserver.database.windows.net]
    • [Initial Catalog = Your_Database]
    • [Password = YourPassword]
    • [User ID = YourUserId]
    • [User Instance = False]

 

 

Screendumps

 

image

image

image

 

image

image

image

 

NOTE

For an initial start of a project on Windows Azure I used the [Deploy Database to SQL Azure…] wizard:

 

image

How to enable JSON dynamic HttpCompression (gzip) on IIS in Windows 8.

First check if Dynamic compression is enabled:

 

image

 

administration.config

Open C:\Windows\System32\inetsrv\config\administration.config with notepad and change the httpCompression tag:

 

image

 

For IIS 7, also change the urlCompression tag:

image

 

ISA Server

If the dynamic compression is still not working, verify there is no ISA server between the server and the client, if so follow the steps on http://forums.iis.net/t/1168067.aspx

To check if the ISA server is the problem just open a browser on the server en connect to the localhost url, check with fiddler if the dynamic compression works.

Creating a Mac OS X development image

1. Download and install the latest version of VMWare Workstation 9 for Windows.

2. Unlock VMWare Workstation so it is able to run a MAC OS X image, follow the steps on http://www.souldevteam.net

2. Download the latest version of Mac OS X from the Apple store.

3. Convert the InstallESD.dmg found on the Mac OS X DVD "SharedSupport\InstallESD.dmg" to an *.iso  by using Magic ISO (http://www.magiciso.com/FAQ/FAQ0011.htm)

4. Create VMWare virtual machine based on the created ISO.

Before boot make sure you’ve checked the "Virtualize Intel VT-x/EPT or AMD-V/RVI" option under Hardware > Processors

5. Download and install the VMWare Tools for Mac OS X from http://www.souldevteam.net in the virtual machine.

6. Enable file sharing with the host.

7. Download an install XCode from the Apple store inside the virtual machine.

 

Creating the virtual machine

image

image

image

image

image

image

image

image

image

image

image

image

image

image

image

image

 

Installing Mac OS X in the VMWare Virtual Machine

image

image

image

image

image

image

image

image

image

image

image

image

image

image

image

image

image

image

 

Reboot the machine and install vmware tools (darwin.iso), this will install the correct video driver and will allow you to automatically fit the guest to the correct resolution, depending on the size of the VMWare workstation window.

See image below:

image

 

 

 

Enable file shareing (System Preferences > Sharing)

image

image

 

And this is a dev image so:

image

 

Now you can access files from you MAC OS X virtual machine on the windows host:

image

 

Transferring 1,5 gb xcode from host to client (usb 3.0)

image

Installing XCode

image

image

image

image

image

 

Enable developer modus

image

 

Change to keyboard layout

image

Change caps lock to apple key

image

 

 

PhoneGap

If you want to use PhoneGap, follow the steps on http://docs.phonegap.com/en/2.2.0/guide_getting-started_ios_index.md.html#Getting%20Started%20with%20iOS:

 

First install XCode commandline tools:

image

image

 

~/Documents/Programs:

image

 

Creating PhoneGap project for XCode:

image

 

Enable remote debugging

Add [NSClassFromString(@"WebView") performSelector:@selector(_enableRemoteInspector)]; to the function didFinishLaunchingWithOptions.

image

Run the app in the simulator.

Open Safari on the Mac > Develop > iPad Simulator > Index.html

image

Now you can remotely inspect your HTML, CSS and Javascript on an iOS 6 simulator.

image

 

Last but not least, make a backup of this dev image and store it on a separate external drive.

Convert a date object to a string in JavaScript

If you want to convert a date object to a string in JavaScript and you use jQuery, then you can use the function $.datepicker.formatDate.

 

The following QUnit test will succeed:

/// <reference path="Scripts/qunit.js"/>
/// <reference path="Scripts/jquery-1.8.3.js"/>
/// <reference path="Scripts/jquery-ui-1.9.2.js"/>
"use strict";

test('JsTest', function ()
{
    
    var input = new Date(2012, 10, 28); // Note: months start at zero!
    var expected = '2012-11-28';
    var actual = $.datepicker.formatDate('yy-mm-dd', input);
    ok(expected == actual,
        'Dates are not equal. Expected:' +
        expected + ' _ Actual:' + actual);
});

Convert string to date in JavaScript

If you want to convert a string to a date object in JavaScript and you use jQuery, then you can use the function $.datepicker.parseDate.

 

The following QUnit test will succeed:

/// <reference path="Scripts/qunit.js"/>
/// <reference path="Scripts/jquery-1.8.3.js"/>
/// <reference path="Scripts/jquery-ui-1.9.2.js"/>
"use strict";

test('JsTest', function ()
{
    var text = '2012-11-28';
    var expected = new Date(2012, 10, 28); // Note: months start at zero!
    var actual = $.datepicker.parseDate('yy-mm-dd', text);
    ok(expected.getTime() == actual.getTime(),
        'Dates are not equal. Expected:' +
        expected.toISOString() + ' _ Actual:' + actual.toISOString());
});

Running javascript and typescript unit tests in Microsoft Visual Studio 2012 with Chutzpah

To unit test my JavaScript files in Microsoft Visual Studio 2012, side by side mine C# unit tests, I use Chutzpah.

Chutzpah comes with 2 Microsoft Visual Studio 2012 extensions:

1. Chutzpah Test Adapter for Visual Studio 2012, allows you to run QUnit / Jasmine javascript test files side by side C# unit tests in the test explorer or continuous build process.

2. Chutzpah – A JavaScript Test Runner, allows you to run individual QUnit / Jasmine JavaScript test files in Microsoft Visual Studio 2010 and 2012 by right clicking a test file and choosing "".

 

In Microsoft Visual Studio 2012

– Tools > Extensions and Updates…

– Install both plugins and restart Microsoft Visual Studio 2012

 

image

 

Create a new UnitTest project:

 

image

 

Enable "Run Tests after build"

(The "Play" button found at the top of the Test Explorer")

Now when you press CTRL + SHIFT + B the project will be build and all tests will execute.

 

image 

 

TIP: Never use CTRL + S to save your file, just use CTRL + SHIFT + B.

Now you can see the C# unit test "TestMethod1" succeeded.

 

QUnit for ASP.NET MVC

Right click unit test project and click Manage NuGet Packages…

Click install.

 

image

 

Add Code.js and Test.js

The Code.js file will contain the JavaScript code we want to test.

The Test.js  file will contain the JavaScript test code written, by using the QUnit test framework.

 

Code.js

image

 

Test.js

Reference qunit and the Code.js file to get code completion in your test code.

 

image

 

Code completion in JavaScript in Microsoft Visual Studio 2012 unit test file

 

image

 

 

Run C# and JavaScript unit tests side by side in the Test Explorer

By pressing CTRL + SHIFT + B

image

 

Run only JavaScript unit test file

If you only want to run the QUnit test, right click on the JavaScript Test.js file and choose "Run JS Tests".

 

image

 

If you want to run JavaScript unit tests by pressing a keyboard shortcut, you need to install

image

 

Then you can bind a shortcut to the ProjectAndSolutionsContextMenus.Project.RunJSTests command to run JS tests.

(http://matthewmanela.com/blog/chutzpah-1-1-0-released/)

 

image

Simple way for converting "Rijksdriehoek" coordinates to lat and long (WGS84) in C#

In the Netherlands "Rijksdriehoek" coordinates are used to show the exact position of an object on a chart. To convert "Rijksdriehoek" coordinates to lat and long coordinates in C# use the following class:

 

Note

This code is base on the information found in  http://www.dekoepel.nl/pdf/Transformatieformules.pdf

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Research.Core
{
public interface IRijksdriehoekComponent
{
string ConvertToLatLong(double x, double y);
}

public class RijksdriehoekComponent : IRijksdriehoekComponent
{
public string ConvertToLatLong(double x, double y)
{
    string result = null;

    // The city "Amsterfoort" is used as reference "Rijksdriehoek" coordinate.
    int referenceRdX = 155000;
    int referenceRdY = 463000;

    double dX = (double)(x - referenceRdX) * (double)(Math.Pow(10,-5));
    double dY = (double)(y - referenceRdY) * (double)(Math.Pow(10,-5));

    double sumN = 
        (3235.65389 * dY) + 
        (-32.58297 * Math.Pow(dX, 2)) + 
        (-0.2475 * Math.Pow(dY, 2)) + 
        (-0.84978 * Math.Pow(dX, 2) * dY) + 
        (-0.0655 * Math.Pow(dY, 3)) + 
        (-0.01709 * Math.Pow(dX, 2) * Math.Pow(dY, 2)) + 
        (-0.00738 * dX) + 
        (0.0053 * Math.Pow(dX, 4)) + 
        (-0.00039 * Math.Pow(dX, 2) * Math.Pow(dY, 3)) + 
        (0.00033 * Math.Pow(dX, 4) * dY) + 
        (-0.00012 * dX * dY);
    double sumE = 
        (5260.52916 * dX) + 
        (105.94684 * dX * dY) + 
        (2.45656 * dX * Math.Pow(dY, 2)) + 
        (-0.81885 * Math.Pow(dX, 3)) + 
        (0.05594 * dX * Math.Pow(dY, 3)) + 
        (-0.05607 * Math.Pow(dX, 3) * dY) + 
        (0.01199 * dY) + 
        (-0.00256 * Math.Pow(dX, 3) * Math.Pow(dY, 2)) + 
        (0.00128 * dX * Math.Pow(dY, 4)) + 
        (0.00022 * Math.Pow(dY, 2)) + 
        (-0.00022 * Math.Pow(dX, 2)) + 
        (0.00026 * Math.Pow(dX, 5));


    // The city "Amsterfoort" is used as reference "WGS84" coordinate.
    double referenceWgs84X = 52.15517;
    double referenceWgs84Y = 5.387206;

    double latitude = referenceWgs84X + (sumN / 3600);
    double longitude = referenceWgs84Y + (sumE / 3600);

    // Input
    // x = 122202
    // y = 487250
    //
    // Result
    // "52.372143838117, 4.90559760435224"
    result = string.Format("{0}, {1}", 
        latitude.ToString(CultureInfo.InvariantCulture.NumberFormat),
        longitude.ToString(CultureInfo.InvariantCulture.NumberFormat));

    return result;
}
}
}

Test

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Research.Core;

namespace UnitTest
{
[TestClass]
public class RijksdriehoekComponentTests
{
    [TestMethod]
    public void TestMethod1()
    {
        IRijksdriehoekComponent component = new RijksdriehoekComponent();
        double x = 122202;
        double y = 487250;
        string result = component.ConvertToLatLong(x, y);
        Assert.AreEqual("52.372143838117, 4.90559760435224", result);
    }
}
}

How to start a process / application on an other computer from C#, by using PowerShell remoting

 

You van execute a process on an other machine from C#, by using the code below:

 

Example for calling the function

var rc = new RemotingComponent(null);
rc.RunRemoteProcess
(
    @"MyMachine1", 
    "MyMachine1\Administrator", 
    "MyPassword1", 
    @"C:\Windows\System32\notepad.exe",
    string.Empty
 );

C# class

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Security;
using System.Text;

namespace Research
{
    public interface IRemotingComponent
    {
        void RunRemoteProcess(string machineName, string userName, string password, string processPath, string processArguments);
    }

    public class RemotingComponent : IRemotingComponent
    {
        public void RunRemoteProcess(string machineName, string userName, string password, string processPath, string processArguments)
        {
            var connectTo = new Uri(String.Format("http://{0}:5985/wsman", machineName));

            _logger.Info("Building powershell command.");
            var command = new StringBuilder();
            command.AppendLine("$pinfo = New-Object System.Diagnostics.ProcessStartInfo");
            command.AppendLine(string.Format(@"$pinfo.FileName = ""{0}""", processPath));
            command.AppendLine("$pinfo.UseShellExecute = $false");
            command.AppendLine("$pinfo.RedirectStandardError = $true");
            command.AppendLine("$pinfo.RedirectStandardOutput = $true");
            command.AppendLine("$pinfo.CreateNoWindow = $true");
            command.AppendLine(string.Format(@"$pinfo.WorkingDirectory = ""{0}""", new FileInfo(processPath).Directory.FullName));
            command.AppendLine(string.Format(@"$pinfo.Arguments = ""{0}""", processArguments));
            command.AppendLine("$p = New-Object System.Diagnostics.Process");
            command.AppendLine("$p.StartInfo = $pinfo");
            command.AppendLine("$p.Start() | Out-Null");
            command.AppendLine("$output = $p.StandardOutput.ReadToEnd()");
            command.AppendLine("$p.WaitForExit()");
            command.AppendLine("$output");
            
            string shell = @"http://schemas.microsoft.com/powershell/Microsoft.PowerShell";
            using (var passing = new SecureString())
            {
                foreach (char c in password.ToCharArray())
                {
                    passing.AppendChar(c);
                }
                passing.MakeReadOnly();
                var credentials = new PSCredential(userName, passing);

                var connection = new WSManConnectionInfo(connectTo, shell, credentials);
                using (var runspace = RunspaceFactory.CreateRunspace(connection))
                {
                    runspace.Open();

                    using (var powershell = PowerShell.Create())
                    {
                        powershell.Runspace = runspace;
                        powershell.AddScript(command.ToString());

                        var results = powershell.Invoke();
                        runspace.Close();

                        foreach (var obj in results.Where(o => o != null))
                        {
                            Console.Writeline(string.Format("Output: [{0}].", obj));
                        }
                    }
                }
            }
        }
    }
}