There Is No Argument Given That Corresponds to the Required Formal Parameter - .Net Error

There is no argument given that corresponds to the required formal parameter 'context of GenericRepository Incident .GenericRepository(dbContext)

The error tells you that you don't call an appropriate base constructor. The constructor in the derived class ...

public IncidentRepository(db_SLee_FYPContext context)
{
this.context = context;
}

... is in fact doing this:

public IncidentRepository(db_SLee_FYPContext context)
: base()
{
this.context = context;
}

But there is no parameterless base constructor.

You should fix this by calling the matching base constructor:

public IncidentRepository(db_SLee_FYPContext context)
: base(context)
{ }

In C# 6 you get this message if there is only one constructor in the base type, so it gives you the best possible hint which argument in the base constructor is missing. In C# 5 the message would simply be

GenericRepository does not contain a constructor that takes 0 arguments

There is no argument given that corresponds to the required formal parameter - .NET Error

You have a constructor which takes 2 parameters. You should write something like:

new ErrorEventArg(errorMsv, lastQuery)

It's less code and easier to read.

EDIT

Or, in order for your way to work, you can try writing a default constructor for ErrorEventArg which would have no parameters, like this:

public ErrorEventArg() {}

Resolve error 'there is no argument given that corresponds to required formal parameter'?

Fixing your bug:

The error occurs due to the lack of a parameterless constructor (or your lack of using the base() method in your constructor (just like user3185569 had said)

Fixing your code:

It clearly seems you are lacking some basics in .NET so I've decided to give a re-writing to your code with the following things in mind:

a. Conventions

There are some rules about common conventions that should apply to your code.

Members usually begin with either m or _ and then the memberName (camel casing).

Properties are usually written regularly as PropertyName and same applies to methods.

Parameters and variables are simply camel cased like parameterName

b. Access Modifiers

I don't know the use of your Oval and circle but I assume you'd want to access them outside of Oval and Circle.

I think it would be the best to reference you to here to read some more about the topic: https://msdn.microsoft.com/en-us/library/ms173121.aspx

I've re-written your code to include all those tips (and also fix your issue)

public class Oval:Shape
{
//Constructor
public Oval(double majorAxis, double minorAxis)
{
MajorAxis=majorAxis;
MinorAxis=minorAxis;
}

protected double MajorAxis{ get; set; }
protected double MinorAxis{ get; set; }
}

public class Circle:Oval
{
//Constructor
public Circle(double radius): base(radius,radius)
{
radius = Circle_Radius;
}

public double Radius
{
get
{
return MajorAxis;
}
set
{
MajorAxis = value;
MinorAxis = value;
}
}
}

There is no argument given that corresponds to the required formal parameter - when trying to test OOP Inheritance

TL;DR: Constructors aren't inherited.

Longer explanation: Your Test2 class implicitly has a constructor like this:

public Test2() : base()
{
}

... because you haven't declared any constructors in Test2. If you declare any constructor in Test2, the compiler won't try to provide the implicit one. (Your constructor will need to call base(...) providing a value for p though.

So you probably want:

public class Test2 : Test
{
public Test2(int p) : base(p)
{
}
}

CS7036:There is no argument given that corresponds to the required formal parameter 'i'

In the constructor of the child class you must reference the parameters of the parent/base class.
In this case change the constructor of the Car class to the following.

//Inside class Car
public Car(string i, string modelName, double priceVal, string ColorName, bool avail) : base(i)
{
//Code inside
}

This is all that cause an issue not anything else.

Error: There is no argument given that corresponds to the required formal parameter 'password'

The error message is saying the compiler looked for a value for the password parameter but could not find it.

Looking at your code, that is a parameter of the UPDATE method.

In your call to the UPDATE method, you are indeed supplying a password. So why the error? Well, we have to ensure the arguments we are passing match up with the parameters in the method signature. In this case, you are passing the password as the fifth parameter, which maps to TYPEROLE. So the password is being assigned to TYPEROLE, and there is no value being assigned to the password parameter, hence the error.

Side note: You are using a seemingly random mix of upper and lower case for your parameter names. I'd recommend consistent casing in order to improve code maintainability. A commonly accepted standard for parameter names is camel case. Using this scheme, TYPEROLE becomes typeRole, for example.

No argument was given that corresponds to the required formal parameter 'htmlAttributes' of 'IHtmlHelper - DropDownListFor

I finally found the solution to my problem.
What I had to do finally was to use the IHtmlHelper DropDownList
instead of DropDownListFor.

My razor View code:

@Html.DropDownList("Provincia",  PoblacionesExtensions.ToSelectList(ViewBag.locations), optionLabel: null, htmlAttributes: new{@class="form-control form-control-login font-weight-bold p-0"} )  

My Controller's code for returning the view with the model I applied to it.

   [AllowAnonymous]
public async Task<IActionResult> ContactUs()
{
var data = new ContactUsPageModel();
var user = await userSessionVars.GetCurrentUser();
var locationsVar = await userSessionVars.GetCurrentLocation();
ViewBag.locations = locationsVar;

if (user != null)
{
data = new ContactUsPageModel()
{
Name = $"{user.Nombre} {user.Ape1} {user.Ape2}",
Phone = user.UserName,
Email = user.Email,
Provincia = locationsVar
};
}

return View(data);
}

Here is the task from the service I am using to get the locations for my dropdown.
I had to explicitly declare the final received locations variable as type of List<string>.

 public async Task<List<string>> GetCurrentLocation()
{
var ConsultaLocalidadesEsp = await ServiceEntityHub.ConsultaLocalidadesEsp();
var locations = JsonConvert.DeserializeObject<List<PoblacionDto>>(ConsultaLocalidadesEsp);
List<string> locationsFinal = locations.Select(x => x.provincia).Distinct().ToList();
return locationsFinal;
}

As a final observation, the initial problem I think was with the DropDownListFor IHtmlHelper which was creating the issue and thus by applying this new approach it solved my problem.

There is no argument given that corresponds to the required formal parameter 'options'

LakeViewContext expects a DbContextOptions<LakeViewContext> to be passed into its constructor. However, you are calling the constructor without providing anything:

private LakeViewContext db = new LakeViewContext();

To fix the issue, you can just plug into the Dependency Injection system that you've set up. To do this, change your controller as follows:

public class CoursesController : Controller
{
private readonly LakeViewContext db;

public CoursesController(LakeVieContext db)
{
this.db = db;
}

...

The ASP.NET Core Dependency Injection system will provide you with a LakeViewContext in the constructor - Just use that.

There is no argument given that corresponds to the required formal parameter - c#

the signature of GenerateRequestUriData has four parameters

GenerateRequestUriData(string endpoint, string dateQuery, string num, int statNum)

you are only passing ONE

GenerateRequestUriData(Constants.EndPoint)

you either need to pass all the required parameters, or set default values for them



Related Topics



Leave a reply



Submit