Solved

Accessing methods in different C# solutions

Posted on 2014-09-29
5
141 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 34

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 34

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 34

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
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…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

718 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