tzenes
tzenes

Reputation: 1709

Trouble referencing an F# dll in a C# project

Forgive me if the answer seems obvious.

I created a Visual Studio solution and added two projects to it, one an F# Library (called MathLibrary) and the second, a C# frontend (called frontend, I'm aware of my creativity).

So I add a reference to the MathLibrary DLL in my frontend project, compiled the MathLibrary DLL (to make sure) and attempted to use it in my frontend project. At which point my compiler complained that it was an undefined reference. It was my understanding that adding the appropriate reference would allow me access to my DLL, but clearly I'm missing an important step.

Any help?

Upvotes: 1

Views: 915

Answers (3)

pblasucci
pblasucci

Reputation: 1778

There is no realtionship between a .fs file's name, and the namespaces/modules therein contained... except in the case where you completely omit any namespace or module declarations; in this case, the compile assumes a module with the same name as the file. While I am glad you were able to compile, I don't think you've hit upon the actual problem/solution.

Upvotes: 1

Tomas Petricek
Tomas Petricek

Reputation: 243126

Did the F# library build successfuly? Can you see the DLL file and does it contain any classes and namespaces if you open it using Reflector?

In any case, you'll also need to add reference to FSharp.Core.dll (which is a library containing core F# types such as lists, etc. and is referenced by any dll that the F# compiler produces). However, I suppose the error message you'd get if you just needed to add this reference would be different.

Upvotes: 0

Brian
Brian

Reputation: 118925

Does it perhaps show up as Module1.SomeClass. The default file in an F# library project is called Module1, and if you don't start the source code file with either a namespace or module declaration, you generate code in a module with the same name as the filename.

You might try adding namespace FsLib to the top of your F# library code that defines some class, and then see if FsLib.SomeClass works in C#.

Upvotes: 0

Related Questions