Solved

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

Posted on 2014-10-28
9
234 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Lotus Notes – formerly IBM Notes – is an email client application, while IBM Domino (earlier Lotus Domino) is an email server. The client possesses a set of features that are even more advanced as compared to that of Outlook. Likewise, IBM Domino is…
Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
In this video we show how to create an Address List 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 Organization >> Ad…
In this Micro Video tutorial you will learn the basics about Database Availability Groups and How to configure one using a live Exchange Server Environment. The video tutorial explains the basics of the Exchange server Database Availability grou…

930 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

10 Experts available now in Live!

Get 1:1 Help Now