Solved

Error Message: does not contain a constructor that takes 1 arguments

Posted on 2014-10-28
9
254 Views
Last Modified: 2014-10-29
I am trying to send an an Exchange Calendar Event from c#. When I call it from Page_Load it works great. However when I call it from an on_click function I get an error saying "does not contain a constructor that takes 1 arguments." Why is that?

        protected void Page_Load(object sender, EventArgs e)
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
            service.Credentials = new WebCredentials("Email", "Password");
            service.AutodiscoverUrl("Email", RedirectionUrlValidationCallback);
            Appointment meeting = new Appointment(service);
            meeting.Subject = "Team Building Exercise";
            meeting.Body = "Everyone is invited";
            meeting.Start = DateTime.Now.AddDays(5);
            meeting.End = meeting.Start.AddHours(4);
            meeting.StartTimeZone = TimeZoneInfo.Local;
            meeting.EndTimeZone = TimeZoneInfo.Local;
	    meeting.RequiredAttendees.Add("Mack@contoso.com");
            meeting.RequiredAttendees.Add("Sadie@contoso.com");
            meeting.OptionalAttendees.Add("Magdalena@contoso.com");
            meeting.ReminderMinutesBeforeStart = 60;
            meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
            Item item = Item.Bind(service, meeting.Id, new PropertySet(ItemSchema.Subject));
            label1.Text = item.Id + "has been scheduled"; 
        }

	protected void EnterAppointment_Click(object sender, EventArgs e)
        {
            ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
            service.Credentials = new WebCredentials("Email", "Password");
            service.AutodiscoverUrl("Email", RedirectionUrlValidationCallback);
            Appointment meeting = new Appointment(service);
            meeting.Subject = "Team Building Exercise";
            meeting.Body = "Everyone is invited";
            meeting.Start = DateTime.Now.AddDays(5);
            meeting.End = meeting.Start.AddHours(4);
            meeting.StartTimeZone = TimeZoneInfo.Local;
            meeting.EndTimeZone = TimeZoneInfo.Local;
	    meeting.RequiredAttendees.Add("Mack@contoso.com");
            meeting.RequiredAttendees.Add("Sadie@contoso.com");
            meeting.OptionalAttendees.Add("Magdalena@contoso.com");
            meeting.ReminderMinutesBeforeStart = 60;
            meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
            Item item = Item.Bind(service, meeting.Id, new PropertySet(ItemSchema.Subject));
            label1.Text = item.Id + "has been scheduled"; 
	}

        private static bool RedirectionUrlValidationCallback(string redirectionUrl)
        {
            bool result = false;

            Uri redirectionUri = new Uri(redirectionUrl);

            // Validate the contents of the redirection URL. In this simple validation
            // callback, the redirection URL is considered valid if it is using HTTPS
            // to encrypt the authentication credentials. 
            if (redirectionUri.Scheme == "https")
            {
                result = true;
            }
            return result;
        }

Open in new window

0
Comment
Question by:RecipeDan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
  • 2
9 Comments
 
LVL 36

Expert Comment

by:Miguel Oz
ID: 40409913
Is this the faulty line?
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);

If so please change it to:
ExchangeService service = new ExchangeService();

No need to specify version when you are targeting the latest one.
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 40409923
No it is this line that is showing the error:

Appointment meeting = new Appointment(service);
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 40409925
I tried your suggestion and still get the same error message
0
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 
LVL 36

Expert Comment

by:Miguel Oz
ID: 40409951
That is very odd - the code looks right.
Q1. Did you remove the page load code before running the click event handler?
Q2. Have you had a breakpoint in the faulty line to check that service is initialized correctly?
Q3. What VS/ASP.NET MVC version are you using?

Note: You could try to declare service as private variable of your page and remove the constructor line, thus the service variable will be available for the lifetime of the page not just the click event handler.
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 40409998
Q1: Yes I did
Q2: Yes it is being initialized
Q3: I am using web forms

I did try it as a private variable before I posted the question. Same result.
0
 
LVL 15

Expert Comment

by:ChloesDad
ID: 40410132
Have you put a breakpoint in the page_Load routine to verify that Page_Load is actually being executed?
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 40410399
The Page_Load works fine. It is when I put the routine in an on_click function the error message pops up
0
 
LVL 15

Accepted Solution

by:
ChloesDad earned 500 total points
ID: 40410500
The only reason that this can happen is if the on_click event is seeing another class called Appointment that does not take a parameter in its constructor.

What happens if you enter the full namespace of the appointment class.

Microsoft.Exchange.WebServices.Data.Appointment
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 40410657
Yes that was the case. The page name is appointment.aspx. So I renamed the page and it works fine. Thank you for your assistance.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question