Solved

Accessing methods in different C# solutions

Posted on 2014-09-29
5
137 Views
Last Modified: 2014-10-03
We have a situation were we are developing an NT Service application in C# that will need to run various methods contained in a separate MVC 4.0 application.   These methods can be in a controller or simply in a C# class.

What is the best way for the separate C# program to call other C# program's methods but are not in the same solution?

We are looking at having the methods in their own .DLL or maybe adding a web service to the MVC application.

Any ideas on what would work best?
0
Comment
Question by:jkanisut
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:it_saige
ID: 40351035
You hit it right on the head.

Having multiple projects simply requires a reference from Project B into Project A.

I.E. (Untested)
ProjectA
using System;
using ProjectB;

namespace ProjectA
{
	public class ProjectAClass
	{
		public void ShowProjectB()
		{
			ProjectBClass bClass = new ProjectBClass();
			Console.WriteLine(bClass.ShowProjectB());
		}
	}
}

Open in new window

ProjectB
using System;

namespace ProjectB
{
	public class ProjectBClass
	{
		public string ShowProjectB()
		{
			return "Saying hello from Project B";
		}
	}
}

Open in new window


-saige-
0
 
LVL 1

Author Comment

by:jkanisut
ID: 40351043
But these will be different / separate solutions...
0
 
LVL 33

Expert Comment

by:it_saige
ID: 40351051
Yes.  Here is a more complete example:

stackoverflow.com/questions/3554658/how-to-use-a-class-from-one-c-sharp-project-with-another-c-sharp-project

A solution is nothing more than a group of one or more projects.  Using multiple solutions does not prevent you from accessing members cross solution or even cross solution; cross project.

-saige-
0
 
LVL 33

Accepted Solution

by:
it_saige earned 500 total points
ID: 40351063
More information regarding referencing projects from other solutions:

stackoverflow.com/questions/9568094/how-should-i-reference-assemblies-from-another-solution

Quite simply, once you build one projects output.  You add a reference to the project output via browsing for the output file.  The rules with regards to assembly resolution apply:

http://msdn.microsoft.com/en-us/library/yx7xezcf(v=vs.110).aspx

-saige-
0
 
LVL 1

Author Closing Comment

by:jkanisut
ID: 40360779
Thanks for pointing me in the right direction.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video teaches viewers about errors in exception handling.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question