• Register
0 votes
213 views

Problem :

I am facing below error while trying to compile my code of C# in visual Studio 2015.

“There is no argument given that corresponds to the required formal parameter”

7 5 2
3,870 points

2 Answers

0 votes

Solution :

I had also faced a same issue in the past. I did a lot of research on it and found a solution on it. Since the Circle inherits from the Oval, when you create the Circle a default constructor for Oval is called in this case. Since that constructor accepts only 2 parameters, you need to explicitly call a constructor and provide them as shown below:

class Circle : Oval
{
    private double rad;
    public Circle(double Circle_Radius) : base(0, 0) // change to your values
    {
      rad = Circle_Radius;  
    }
}

So the Circle is an Oval, so it has a major_axis and minor_axis values. It seems you just did not provide them as they are very much required values to create the Oval.

Of course you can add the default public constructor for your Oval with no parameters, but that makes you to create the Oval with no major_axis and minor_axis and both seem required by a only constructor in a current status of your code. So, you need to rethink how to design the classes.

 

9 7 4
38,600 points
0 votes

Solution:

You have a constructor which accepts 2 parameters. You must write something like:

new ErrorEventArg(errorMsv, lastQuery)

It's less code and simpler to read.

EDIT

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

public ErrorEventArg() {}

In the constructor of

 public class ErrorEventArg : EventArgs

You have to include "base" as follows:

  public ErrorEventArg(string errorMsg, string lastQuery) : base (string errorMsg, string lastQuery)
    {
        ErrorMsg = errorMsg;
        LastQuery = lastQuery;
    }

Your MenuModel class has a single constructor, which needs a DbContext parameter:

public MenuModel(DBContext context)

You are attempting to create an example of that class by calling the constructor without passing any parameters:

var menuModel = new NewWebsite_Site_2018.Pages.View.ViewBar_Info.MenuModel();

The compiler can't trace a constructor which doesn't accepts any parameters, and hence it generates the compiler error from your question.

You either require to pass the parameter to the constructor:

var menuModel = new NewWebsite_Site_2018.Pages.View.ViewBar_Info.MenuModel(new DBContext());

or include a parameterless constructor to the class:

public MenuModel() : this(new DBContext()) 
{
}

 

10 6 4
31,120 points

Related questions

0 votes
1 answer 26 views
26 views
Problem: I am beginner to C#. Please find below my code for your help: public class MySoundManager : MonoBehaviour { public List<AudioSource> audioSounds = new List<AudioSource>(); public double minTime = 0.5; public static void playSound(AudioClip sourceSound, Vector3 objectPosition, int ... to create the object of a class or create a methods as the static one but I don&rsquo;t know how to do it.
asked Jul 22 Raphael Pacheco 4.9k points
1 vote
1 answer 34 views
34 views
Problem : While binding the dropdown in MVC, I often face following error: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key country. Please find below my View for your reference : @Html.DropDownList("country", (IEnumerable<SelectListItem>)ViewBag ... .countryid.ToString() }); } ViewBag.mycountrydrop = myitem8; return View(); I do not know how to resolve above error.
asked Dec 28, 2019 alecxe 7.5k points
0 votes
1 answer 12 views
2 votes
1 answer 16 views
16 views
Problem : I am new to C# and I am currently preparing for my interview and I have below question. &ldquo;When to use abstract class and interface in c# with real time example&rdquo; Can somebody help me in finding correct answer for above question?
asked Mar 24 morrisBson 3.2k points