Describe the bug
So I'm trying to get a WebServer library project , which is based on .NET Standard 2.0, to work with a console project, which is based on.NET Framework 4.6.1 running. However, I'm unable get back responses from the API controllers, while static resources work fine.
.NET Standard 2.0 library via .NET Framework 4.6.1 console app. .NET Standard 2.0 library via .NET Core console app. To Reproduce
Steps to reproduce the behavior:
public class TestWebServer
{
public TestWebServer()
{
WebServer server = new WebServer("http://localhost:4002", RoutingStrategy.Regex)
.WithWebApiController<TestController>();
server.RunAsync();
}
}
public class TestController : WebApiController
{
[WebApiHandler(HttpVerbs.Get, "/hello")]
public Task<bool> HelloThere(WebServer server, HttpListenerContext context)
{
return context.StringResponseAsync("Hello there!");
}
}
class Program
{
static void Main(string[] args)
{
TestWebServer test = new TestWebServer();
Console.ReadLine();
}
}
http://localhost:4000/helloExpected behavior
I expect no 404 when hitting /hello
Screenshots
Desktop (please complete the following information):
Smartphone (please complete the following information):
Additional context
If you need anything more, I'm happy to help ๐
Can you upload a sample project? I'm not quite sure to understand the issue.
On Sat, Sep 1, 2018, 5:01 PM Jonas Dellinger notifications@github.com
wrote:
Describe the bug
So I'm trying to get a WebServer library project , which is based on .NET
Standard 2.0, to work with a console project, which is based on.NET
Framework 4.6.1 running. However, I'm unable get back responses from the
API controllers, while static resources work fine.
- DOESN'T WORK: .NET Standard 2.0 library via .NET Framework 4.6.1
console app.- WORKS: .NET Standard 2.0 library via .NET Core console app.
To Reproduce
Steps to reproduce the behavior:
Create a new basic .NET Standard 2.0 lib and add embedio
public class TestWebServer
{
public TestWebServer()
{
WebServer server = new WebServer("http://localhost:4002", RoutingStrategy.Regex)
.WithWebApiController();
server.RunAsync();
}
}public class TestController : WebApiController
{
[WebApiHandler(HttpVerbs.Get, "/hello")]
public TaskHelloThere(WebServer server, HttpListenerContext context)
{
return context.StringResponseAsync("Hello there!");
}
}Add a ".NET Framework 4.6" project and reference your .NET Standard
libclass Program
{
static void Main(string[] args)
{
TestWebServer test = new TestWebServer();
Console.ReadLine();
}
}Try to reach http://localhost:4000/hello
- Get a 404
Expected behavior
I expect no 404 when hitting /helloScreenshots
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Additional context
If you need anything more, I'm happy to help ๐โ
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/unosquare/embedio/issues/188, or mute the thread
https://github.com/notifications/unsubscribe-auth/ABsYsNH5GZMCIg2N3b5ZttMZUw0ua8YAks5uWwO2gaJpZM4WWYnC
.
I'm actually seeing the same thing. The library I'm building using your package (awesome work by the way) is a .NET Standard 2.0. I'm testing the library using a console app built in .NET 4.6.1. There are no errors when running the test app, but REGEX web api controller always returns error 404. When I build a test app using .NET Core and test the library, it works!
Trying to reproduce the issue, I'm getting the following exception:
System.IO.FileNotFoundException
HResult=0x80070002
Message=Could not load file or assembly 'Unosquare.Swan.Lite, Version=0.33.4.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
Source=Unosquare.Labs.EmbedIO
StackTrace:
at Unosquare.Labs.EmbedIO.WebServer..ctor(String[] urlPrefixes, RoutingStrategy routingStrategy) in C:\Unosquare\embedio\src\Unosquare.Labs.EmbedIO\WebServer.cs:line 89
at Unosquare.Labs.EmbedIO.WebServer..ctor(String urlPrefix, RoutingStrategy strategy) in C:\Unosquare\embedio\src\Unosquare.Labs.EmbedIO\WebServer.cs:line 52
at IssueLib.TestWebServer..ctor() in C:\Unosquare\embedio\src\IssueLib\TestWebServer.cs:line 14
at Test461.Program.Main(String[] args) in C:\Unosquare\embedio\src\Test461\Program.cs:line 13
After adding the missing nuget, the /hello endpoint is responding correctly. I created a branch with the sample lib and console app.
If adding the nuget fix your issues, it must be something wrong when the nuget client is resolving dependencies. Try to use .NET 4.6, for example.
@geoperez I created a small test project based on nuget packages here (uses 8080 as port and the / endoint): https://github.com/JohnnyCrazy/EmbedIOTestProject
You were right, I had to add the nuget package. But still, I was not able to reach the controller, always got a 404.
OK, let me take a look.
This is the issue:
16:44:17.476 ERR >> [WebServer] Failing module name: Web API Module
$type : System.InvalidCastException
Message :
Unable to cast object of type 'Unosquare.Net.HttpListenerContext' to type 'System.Net.HttpListenerContext'.
TargetSite :
System.Threading.Tasks.Task`1[System.Boolean] lambda_method(System.Runtime.CompilerServices.Closure, System.Object, System.Object[])
StackTrace :
at lambda_method(Closure , Object , Object[] )
at Unosquare.Labs.EmbedIO.MethodCacheInstance.Invoke(Object[] arguments) in C:\Unosquare\embedio\src\Unosquare.Labs.EmbedIO\MethodCache.cs:line 112
at Unosquare.Labs.EmbedIO.Modules.WebApiModule.<<-ctor>b__2_0>d.MoveNext() in C:\Unosquare\embedio\src\Unosquare.Labs.EmbedIO\Modules\WebApiModule.cs:line 95
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at Unosquare.Labs.EmbedIO.WebServer.<ProcessRequest>d__34.MoveNext() in C:\Unosquare\embedio\src\Unosquare.Labs.EmbedIO\WebServer.cs:line 252
Source : Anonymously Hosted DynamicMethods Assembly
HResult : -2147467262
Explanation - We are using two HttpListener implementations, one from Microsoft and one custom in the core of EmbedIO. The target .NET 4.6 will always use (at least in this version) the custom HttpListener and NET Standard 2.0 will use Microsoft's. So when you build an assembly your WebAPI Controller code will expect classes from System.Net, but the runtime will be running against Unosquare.Net so they won't connect.
We are refactoring this and other issues with the compatibility between many frameworks, allowing to choose the HttpListener from a Factory.
Oh okay, got it. is there any current workaround or do I have to wait till 2.0?
This would fix https://github.com/JohnnyCrazy/SpotifyAPI-NET/issues/279
The only workaround I can suggest, for now, it's to support NET46 as a target framework along with NET Standard 2.0 in your library.
Alright, I will try that, thanks for your quick help and awesome library ๐
EmbedIO 2.0 RC2 is ready to be tested (https://www.nuget.org/packages/EmbedIO/2.0.0-rc2)
I will appreciate the feedback.
EmbedIO 2.0 RC2 is ready to be tested (https://www.nuget.org/packages/EmbedIO/2.0.0-rc2)
I will appreciate the feedback.

Got this error.
Can you elaborate how did you get the error?
Working sample
Sample.zip

working?
My bad, previous version. EmbedIO must be declared in the TheExe dependencies:
@JohnnyCrazy can I close this issue?
I will try to test it today and report back :+1:
@geoperez I would gladly like to test it out, but as it seems right now, I won't get to it before monday in a week due my thesis deadline...If you are able to delay the release, I will test it ASAP!
Sure, no problem.
I know it's kinda old, but I successfully tested the last version and it seems to work fine ๐
Great work on this library BTW :)
Thanks.
Most helpful comment
This is the issue:
Explanation - We are using two HttpListener implementations, one from Microsoft and one custom in the core of EmbedIO. The target .NET 4.6 will always use (at least in this version) the custom HttpListener and NET Standard 2.0 will use Microsoft's. So when you build an assembly your WebAPI Controller code will expect classes from System.Net, but the runtime will be running against Unosquare.Net so they won't connect.
We are refactoring this and other issues with the compatibility between many frameworks, allowing to choose the HttpListener from a Factory.