Tessnet2 error in C#

风格不统一 提交于 2019-12-11 04:00:08

问题


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


回答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




回答2:


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.



来源:https://stackoverflow.com/questions/11944778/tessnet2-error-in-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!