How to reference another project from an F# project? - f#

I have two F# projects in a solution. I added a reference of project1 to project2. When I try to use modules from project1 I get
Error The type referenced through 'xxx' is defined in an assembly
that is not referenced. You must add a reference to assembly 'yyy'.
Error tells that reference of a dll which is used by project1 should be added to project2. With C# it works only by adding a reference to the other project. Is there something extra we should do in order to avoid adding those dlls to every project we use references?

Related

VS2019 Reference a foreign project and its packaged assemblies in .Net 5.0

To recap how .net framework references work: Assume I have a .net framework class project called ProjectFw which references a .dll called Grpc.dll. When I create a new Solution as a .net framework console project called ProjectFwRef which adds a reference to ProjectFw.dll the build automatically brings the .dll Grpc.dll into the release folder of ProjectFwRef.
But .net 5.0 does not do that: Assume I have a .net 5.0 class project called ProjectNet which references a package called Grpc. When I create a new Solution as a .net 5.0 console project called ProjectNetRef which adds a reference to ProjectNet.dll the build DOES NOT automatically bring the Grpc.dll nor Grpc package into the release folder of ProjectNetRef.
This fundamental difference in how foreign .dlls are imported into a .net 5.0 project begs the question of the best way to deal with it. One obvious answer is to manually add the package Grpc to ProjectNetRef. Am I missing a better solution? What if I do not know the .dll's a foreign project references? Do I have to wait for the dreaded 'Cannot load file or assembly' error to find out what package I should have added?

Same class name in library and project

If I have a class named ClassA in my main project, and I have a sub project built for a static library, in this sub project a class also named ClassA. I'm wonder that I can build and run successfully, how the compiler distinguish the two class?
I think you are talking about how linker works.
The static library is a collection of several relocatable object files with the suffix ".o". The source files in your project are also compiled into a relocatable object files.
When linker works, it will resolve the symbols like ClassA that used in your code. If it finds that in a relocatable object file - let's say rof1.o, it would absorb rof1.o into the executable file. The searching order of relocatable object file when linker try to resolve symbols determines which ClassA is used. As the searching order is non-deterministic to us, you should use a different class name.
BTW if you set the other link flags to '-all_load', which indicates that the linker will try to combine all the relocatable object files into the executable file. Then if there are two or more same symbols, it will show an error "duplicated symbols".
You need to rename one of your classes otherwise compiler throws an error when building your code.

how to add third party dll reference to F# project?

I'm adding a third party dll reference to my F# project. I added the dll in references and when I use this i.e highlight the code and do Alt+Ent, I get the error "The namespace or module 'AZROLESLib' not defined." Am I missing some thing.
In short, you have to use #r "/path/to/AZROLESLib.dll" in order that F# Interactive recognizes and loads the dll file.
Adding a dll reference helps Visual Studio to find correct libraries when compiling the project, but it has nothing to do with F# Interactive. Therefore, you have to use #r directive to point to AZROLESLib.dll. If VS has some troubles to highlight the code,
you may have to open the exact module in your dll file:
open AZROLESLibModule
If the code is in a *.fs file, you may want to distinguish between using fsi and using fsc:
#if INTERACTIVE
#r "/path/to/AZROLESLib.dll"
#endif
for some things you can call them directly by name with no path
#r "EnvDte"
works for vs2013 here for instance
In my case my F# project was referencing a C# DLL but I had the same issue, "The namespace or module 'MyModule' not defined", when doing "open MyModule".
The solution was to edit the settings to use the same framework (one was using 4.5 and the other 4.0).

How to generate a separated dll file for the code of a specific namespace

I have an asp.net mvc application, when I compile, it creates one dll file
However, I have some code that I would like to re-use in other projects
I guess I could create another project, then put this specific code inside it and it would generate a separated dll file.
But is there another way to process in order to put the code of a specific namespace of my current project inside a separated dll file?
Thanks
Put that code in a separate project--make that project a "Class Library". This will create a DLL for that project, and you only need to add it as a reference on the original project and any other project that needs to share that code.

Delphi Error E1026 File not found: "myprojectname.tlb"

I have a project let's call it Yellow.dproj, which I saved as Blue.dproj, to make some changes. There must be some COM/DCOM related code in this project, but I can't figure out where.
The error I am getting when I try to build Yellow.dproj is that it can not find a type library (TLB) file: "E1026 File not found: ". The file it can't find is MyAppName.tlb. There is a MyAppName_tlb.pas file, which I have tried adding and removing from the project, either way I get this error.
I think I probably have to go into that TLB file, which I don't really understand, and rename a bunch of junk in there, because it is dependant on the name of my application. This is something that happens to you, I suspect, when you use COM/DCOM and type libraries in Delphi (Delphi 2010). You can't just rename or save-as and build a new project again.
What do I do to fix this unit up?
Do you have {$ *.TLB} in your project source?
The * is the project name, so the TLB file has to match the name of the project - perhaps the name of the tbl was not changed along with the project.

Resources