I have two libraries written in C# that I'd like to use in an F# application. Both libraries use the same type, however, I am unable to convince F#'s type checker of this fact.
Here's a simple example using the Office interop types. F# seems particularly sensitive to these type issues. Casting on the F# side does not seem to help the situation. All three projects have a reference to the same assembly ("Microsoft.Office.Interop.Excel" version 14.0.0.0).
In project "Project1" (a 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" (a C# project):
namespace Project2
{
public class Class2
{
Microsoft.Office.Interop.Excel.Application _app;
public Class2(Microsoft.Office.Interop.Excel.Application app)
{
_app = app;
}
}
}
In project "TestApp" (an F# project):
[<EntryPoint>]
let main argv =
let c2 = Project2.Class2(Project1.Class1.GetApp())
0
Any hints?
Edit:
Changing the call to Class2
's constructor with the following dynamic cast solves the problem:
let c2 = Project2.Class2(Project1.Class1.GetApp() :?> Microsoft.Office.Interop.Excel.Application)
However, this is unsatisfying, since it is 1) dynamic, and 2) I still don't understand why the original type check failed.