Solved

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

Posted on 2014-10-28
9
249 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
  • 5
  • 2
  • 2
9 Comments
 
LVL 35

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
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 35

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
Following basic email etiquette rules will help you write a professional email and achieve a good, lasting impression with your contacts.
In this video we show how to create a Resource Mailbox in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: Navigate to the Recipients >> Resources tab.: "Recipients" is our default selection …
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…

829 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