Using an F# library in a C# project in Xamarin - c#

I have a solution in Xamarin Studio with a C# console program trying to call an F# library.
The reference is fine, everything builds.
My F# code looks like the following:
namespace MyStore.Library
module public Lookup =
open System
let lookup name (age:int) =
String.Format("{0}, {1}", name, age.ToString() );
I can call the F# library from an F# console and a C# library from the C# console, but I can't mix the two.
The C# console doesn't see any F# namespaces at all.
What am I doing wrong?
What should I do to see the F# namespace from C#?

In the C# project, you need to add a reference to your F# project.
In the Solution pane, expand your project, and click the gear icon -> Edit References
Then go to Projects tab, check the F# project you want to reference to, then click OK.
Also, make sure both C# and F# project target to the same .NET framework! To check that, right click a project, Options -> Build -> General

Related

Importing C# dll to C++ managed code (.NET)

I'm using Visual Studio 2010. I've written a dll in C#, managed dll then.
Now for some reason, I need to write a software in C++ (.NET then also managed).
I need to import the C# dll into my C++ .NET code.
I can't figure out to do this, I've made several search but this problem seems to not be covered. For example, in C# I don't have include file, then how my C++ (.NET) projet knows about classes and functions inside the dll?
Thanks,
In Visual Studio, bring up the properties of the C++/CLI project, go to "Common Properties/Framework and References" in the tree at the left, and click the "Add New Reference" button. This will bring up the standard "Add Reference" dialog you can get from a C# project, just select your C# DLL or reference a C# project in the same solution.
You need to add a reference into your project. In Visual Studio, right-click your project, then select "References".
You add reference to you assembly, Set ComVisible attribute to your assembly
Edit your AssemblyInfo.cs
[assembly: ComVisible(true)]
.Net Framework have MSIL langage in order to manage interoperability betwwen different langages
Link : http://support.microsoft.com/kb/828736
You just need to add only reference of that dll in your project, as George has replied.
then use that namespace or name of classes in your code...
It is possible. Google search would gave you answers. Few links from Stackoverflow
How to use c# Dll in vc++?
using c# dll in project c++
and you get many more links https://www.google.co.in/#sclient=psy-ab&hl=en&site=&source=hp&q=using+c%23+dll+in+vc%2B%2B&oq=using+C%23+dll+&gs_l=hp.3.2.0l4.1601.6409.0.9065.18.13.2.3.3.2.468.2716.0j9j1j2j1.13.0...0.0...1c.1.ixoWIPWicqo&pbx=1&bav=on.2,or.r_gc.r_pw.&fp=64f4e49ac7d1c408&biw=936&bih=595
Hope this helps

A project with an output type of class library cannot be started directly (2)

A project with an output type of class library cannot be started
directly. In order to debug this project, add an executable project to
this solution which references the library project. Set the executable
project as the startup project.
While running the program in C# visual studio 2010 I am getting this error. Please tell me how to sort out this error?
Set your startproject in the project explorer by clicking right mouseclick on an executable project and choose "Set as start project"
You created the project as a class library project, not an executable program. Class libraries are compiled and then used by other applications for common functionality.
If you meant to create a class library, you need to create a test application (or, better yet, Unit Tests) to test the functionality. If you meant to create an executable application, you'll need to modify the project.
If you have multiple projects in a single solution, you might also need to make sure you have the correct project set as the "Start Project" rather than one of the class library projects.
what you have done is that you have made a class library with all your code
every project in .Net needs a starting point like Main() function in c# which obsly isnt present in a class libraty type of project
what you can do instead is
1. Make a console project inside the same solution. by right clicking the solution and add new project
2. Add a reference to the class library
3. Access the classes/methods of the class library and then starting the console project instead of class library project
Alternatively,
If you have a console project OR any other project in the solution already
right click the project in the solution explorer and Set as Startup project
Right click on Solution-->Go to properties-->Expand Common properties tab-->(On right side) Select Radio button with option Single startup project-->choose project from drop down list.
Enjoy.
If you want to debug code in the DLL or run it using tests, go to the properties of the project, go to the Debug tab, select "Start external program" and enter the name of the application to use, such as a test runner.
Go to your project properties page, change Output Type to Console Application or Windows Application (depending on what it is).
Make sure that you've got correct project set as startup one (right click -> set as startup project), and that this one is not of type Class Library. If your only project in solution is class library, then you need to create some test executable for it.
The same error type i have found in my one of project suddenly which is running in VS 2012 with MVC 4 only. I have run multiple ways to resolve this error, but i have found filly with small change option in Property window of your respective error giving project.
I have went project property window there i have change startup Project from Healpars to Myproject.Then it is working fine.
Thank you
I was surprised to learn that you can indeed set some Class Libraries as Startup and run them, IF they contain user controls. They run in the UserControl TestContainer which allows one to modify properties, etc. Basically debug at DesignTime, which can be really helpful. I have about 20 user controls in a single Project. This way I can run the TestContainer and choose which user control to run and debug.
If it is a function app project that you want to execute then you need to have Azure development tool installed in your visual studio. Please see the below image for more info.
enter image description here
You need to mark the API in the set as startup project
Right key on the API
select .net core project, then it will start directly with no doubt. Thanks

How to Create a DLL file in Visual Studio C# 2010 Express edition?

