OfficeDev / ews-managed-api

Other
583 stars 317 forks source link

System.NullReferenceException: Object reference not set to an instance of an object in AutodiscoverUrl #258

Open TheMixy opened 3 years ago

TheMixy commented 3 years ago

Following this example from Microsoft: https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/get-started-with-ews-managed-api-client-applications I have put together the following code to send an email (*):

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1); service.UseDefaultCredentials = true; service.TraceEnabled = true; service.TraceFlags = TraceFlags.All; service.AutodiscoverUrl("name.surname@mydomain.com", RedirectionUrlValidationCallback); EmailMessage email = new EmailMessage(service); email.ToRecipients.Add("recepient@mydomain.com"); email.Subject = "HelloWorld"; email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed API"); email.Send();

In service.AutodiscoverUrl I get a System.NullReferenceException: Object reference not set to an instance of an object.

Can anyone help us with the solution to resolve this issue?

* From our intranet web app (Asp.net core 3) and an on premises MS Exchange Server 2016 (part of our domain).

ntziolis commented 3 years ago

I'm seeing the same error. Did you find a solution for this?

sleepEarly7z commented 3 years ago

Hi, I have the same error here. Didn't get a solution anywhere.

I changed Exchange2013_SP1 to Exchange2007_SP1, it passed all the way down to email.Send(). email.Send() will throw the same NullReferenceException, but the email was successfully sent.

Please let me know if there's a solution.

ruggedjungleboy commented 2 years ago

I'm also still getting the same intermittent error on: FindItems(WellKnownFolderName.Inbox, searchFilter, view); and on email.Send().

The only difference is that FindITems fail and email.send() throws the error but the email was sent successfully?!

Please let me know if there an update on this.

MichelZ commented 2 years ago

You might want to read up on this: https://github.com/OfficeDev/ews-managed-api#support-statement

Support statement

Starting July 19th 2018, Exchange Web Services (EWS) will no longer receive feature updates. While the service will continue to receive security updates and certain non-security updates, product design and features will remain unchanged. This change also applies to the EWS SDKs for Java and .NET. More information here: https://developer.microsoft.com/en-us/graph/blogs/upcoming-changes-to-exchange-web-services-ews-api-for-office-365/

There will be no more development here.

markfilan commented 2 years ago

An Object is an instance of a Class , it is stored some where in memory. A reference is what is used to describe the pointer to the memory location where the Object resides. The message "object reference not set to an instance of an object" means that you are referring to an object the does not exist or was deleted or cleaned up. It's usually better to avoid a NullReferenceException than to handle it after it occurs. To prevent the error, objects that could be null should be tested before being used.

if (mClass != null)
{
  // Go ahead and use mClass
  mClass.property = ...
}
else
{
  // Attempting to use mClass here will result in NullReferenceException
}