?
Solved

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

Posted on 2014-10-28
9
Medium Priority
?
260 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
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
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 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
A couple of months ago we ran into an issue that necessitated re-creating our Edge Subscriptions. However, when we attempted to execute the command: New-EdgeSubscription -filename C:\NewEdgeSub_01.xml we received an error indicating that the LDAP se…
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…
Suggested Courses

770 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