sensaura-public / iotweb

A simple HTTP and WebSocket server component for Windows 10 IoT Core and .NET 4.5
38 stars 21 forks source link

HttpServer for Background Application #8

Closed JamieMeyer closed 7 years ago

JamieMeyer commented 7 years ago

I am trying to implement the HttpServer in an IOT background application. During the instantiation, I get an exception when trying to get the current assembly; Webserver.AddHttpRequestHandler( "/", new HttpResourceHandler( Utilities.GetContainingAssembly(typeof(StartupTask)), "BrowserUI", "index.html" ) ); A simplification of this code is: Assembly test = Utilities.GetContainingAssembly(typeof(StartupTask));

This alone triggers the exception, so I have ruled out the WebServer, but I still need to have this work in the background app.

Has anyone been able to resolve this issue?

Windows IOT version is 10.0.14393.187

I have also cross-posted this in a simplified form as [http://stackoverflow.com/questions/39810947/cannot-obtain-containing-assembly-in-background-application]

JamieMeyer commented 7 years ago

I was able to work around this issue with the following code: Assembly ThisAssembly = typeof(StartupTask).GetTypeInfo().Assembly;

This works due to the fact that the resources are available in the executing assembly. I have not debugged the source, but it may still be an issue with other assemblies which contain the resources. The Utilities code also attempts to load the assembly, which this approach obviously does not do.