Today I tried to load the Fields from a list using PnP PowerShell and CSOM.


$ctx = Get-PnPContext

$list = Get-PnPList -Web $web -Identity $listName


This quite quickly resulted in :

Exception calling “Load” with “1” argument(s): “The object is used in the context different from the one associated with the object.”
At line:1 char:1
+ $web.Context.Load($list.Fields)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : InvalidOperationException

Ok, maybe I need to use my $web.Context

$list = Get-PnPList -Web $web -Identity $listName


No, the same error still occurs.

Hmm, so the $list object has its own

$list = Get-PnPList -Web $web -Identity $listName


and now I can get to my $list.Fields.