I have two libraries written in C # that I would like to use in an F # application. Both libraries use the same type, however I cannot convince F # the type of verification of this fact.
Here is a simple example of using interaction types with Office. F # seems especially sensitive to these types of problems. Casting on the F # side doesn't seem to help the situation. All three projects have a link to the same assembly ("Microsoft.Office.Interop.Excel", version 14.0.0.0).
In project Project1 (C # project):
namespace Project1 { public class Class1 { public static Microsoft.Office.Interop.Excel.Application GetApp() { return new Microsoft.Office.Interop.Excel.Application(); } } }
In project Project2 (C # project):
namespace Project2 { public class Class2 { Microsoft.Office.Interop.Excel.Application _app; public Class2(Microsoft.Office.Interop.Excel.Application app) { _app = app; } } }
In the project "TestApp" (project F #):
[<EntryPoint>] let main argv = let c2 = Project2.Class2(Project1.Class1.GetApp()) 0
Any clues?
Edit:
Changing the call to the Class2 constructor with the following dynamic push solves the problem:
let c2 = Project2.Class2(Project1.Class1.GetApp() :?> Microsoft.Office.Interop.Excel.Application)
However, this is unsatisfactory, since it is 1) dynamic and 2) I still do not understand why the original type check failed.
c # f # office-interop
Dan barowy
source share