I have already come across the Stack Overflow question "Is there a way to generate a DLL file from Visual Studio Express without explicitly creating a DLL project?", but it does not directly answer my query, so I'm raising it here.
The problem I am facing while trying to make the DLL is that I can't find any option under Build named build class file.
I have changed the project property to class file (shown below)
This is how it is:
And here is how my build option is getting displayed:
Also when I am using the command-line option the dll file is getting generated but it is not getting the properties I'm setting in the application.
I am new with Visual Studio so a litte bit confused about this part.
The "Build Solution" option in your second screenshot is the thing you need to click to produce your dll, alternatively you can right click on your project in the Solution Explorer and click "Build":
(If you only have one project in your solution then these two will both do exactly the same thing)
The output dll will normally be placed in the bin\Debug or bin\Release directory depending on whether you are in Release or Debug configuration, check the "Build" tab of the project properties for the exact path.
The reason why you aren't seeing a "Build class file" option is because this is what the "Build project" menu item does - it will produce a class library if the project output type is "Class Library", a windows executable if the project output type is "Windows Application" etc...
You're not trying to build a class file - you're trying to build a class library.
And you just build the solution - that will build each of the projects in your solution, including your LicenseCheckLibrary project is just a class library project.
It looks like you're basically there - look in the bin\Debug or bin\Release folders under LicenseCheckLibrary, and you'll find the DLL.
Why would you want to avoid building a DLL file in the first place? Are you developing an EXE file in order to test the logic and then conver it to DLL once it is working fine? If yes, why not create two projects: Windows Console and Class Library. Inside Class Library implement the licensing logic and use Windows COnsole to test the logic. When you say you are new with Visual Studio, what exactly do you mean? You never used it before or you are new to .NET Framework programming? .NET Framework has certain classes for developing licenses. Also, there were quetions here on stackoverflow regarding the licensing. Find some of them instead of reinventing the wheel.
Have a look at this article http://www.developer.com/net/net/article.php/3074001
Create a new class library project
Create classes and code
compile Project
Dll Created
Create a new project
Click on Add Reference
Navigate to the class library folder
Go into the debug folder or whatever and include
Remember you will prob have to include the namespace. in the new
project.

Problem creating COM assembly in C# 2005

I am kind of new to C#. I built a class library in order to create a DLL which I need to reference from a VB.Net application.
I followed all the steps detailed in this this article in order to generate the COM assembly based on my C# class library.
All the process ran smoothly (create the key, run gacutil.exe to add the assembly to the cache), but I still can't see the DLL from my main project in order to add it as a reference.
What am I doing wrong? Any help will be appreciated
There's some pretty bad advice in that article, the GAC is a deployment detail and has no relevance to the task of writing and using an assembly on your dev machine. The entire process also has nothing to do with COM at all.
Get ahead by opening your VB.NET solution in Visual Studio. Right-click the solution in the Solution Explorer window, Add, New Project. Pick "Class Library" from the C# node. Now right-click your VB.NET project, Add Reference, Project tab and select your C# project. Any of the public C# classes you write are now available in your VB.NET code.
You might not see the solution if it contains only one VB.NET project. Fix with Tools + Options, Project and Solutions, General, tick "Always show solution".

Visual Studio equivalent of the Delphi "search path"

I've made a C# class defined in a .cs file, which I'm using in an existing project.
Let's call it the Magic class, defined in Magic.cs.
Now I'm working on a new project, and I'd like to instantiate an instance of that class in my new project.
How can I reference that class in my new project without actually copying the file into the new project's directory?
In Delphi, the answer would be "add the location of the class definition to your search path". This is an embarassingly stupid question, but I can't find a good answer anywhere.
Here is what I've tried:
1 - Project->Properties->Reference Paths->Add the location of my class (references to the class are still unresolved)
2 - Right click on project -> "Add existing item" -> choose the class (creates a new separate copy in my project folder)
3 - Right click on project -> "Add reference" -> see that it is expecting a compiled target like a DLL.
See also
How do you share code between projects/solutions in Visual Studio?
Visual Studio&Source Control: How to have shared code?
You are in a whole new world. There is no equivalent.
If you want to share the class with out copying it in you create a class library and build your class into that library. Then you reference that built library from your project.
You can add a class library to your solution and the reference the project while you are developing. Class libraries act very similarly to the way BPLs do if you ever used those.
Once you have a class library you can then share the library between your solutions. This can be done in 2 ways - by building the library and sharing the binary - or by including the class libraries project in your solution. At first you probably want to go with the latter method till you get the hang of it, but once things get quite large and your shared code settles down it is better to reference the pre-built binary.
There is learning curve here - but at the end of the day you will be better off.
Good luck.
Joseph, Visual Studio does not provide this functionality, so must reference each class manually. Anyway to avoid to create a copy of your class every time which is included in a new project you must use the a option Add existing item selecting add as link.
Sorry but you cant do this, its good to know that Delphi provide such facility but may be Visual Studio doesn't do this because at the end of the day this may lead to a mess of linked files. Visual studio likes to organize related files in the same project or solution.
If you want to have your earlier class available then as mentioned above you have only two options.
1) Simply copy the existing .cs file in your project directory (By Right click on project -> "Add existing item" -> choose the class )
2) Add the Project in your solution (Right click on Solution -> Add -> Add Existing Project... -> Select the project file from File Browser) and then Add the class refrence (Right click on project -> "Add reference" -> In Projects Tab Select your Project). It will automatically make a reference to the .dll.
3) And last option is to compile your class in a .dll and then add the refrence to it in your Project.
Good Luck
You want to reference either a compiled .Net assembly (dll in this case) or another project that is part of the your solution. If you have the source, you add the library project to your solution. Then add the library project as a reference to the project that uses it. When it compiles, it'll copy the dll over to your build directory. Using this method is nice because you'll be able to step through the code in the library when using the debugger.

Categories