question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting Lists causes 'Instance Was deleted Error'

See original GitHub issue

In my solution I’m trying to read all SharePoint Online data of a tenant, and in order to improve performance and reduce the amount of objects in memory, I use separate threads for each SharePoint object. The PnPContext is created only once per URL, stored in a Map and re-used as needed.

When I try to read Lists from Web I sometimes get the following exception:

This model instance was deleted, you can't use it anymore

at PnP.Core.Model.TransientObject.CheckDeleted()
at PnP.Core.Model.TransientObject.GetValue[T](String propertyName)
at PnP.Core.Model.BaseDataModel`1.GetModelCollectionValue[T](String propertyName)
at PnP.Core.Model.SharePoint.Web.get_Lists()

Code I use for loading Lists:

var list = context.Web.Lists.GetById(new Guid("xxxxx")

Important: I have multiple threads running parallel that are probably using the same Context to load different Lists of the current Web.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
KoenZomerscommented, Nov 9, 2021

Ran into the same here with only two concurrent threads. Cloning the PnPContext for every call as Bert mentions above fixed it for me.

1reaction
jansenbecommented, Oct 14, 2021

@bajce : if you want to run work for the same IWeb in parallel via threads then cloning a context should fix things for you. https://pnp.github.io/pnpcore/using-the-sdk/basics-context.html#cloning-a-pnpcontext-for-the-same-web describes the details, but a default clone operation will not result in a server roundtrip. If you however optimized the initial load as described in my previous reply, then not all properties are copied over to the cloned context.

If this answers your questions, then please close the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

List instance deleted on retraction
The problem is that when I retract the solution or redeploy then the list instance is removed. This is going to cause an...
Read more >
List default view deleted in production
When a list view is deleted in any instance, it will generate a customer update XML record in the current update set.
Read more >
Why am I getting deleted instance passed to merge, when ...
This happens because you first delete the object (without committing) and then try to update it. ... To avoid the error you should...
Read more >
Error codes for the Amazon EC2 API - AWS Documentation
These errors are usually caused by an AWS server-side issue. ... This section lists the client error codes that all Amazon EC2 API...
Read more >
FIX: BizTalk Operators issue when you terminate service ...
When selecting multiple service instances in the Admin Console and then deleting them, you notice that not all of them get deleted and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found