Category
Describe the bug
In case a folder does not exist, all methods pnpContext.Web.GetFolder* throw the wrong error.
HttpResponseCode: 404
Code: System.IO.FileNotFoundException
Message: File not found.
ClientRequestId: ...
SPClientServiceRequestDuration: 19
X-SharePointHealthScore: 0
X-SP-SERVERSTATE: ReadOnly=0
PnP.Core.SharePointRestServiceException: SharePoint Rest service exception
at PnP.Core.Services.BatchClient.ExecuteSharePointRestInteractiveAsync(Batch batch)
at PnP.Core.Services.BatchClient.ExecuteSharePointRestBatchAsync(Batch batch)
at PnP.Core.Services.BatchClient.ExecuteBatch(Batch batch)
at PnP.Core.Model.BaseDataModel`1.BaseRetrieveAsync(ApiCall apiOverride, Func`2 fromJsonCasting, Action`1 postMappingJson, Expression`1[] expressions)
at PnP.Core.Model.SharePoint.Web.GetFolderByIdAsync(Guid folderId, Expression`1[] expressions)
...
Steps to reproduce
Just try pnpContext.Web.GetFolderByIdAsync(folderId) or any method for getting a folder by passing a parameter indicating a non-existent folder.
Expected behavior
Code is: FileNotFoundException and should be DirectoryNotFoundException
Message is: "File not found." and should be "Folder not found."
Environment details (development & target environment)
- SDK version: 1.15.0
- OS: Windows 11 Version 25H2
- SDK used in: ASP.NET Core Web API
- Framework: .NET 10
- Browser(s): Testing APIs with Postman
- Tooling: Visual Studio 2026
- Additional details:
Additional context
Thanks for your contribution! Sharing is caring.
Category
Describe the bug
In case a folder does not exist, all methods
pnpContext.Web.GetFolder*throw the wrong error.Steps to reproduce
Just try
pnpContext.Web.GetFolderByIdAsync(folderId)or any method for getting a folder by passing a parameter indicating a non-existent folder.Expected behavior
Code is:
FileNotFoundExceptionand should beDirectoryNotFoundExceptionMessage is: "File not found." and should be "Folder not found."
Environment details (development & target environment)
Additional context
Thanks for your contribution! Sharing is caring.