tags:

views:

57

answers:

3

Hi all, I have created an exe with some methods in it (ref example exe below).

using System;  
using System.Collections.Generic;  
using System.Text;  

namespace SampleRef  
{  
  public class Program  
  {  
  static void Main(string[] args)  
    {  
    }  
  }  
  public class Sample  
  {    
   public Sample(int count)  
    {

    }

    public string SampleString(int InputValue)
    {
      //Do something
       return "<the result>";
    }
  }  
}  

I want to add reference this exe into my web application to call (SampleString) methods in side the exe. Is it possible in .net and how can I achieve this?

+1  A: 

Yes - just add it as if it were a class library. Visual Studio has supported this since 2005.

EDIT: Okay, it sounds like ASP.NET may not like .exe assemblies :(

In that case I suggest you extract the code from your current executable and put it into a class library. You may find it easier to change the whole of your normal application into a DLL - and just add another executable project which does nothing but call into the DLL to start the "application". That shouldn't be the end-point of your code, but it's an easy way to get up and running.

Jon Skeet
Hi Jon, I have added with Add reference thro VS2005. But in web app, the namespace SampleRef is available.
Selva TS
@Selva TS: It certainly should be... what happens if you add a `using SampleRef;` statement in your code?
Jon Skeet
Hi Jon, It shows compiler error in my web app.
Selva TS
@Selva: What exact compiler error? Do you see the same error if you add a reference to a normal class library?
Jon Skeet
Hi Jon, I got this compiler error when adding reference the exe.(Actually reference added but not accessible in code) - "The type or namespace name 'SampleRef' could not be found (are you missing a using directive or an assembly reference?)"
Selva TS
@Selva: Okay - and what happens if you just add a reference to a class library (for testing purposes)?
Jon Skeet
When adding a class library all the methods are available for use. But adding exe makes only problem.
Selva TS
@Selva TS: Okay... maybe it's something weird that ASP.NET's doing... it would certainly be fine from a normal application :(
Jon Skeet
Hi Jon thanks.. Yes.. I have checked with console application as well as windows application. It works fine. But in ASP.Net application only it makes problem.
Selva TS
@Selva: In that case, I'm afraid I don't know... will edit my answer.
Jon Skeet
A: 

Yes.

Just go to the Project menu, select Add Reference change to the Browse tab and find and select the executable.

ho1
A: 

Final compiled output in .Net is called Assemblies and EXEs are no different in this case. It's just that they carry a special header that identify them as executables with program entry points and normal compiled dll assemblies don't have this, but both are assemblies and you can add assemblies as reference in any .net project you're working on.

this. __curious_geek