Error calling a method in ASP.NET Web API and Ninject

Asked

Viewed 222 times

-1

I am getting error while trying to call a method from a Web API.

Declaration of the method in ApiController

public class AcessoController : ApiController
{

    [HttpGet]
    public UsuarioModel ValidarUsuario(string login, string senha, string modoAutenticacao)
    {

    }

}

Consuming the API

HttpClient client = new HttpClient();
client.BaseAddress = new Uri(ConfigurationManager.AppSettings["UrlAPI"]);
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

HttpResponseMessage response = new HttpResponseMessage();
response = await client.GetAsync(string.Format("api/Acesso/ValidarUsuario?login={0}&senha={1}&modoAutenticacao={2}", model.Login, model.Senha, (model.ModoAutenticacao == LoginViewModel.Dominio.Computecnica) ? "interno" : "externo"));

if (response.IsSuccessStatusCode) //esta retornando falso
{

}

Error:

Cannot be null Parameter name: root

It seems to be fault in the construction of the URL, since the execution of this method worked through Unittest.

  • 3

    This is bizarre. API consumes itself?

  • Seems to be missing the method when consuming the API? For example: client.GetAsync(string.Format("api/Acesso/ValidarUsuario?login={0}... (includes "Validarusuario" in the text)

  • I have been looking at this example and it seems to me that the name of the method is not given. It appears he identifies which method to call, according to past parameters. http://csharp-video-tutorials.blogspot.com.br/2016/09/aspnet-web-api-query-string-parameters.html

  • Anyway, I just made a test by putting the name of the method, but it still hasn’t worked. Code is updated in the main question.

  • @Ciganomorrisonmendez is not the same application. I have a WEB API project that validates users, and an MVC application that consumes this Web API

  • Does it keep giving error? Or now just returns false? Investigating the object response, vc has the answer HTTP code?

  • The same error continues. I tried calling the url directly from the browser: http://localhost:52337/api/Access/Validationroom? login=cpt&password=cpt&modoAutentico=external Error: Cannot be null Parameter name: root

  • I was going to tell you to do it. : ( I did a search in English and this error only appears to those who are using Ninject. You are using Ninject?

  • Yes, this one has the same coding as the MVC project, because they both share the same data access project, which is encoded with dependency injection.

  • Maybe the solution to these posts can help you: http://stackoverflow.com/questions/3703903/wcf-with-ninject-throwing-argumentnullexception or http://stackoverflow.com/questions/5451580/ninject-wcf-extension-argumentnullexception-using-net-tcp-Binding They talk about upgrading libraries to newer version...

  • 1

    Thanks for the help. Searching on the subject, I discovered that the problem was in the lack of installation of the package Webactivaotorex, Ninjectmvc5.

Show 6 more comments

1 answer

1

As spoken by comment, check if the package Webactivatorex was installed together with Ninject.

The mistake:

Cannot be null Parameter name: root

It’s triggered by the Ninject, not exactly by the ASP.NET Web API.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.