2012-08-14 37 views
2

我使用Tessnet2 OCR在C#中通過以下代碼:Tessnet2錯誤使用C#

tessnet2.Tesseract ocr = new tessnet2.Tesseract(); 
      ocr.SetVariable("tessedit_char_whitelist", ""); 
      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; 

但是當我運行調試它顯示在5日線的錯誤消息:

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

FileLoadException是Unhandle:
混合模式程序集是針對運行時版本「v2.0.50727」構建的,不能在沒有附加配置信息的4.0運行時加載。


你知道如何解決這個問題嗎?

親切的問候
GAV株系

回答

1

我覺得從4.0到2.0改變項目的目標框架將幫助。

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

enter image description here

+0

我已將.net更改爲2.0,但整個項目無法在2.0 .NET下運行,還有其他方法嗎?謝謝 – 2012-08-14 19:37:00

+0

對不起@ achitaka-san我犯了一個錯誤,它現在不再出現警告,但它停止了項目,當我調試它「託管(v2.0.50727)退出代碼0(0x0)。你知道如何解決它?謝謝 – 2012-08-14 20:08:13

8

嘗試增加

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

您的App.config。

這使您可以引用該DLL而不必更改整個項目的框架版本。