Solved

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

Posted on 2014-10-28
9
214 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
 
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
Do email signature updates give you a headache?

Do you feel like you are constantly making changes to email signatures? Are the images not formatting how you want them to? Want high-quality HTML signatures on all devices, including on mobiles and Macs? Then, let Exclaimer solve all your email signature problems today.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Learn to move / copy / export exchange contacts to iPhone without using any software. Also see the issues in configuration of exchange with iPhone to migrate contacts.
Scam emails are a huge burden for many businesses. Spotting one is not always easy. Follow our tips to identify if an email you receive is a scam.
In this video we show how to create a mailbox database in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Servers >> Data…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

744 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now