Closed Cruik closed 8 years ago
Are you using RC1? These new APIs are only in the upcoming RC2 build. If you're looking for RC1 bits I'd suggest:
or making a new empty web project and looking at the Main method
@Itempas You mean ASP.NET 4 Web API 2? Because this repo tracks ASP.NET Core 1 work. And Web API has been merged with MVC in MVC Core 1.
@muratg i m using RC2 and also asp.net core 1. i can make it compile now but till i am very new to web api thing i need some more experience and time.
i get now the: The given assembly name or codebase was invalid. with the following code:
var host = new WebHostBuilder()
.UseDefaultConfiguration(args)
.UseServer("http://localhost:5004")
.UseStartup<Program>()
.Build();
What's the full exception and stack trace?
Ah sry my bad, forget to take the complete stack trace :)
at System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent) at System.Reflection.AssemblyName..ctor(String assemblyName) at Microsoft.AspNetCore.Hosting.Server.ServerLoader.LoadServerFactory(String assemblyName) at Microsoft.AspNetCore.Hosting.Internal.WebHost.EnsureServer() at Microsoft.AspNetCore.Hosting.Internal.WebHost.BuildApplication() at Microsoft.AspNetCore.Hosting.WebHostBuilder.Build() at ConsoleHost.Program.Main(String[] args) in C:\Users\e1073\Documents\Visual Studio 2015\Projects\TraverseFileSystem\ConsoleHost\Program.cs:line 13
@Itempas can you make a repository on github with the repro and instructions on how you ran it?
How did you end up with this solution? There are a few problems:
WebApi2
-*
version in there. Pick a specific version across the board and stick with it. If you mix and match while we're in pre-release, you'll be in a world of hurt.ConsoleHost
Which project is giving you the error? Also, is it a runtime error now? The original post had a compile time error.
Note your ConsoleHost .UseStartup<Program>()
won't work because Program does not have a Configure method to setup the app. It should be referring to WebApi2's Startup class instead.
@Itempas Let us know if fixing the references + using Startup instead of Program did not fix your issue.
Sry guys, i was on vacation for a few days.
I updated my code now and get the following stack strace:
at System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent) at System.Reflection.AssemblyName..ctor(String assemblyName) at Microsoft.AspNet.Hosting.Server.ServerLoader.LoadServerFactory(String assemblyName) at Microsoft.AspNet.Hosting.Internal.HostingEngine.EnsureServer() at Microsoft.AspNet.Hosting.Internal.HostingEngine.BuildApplication() at Microsoft.AspNet.Hosting.Internal.HostingEngine.Start() at ConsoleHost.Program.Main(String[] args) in C:\Users\e1073\Source\Repos\WebApi2Test\ConsoleHost\Program.cs:line 18
Source is mscorlib
The exception is thrown at host.Start():
The code is on : https://github.com/Itempas/UpdatedWebApi2Test/tree/Test
Am i missing a thing ?
var host = CreateWebHostBuilder()
.UseServer("Microsoft.AspNet.Server.Kestrel")
.UseUrls("http://localhost:5004")
.UseStartup<Program>()
.Build();
Also add "Microsoft.AspNet.Server.Kestrel" to your project dependencies.
Hey @Tratcher , thanks for your reply!
i tried that, but i get an error with .UseUrls()
'WebHostBuilder' does not contain a definition for 'UseUrls' and no extension method 'UseUrls' accepting a first argument of type 'WebHostBuilder' could be found (are you missing a using directive or an assembly reference?) ConsoleHost.DNX Core 5.0
@Itempas instead of this back and forth can you make a project that reproduces the issue? We cant tell what versions you;re using so it would be better if you could provide a project on github with the project.json and project.lock.json so we can take a look.
@davidfowl yeah , sure.
i just added the code from Tratcher to my Program.cs + the reference in project.json
So you're using rc1
yep, since i couldn´t found a rc2-final
rc2 is far from final.
Thats the reason why i decided to stick with rc1 :D sry if it´s annoying, i just began with Web API and i want to understand it :x
Hey guys, i got it!!
The server is running but now he is refusing my connections when i try to call the controller actions via browser :/
The code is here : https://github.com/Itempas/UpdatedWebApi2Test/tree/Test
Locally or remotely?
I m testing it locally on my computer
or shall i open a new issue for that ?
I'm not sure there's any issue yet. I think you just have a mix of package versions and it's causing problems.
The important packages are: "Microsoft.AspNet.Hosting": "1.0.0-rc1-final", "Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final", "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final" Am i right?
Sure, it looks like all Rc1 bits now.
that would mean that the packages are right ?
Note you're getting a 500 response from the controller. When I added app.UseDeveloperExceptionPage();
from Microsoft.AspNet.Diagnostics
I see this error:
InvalidOperationException: No service for type 'WebApi2.Repository.IContactsRepository' has been registered.
Adding the following fixed it:
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore();
services.AddSingleton<IContactsRepository, ContactsRepository>();
}
Hey guys,
i m not able to set up a Web Api 2 service as a self hosted console applicaton. My problem is more precisely in this Stack Overflow Post:
http://stackoverflow.com/questions/35943690/using-web-api-2-as-self-console-host-in-c-sharp
Hope you can help me :+1: