Solved

Accessing methods in different C# solutions

Posted on 2014-09-29
5
133 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 32

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 32

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 32

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

762 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now