none
Microsoft.Exchange.WebServices.Data -> AutodiscoverUrl() throwing Null referencing when called using .net core 2.1

    Question

  • Hi,

       I am facing some issue while working with Exchange on a .net core application. It is giving null reference error while calling AutodiscoverUrl(). Following is piece of code I am using, same code works fine when called from a .net application -:

                                        

                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
                try
                {

                        service.EnableScpLookup = false;
                        service.Credentials = new WebCredentials("*****@outlook.com", "******");
                        service.Timeout = 25000;
                        string email = "*****@outlook.com";

                        if (!string.IsNullOrEmpty(email) && email.Split('@').Length > 1)
                        {
                            service.AutodiscoverUrl(email, RedirectionUrlValidationCallback);
                        }
                }
                catch(Exception ex)
                {

                }

    Line service.AutodiscoverUrl(email, RedirectionUrlValidationCallback) gives Null reference error. Exception message is "Object reference not set to an instance of an object." Exception source is "Microsoft.Exchange.WebServices".

    StackTrace -:

    at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRequest.GetResponseStream(IEwsHttpWebResponse response) in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Autodiscover\\Requests\\AutodiscoverRequest.cs:line 466\r\n   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverRequest.InternalExecute() in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Autodiscover\\Requests\\AutodiscoverRequest.cs:line 115\r\n   at Microsoft.Exchange.WebServices.Autodiscover.GetUserSettingsRequest.Execute() in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Autodiscover\\Requests\\GetUserSettingsRequest.cs:line 95\r\n   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetUserSettings(List`1 smtpAddresses, List`1 settings, Nullable`1 requestedVersion, Uri& autodiscoverUrl) in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Autodiscover\\AutodiscoverService.cs:line 1064\r\n   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetSettings[TGetSettingsResponseCollection,TSettingName](List`1 identities, List`1 settings, Nullable`1 requestedVersion, GetSettingsMethod`2 getSettingsMethod, Func`1 getDomainMethod) in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Autodiscover\\AutodiscoverService.cs:line 973\r\n   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(List`1 smtpAddresses, List`1 settings) in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Autodiscover\\AutodiscoverService.cs:line 878\r\n   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.InternalGetSoapUserSettings(String smtpAddress, List`1 requestedSettings) in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Autodiscover\\AutodiscoverService.cs:line 827\r\n   at Microsoft.Exchange.WebServices.Autodiscover.AutodiscoverService.GetUserSettings(String userSmtpAddress, UserSettingName[] userSettingNames) in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Autodiscover\\AutodiscoverService.cs:line 1667\r\n   at Microsoft.Exchange.WebServices.Data.ExchangeService.GetAutodiscoverUrl(String emailAddress, ExchangeVersion requestedServerVersion, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Core\\ExchangeService.cs:line 4458\r\n   at Microsoft.Exchange.WebServices.Data.ExchangeService.AutodiscoverUrl(String emailAddress, AutodiscoverRedirectionUrlValidationCallback validateRedirectionUrlCallback) in \\\\REDMOND\\EXCHANGE\\BUILD\\E15\\15.00.0913.015\\SOURCES\\sources\\dev\\EwsManagedApi\\src\\EwsManagedApi\\Core\\ExchangeService.cs:line 4383\r\n

    Any help will be appreciated.
    Thanks
    Priyank

    Wednesday, July 4, 2018 7:16 AM

All replies

  • The EWS Managed API has been open source for a few years now see https://github.com/OfficeDev/ews-managed-api. There is no support for .NET core in the github release but people have created Ports of the code to varying success I would suggest you look at https://github.com/OfficeDev/ews-managed-api/issues/96. With the source code you should be able to debug the underlying problem and fix that yourself.

    Cheers
    Glen

    Wednesday, July 4, 2018 10:09 PM
  • Hi Glen,

       Thanks for quick response. I have already tried with library Microsoft.Exchange.WebServices.NETStandard               (https://www.nuget.org/packages/Microsoft.Exchange.WebServices.NETStandard/1.0.4) and was able to resolve the mentioned issue in .net core. But is this the recommended library for production use? As I am not sure which functionalities will not work.

    Thanks


    Thursday, July 5, 2018 4:39 AM
  • It's open source so there is no recommended library as such (eg it isn't a Microsoft release), personally i wouldn't use nuget for something like this. Fork,test and maintain your own copy of the library on Github and submit any bug fixes you find for issues back to author. In that way you have some control over what is going into your production code. 

    Cheers
    Glen

    Thursday, July 5, 2018 11:09 PM