简体   繁体   English

在C#项目中引用F#dll遇到问题

[英]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). 我创建了一个Visual Studio解决方案,并向其中添加了两个项目,一个项目是F#库(称为MathLibrary ),第二个项目是C#前端(称为frontend ,我知道自己的创造力)。

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. 因此,我在前端项目中添加了对MathLibrary DLL的引用,编译了MathLibrary DLL(以确保)并尝试在frontend项目中使用它。 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. 我的理解是,添加适当的引用将使我可以访问自己的DLL,但显然我缺少重要的一步。

Any help? 有什么帮助吗?

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; .fs文件的名称与其中包含的名称空间/模块之间没有关系...除非完全省略任何名称空间或模块声明; 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. 我很高兴您能够编译,但我认为您没有遇到实际的问题/解决方案。

Does it perhaps show up as Module1.SomeClass . 它是否可能显示为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. F#库项目中的默认文件称为Module1 ,并且如果您不使用namespacemodule声明来启动源代码文件,则会在与文件名同名的模块中生成代码。

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#. 您可以尝试将namespace FsLib到定义某些类的F#库代码的顶部,然后查看FsLib.SomeClass是否在C#中工作。

Did the F# library build successfuly? F#库是否成功构建? Can you see the DLL file and does it contain any classes and namespaces if you open it using Reflector? 如果使用Reflector打开该DLL文件,您是否可以看到它,并且它包含任何类和名称空间吗?

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). 无论如何,您还需要添加对FSharp.Core.dll引用(这是一个包含核心F#类型(例如列表等)的库,并且由F#编译器生成的任何dll进行引用)。 However, I suppose the error message you'd get if you just needed to add this reference would be different. 但是,我想如果您只是需要添加此引用,您将收到的错误消息将有所不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM