EWS error Exception Message = "The type initializer for 'Microsoft.Exchange.WebServices.Strings' threw an exception." RRS feed

  • Question

  • Hi I am trying to create a console application to read mails from Exchange server. I am getting this error at autodiscover "The type initializer for 'Microsoft.Exchange.WebServices.Strings' threw an exception."

    I checked my Exchange server version - 14.2.xxxx
    Exchange Web Services Managed API Version 2.0(Version15.0.0.xxxx)
    I am a normal user having email account in my company
    I am developing this code in win server 2008 R2(admin access), VS2010, outlook configured.
    I have figured out EWS intranet url also and tried passing that as well - no luck
    I have tried below code-

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.Security;
    using System.Security.Cryptography.X509Certificates;
    using System.Net.Security;
    using System.Web;
    using Microsoft.Exchange.WebServices.Data;
    namespace FinalEWS
        class Program
            static void Main(string[] args)
                ExchangeService service = CreateConnection("");
                //ExchangeService service = CreateConnection("");
                EmailMessage msg = new EmailMessage(service);
                msg.ToRecipients.Add(new EmailAddress(""));
                msg.Subject = "EWS Test email";
                msg.Body = new MessageBody(BodyType.HTML, "<p>Hello Email!</p>");
     public static ExchangeService CreateConnection(String url)
                // Hook up the cert callback to prevent error if Microsoft.NET doesn't trust the server    
                ServicePointManager.ServerCertificateValidationCallback =
                Object obj, X509Certificate certificate,
                X509Chain chain,
                SslPolicyErrors errors)
                    return true;
                ExchangeService service = new ExchangeService();

                //service.Url = new Uri(url);
                service.Credentials = new NetworkCredential("username", "password", "domain");
                //service.UseDefaultCredentials = true;
                return service;


    Saturday, August 11, 2012 8:36 AM


  • Are you developing against Exchange 2012 Preview ? if not you would better to use the release version 1.2 of the managed api

    Version 2.0 is in Beta I've had that error your having and the fix was to install the .NET 4.5 RC (you don't have to compile against it but it seems to change the  'System.Runtime.CompilerServices.ExtensionAttribute' type in 4.0.)


    • Marked as answer by GauravHP Wednesday, August 15, 2012 8:22 AM
    Monday, August 13, 2012 7:33 AM