Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

683
Visualizações
Can not instantiate proxy of class: System.Net.HttpWebRequest. Could not find a parameterless constructor

I am upgrading my C# function app from .net 3.1 to 6.0`.

When I run my test cases, I found that, 1 of my test case failed with the below error.

Castle.DynamicProxy.InvalidProxyConstructorArgumentsException : Can not instantiate proxy of class: System.Net.HttpWebRequest. Could not find a parameterless constructor.

Basically, I am trying to mock HttpWebRequest and below is my piece of code for that.

var httpWebRequest = new Mock<HttpWebRequest>();

It is working fine in .Net 3.1. I am using Moq version 4.16.1 in both the projects.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Both HttpWebRequest constructors are obsolete and should not be used. You have to use the static function "Create" to create a new instance of the HttpWebRequest class:

HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("http://www.contoso.com/");

To solve your issue, use the HttpClient class instead. This class has a parameterless constructor.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda