2

I am using Tessnet2 ocr in C# by following codes:

 tessnet2.Tesseract ocr = new tessnet2.Tesseract();
            ocr.SetVariable("tessedit_char_whitelist", "0123456789");
            ocr.Init(Application.StartupPath + @"D:\\Program Files (x86)\\Visual Studio 2010\\Projects\\AForgeTest2\\AForgeTest2\\tessdata\\", "eng", true);
            List<tessnet2.Word> result = ocr.DoOCR(numberTest, Rectangle.Empty);
            string code = result[0].Text;
            testBox1.Text = code;

but when I run the debug it shows the error message in the 5th line:

static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());//the line with error
        }

FileLoadException was Unhandle:
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.


Do you know how to solve this problem?

Kind Regards
Gav

psy_gav
  • 23
  • 1
  • 3

2 Answers2

8

Try adding

<configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>

to your App.config.

This enables you to reference that DLL without having to change your entire project's framework version.

Thinkable
  • 301
  • 2
  • 7
1

I think changing the target framework of your project from 4.0 to 2.0 will help.

See: Changing the Target .NET Framework Version or Profile for an Existing Project

enter image description here

George Mamaladze
  • 7,593
  • 2
  • 36
  • 52
  • I ve change the .net to 2.0 but the whole project cant run under 2.0 .NET, is there any other methods? thank you – psy_gav Aug 14 '12 at 19:37
  • Sorry @achitaka-san I make a mistake, it no longer appears the warning now, but it stop the project when I debug it "Managed (v2.0.50727) has exited with code 0 (0x0). do you know how to solve it? thank you – psy_gav Aug 14 '12 at 20:08