2017-05-19 82 views
1

我奮力化解,從我的C#PCL這個運行時異常引用了F#PCL:TypeLoadException:從試圖與F#代碼互操作的C#代碼

未處理的異常:

System.TypeLoadException:無法與令牌0100001d (從typeref,類/組件Microsoft.FSharp.Core.FSharpResult`2, FSharp.Core,版本= 3.259.41.0文化=中性, 公鑰= b03f5f7f11d50a3a)發生

解決類型

注意: 我確保我的C#和F#項目引用相同的FSharp.Core版本。

我記得當我在F#中的測試項目不能很好地處理我的F#項目時,必須添加一個用於版本控制的XML文件。這是相同的情況嗎?

添加以下到我的應用程序配置上我Xamarin.Forms PCL:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 
    <runtime> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <dependentAssembly> 
     <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> 
     <bindingRedirect oldVersion="0.0.0.0-999.999.999.999" newVersion="4.4.0.0" /> 
     </dependentAssembly> 
    </assemblyBinding> 
    </runtime> 
</configuration> 

但我仍然收到同樣的錯誤。

回答

0

FSharpResult是(我假設)在FSharp 4.1中引入的Result<'TSuccess, 'TError>類型,因此您應該獲得FSharp.Core版本4.4.1.0。

+1

感謝您的回覆。我的所有項目都指向最新版本的FSharp.Core。不過,我仍遇到同樣的問題。 –

+0

嗯......怪異......哪個是什麼版本?在上面的問題中,你肯定會展示F#4.0,其中一個庫引用了一個尚不存在的類型,也有說'FSharp.Core,Version = 3.259.41.0'。你有沒有嘗試nugetting Fsharp.Core?這可能是由於某些PCL混合造成的。有沒有可能把這個放在GitHub上以便更好的調試? – s952163

+1

@ScottNimrod - 如果你的目標是F#4.1,那麼'app.config'中的'newVersion =「4.4.0.0''應該是'newVersion =」4.4.1.0「':參見https:// fsharp。 github.io/2015/04/18/fsharp-core-notes.html#fsharpcore-version-numbers – rmunn