jeudi 6 août 2015

Can't load self host http server in reflection

I have a class library that runs a self host http server. it has a SimpleController

public class SimpleController : ApiController
{
    public string Get()
    {
        return "Hello World!";
    }
}

and some class to run the server itself:

public class Server : ICommiunication // ICommiunication is my interface which only has one method - void Run()
{
private readonly HttpSelfHostConfiguration _config;

public Server()
{
    _config = new HttpSelfHostConfiguration("http://localhost:9876")
    _config.Routes.MapHttpRoute(
        "API Default", "api/{controller}/{id}",
        new { id = RouteParameter.Optional });
}

public void Run()
{
    using (var server = new HttpSelfHostServer(_config))
    {
         server.OpenAsync().Wait();
         Console.WriteLine("Press Enter To Quit");
         Console.ReadLine();
    }
}
}

When I compile the project I get System.Web.Http.dll in my output directory (as I Should) when I try to load the dll in reflection:

var ass = Assembly.LoadFile(@"C:\whatever\MySelfHost.dll")
compType = ass.GetTypes().FirstOrDefault(t=>t.GetInterfaces().Select(inter=>inter.Name).Contains("ICommiunication"));

I get an exception System.IO.FileNotFound - can't find or load System.Web.Http... when I install self host http nuget on the loading project it works fine. but I should'nt install my reflection dependencies. anyone has an idea why this is happening? why can't it load the System.Web.Http.dll?





Aucun commentaire:

Enregistrer un commentaire