microsoftgraph/aspnet-connect-sample

Resource not found issue

Closed this issue · 7 comments

I am able to get the Email Address form active directory. When i am trying send the mail to recipient it is throwing ServiceException.
Code: ResourceNotFound
Message: Resource could not be discovered.

Inner error null
Method:
await graphService.SendEmail(graphClient, message);

Do you know for sure that your user has an inbox? Sometimes with new tenants the user won't have an inbox right away, or not until after signing in to view email.

I'm having a similar problem. The login and Get email addresss functions work fine but when I try to send it out I'm getting a System.NullReferenceException at line 65 of GraphService.cs.
I'm completely new to C# and ASP.NET so I don't know where to start looking for a fix.

Here's the Stack Trace that came with the error:

[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft_Graph_SDK_ASPNET_Connect.Models.d__2.MoveNext() in C:\Users\BCCLeeuwarden\Desktop\aspnet-connect-sample-master\Microsoft Graph SDK ASPNET Connect\Microsoft Graph SDK ASPNET Connect\Models\GraphService.cs:65
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61
System.Runtime.CompilerServices.TaskAwaiter1.GetResult() +28 Microsoft_Graph_SDK_ASPNET_Connect.Controllers.<SendEmail>d__3.MoveNext() in C:\Users\BCCLeeuwarden\Desktop\aspnet-connect-sample-master\Microsoft Graph SDK ASPNET Connect\Microsoft Graph SDK ASPNET Connect\Controllers\HomeController.cs:62 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +99 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult) +97 System.Web.Mvc.Async.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult) +17 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult) +32 System.Web.Mvc.Async.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d() +50 System.Web.Mvc.Async.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f() +228 System.Web.Mvc.Async.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult) +10 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult) +34 System.Web.Mvc.Async.<>c__DisplayClass2b.<BeginInvokeAction>b__1c() +26 System.Web.Mvc.Async.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult) +100 System.Web.Mvc.Async.WrappedAsyncResult1.CallEndDelegate(IAsyncResult asyncResult) +10
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult) +27 System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState) +13 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult) +36 System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller) +12 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +22
System.Web.Mvc.Async.WrappedAsyncResultBase1.End() +49 System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult) +26 System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult) +10 System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState) +21 System.Web.Mvc.Async.WrappedAsyncVoid1.CallEndDelegate(IAsyncResult asyncResult) +29
System.Web.Mvc.Async.WrappedAsyncResultBase`1.End() +49
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +28
System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
System.Web.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult ar) +152
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +125

Does your account not have a profile photo? The code is supposed to fall back to the "test.jpg" file that lives in the "Content" directory if the user account doesn't have a profile photo. But it looks like that fallback logic isn't working in your case.

Could you put a breakpoint at line 65 and verify that the "photofile.Id" value is null?

I'm pretty sure I don't have a profile photo yeah. The breakpoint confirms the fallback isn't working. Both photoFile and sharingLink return a null.

I just ran the sample successfully with an account that doesn't have a profile picture, and I can't reproduce the issue. Could you put a break on line 47 of GraphService.cs and see what is happening when it tries to load the fallback image? Is it even reaching this line?

photoStream = System.IO.File.OpenRead(System.Web.Hosting.HostingEnvironment.MapPath("/Content/test.jpg"));

@CPGirish @DiamondHaze - James has left the company and I'm slowly taking ownership over his projects, etc. I just tried reproducing this error using the finished project in this repository, and I cannot. However, there are multiple ways you may have ended up getting to this code, and it might be that the method you used has bad instructions or broken code. Can you help me by clarifying which path you went down?

Did you:

  • Download or clone this repository directly from GitHub and use the [./Microsoft Graph SDK ASPNET Connect/Microsoft Graph SDK ASPNET Connect.sln]([./Microsoft Graph SDK ASPNET Connect/Microsoft Graph SDK ASPNET Connect.sln] solution?
  • Get here from https://developer.microsoft.com/graph/docs/concepts/aspnetmvc, and use the [./Microsoft Graph SDK ASPNET Connect/Microsoft Graph SDK ASPNET Connect.sln]([./starter-project/Microsoft Graph SDK ASPNET Connect.sln] solution?
  • Download a preconfigured ZIP file from https://developer.microsoft.com/graph/quick-start?

Closing this issue for now. Please reopen if you are still having problems