2011-12-14 52 views
1

我使用MATLAB .Net Builder生成了一個.Net庫。我設法在C#中沒有任何問題的情況下使用它,但我正在嘗試使用在F#Interactive中創建的快速F#包裝器進行一些測試。無法將MWArray.dll綁定到F#Interactive

事情是,我似乎無法使用F#Interactive中的MWArray類。

我設法使用#r命令引用DLL,但在open命令後面使用intellisense時找不到MathWorks域。

而且,如果我跑我的代碼,我得到以下錯誤,當流遇到MWArray:跟着

Binding session to 'C:\Program Files\mypath\bin\Debug\MWArray.dll'...

通過

error FS0193: internal error: Could not load file or assembly 'file:///C:\Program Files\mypath\bin\Debug\MWArray.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. System.IO.FileNotFoundException: Could not load file or assembly 'MWArray, Version=2.11.0.0, Culture=neutral, PublicKeyToken=e1d84a0da19db86f' or one of its dependencies. The system cannot find the file specified. File name: 'MWArray, Version=2.11.0.0, Culture=neutral, PublicKeyToken=e1d84a0da19db86f' (...) at [email protected]() in C:\Program Files\mypath\ScriptTest.fsx:line 49

WRN: Assembly binding logging is turned OFF. To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1. Note: There is some performance penalty associated with assembly bind failure logging. To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Stopped due to error

我真的不知道在哪裏這個來自和如何解決問題。

有沒有人成功地使用F#中的MATLAB .Net庫?

你有什麼建議可以幫我解決我的問題嗎?

回答

2

我不熟悉MatLab和.NET互操作,但你檢查過架構?換句話說,確保你不是試圖將一個64位的DLL加載到一個32位的進程中,反之亦然。另外,如果您正在加載對本地程序集進行P/Invoke調用的託管程序集,則該本機DLL應該位於您當前運行FSI會話的目錄中。您可以通過System.Environment類的CurrentDirectory屬性檢查並設置此值。

0

我不知道F#-interactive,不過我已經設法使它使用MWArray.dll和我與MATLAB NE建設者編制了MATLAB的功能非常基本的F#3.0控制檯應用程序...

open makesquare 
open MathWorks.MATLAB.NET.Arrays 
[<assembly: MathWorks.MATLAB.NET.Utility.MWMCROption("-nojit")>] 
do() 

[<EntryPoint>] 
let main argv = 
    let stuff = new MLTestClass() 
    let numArray = new MWNumericArray(5) 
    let res = stuff.makesquare(1, numArray) 
    let res_val = res.GetValue(0) 
    printfn "%A" res_val 
    System.Console.ReadKey() 
    0 // return an integer exit code 

的makesquare功能,僅僅是在本教程 http://www.mathworks.se/help/dotnetbuilder/ug/create-a-net-component-from-matlab-code.html

與.NET製成對於一個類似的解決方案在C#的簡單功能4. +: use .net 2.0 dll in .net 4.5 project (vshost crashes on debug)