SPOTenantSettings: Error on Set-TargetResource
Description of the issue
@FabienTschanz Another one that was working just a couple a weeks ago with previous M365DSC release, I even have changed my code to process it first before any of the other SPO resources so that it doesn't barf on module order issues but now it fails with the below. I'm using your patch from #6686 but that only adds parameters, so it's not causing this issue.
##[error]Deploy execution failed ❌: PowerShell DSC resource MSFT_SPOTenantSettings failed to execute Set-TargetResource functionality with error message: Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan1<Byte>)'. ##[error]PowerShell DSC resource MSFT_SPOTenantSettings failed to execute Set-TargetResource functionality with error message: Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan1
Microsoft 365 DSC Version
1.25.1112.1
Which workloads are affected
SharePoint Online
The DSC configuration
SPOTenantSettings "SPOTenantSettings"
{
ApplicationId = $SPOApplicationId;
ApplyAppEnforcedRestrictionsToAdHocRecipients = $True;
CertificateThumbprint = $SPOCertThumbprint;
CommentsOnSitePagesDisabled = $False;
EnableAzureADB2BIntegration = $False;
Ensure = "Present";
ExemptNativeUsersFromTenantLevelRestricedAccessControl = $False;
FilePickerExternalImageSearchEnabled = $True;
HideDefaultThemes = $False;
IsSingleInstance = "Yes";
LegacyAuthProtocolsEnabled = $False;
MarkNewFilesSensitiveByDefault = "AllowExternalSharing";
MaxCompatibilityLevel = 15;
MinCompatibilityLevel = 15;
NotificationsInSharePointEnabled = $True;
OfficeClientADALDisabled = $False;
OwnerAnonymousNotification = $True;
PublicCdnAllowedFileTypes = "CSS,EOT,GIF,ICO,JPEG,JPG,JS,MAP,PNG,SVG,TTF,WOFF";
PublicCdnEnabled = $False;
SearchResolveExactEmailOrUPN = $False;
SignInAccelerationDomain = "";
SocialBarOnSitePagesDisabled = $False;
TenantDefaultTimezone = "(UTC-08:00) Pacific Time (US and Canada)";
TenantId = $OrganizationName;
UseFindPeopleInPeoplePicker = $False;
UsePersistentCookiesForExplorerView = $False;
}
Verbose logs showing the problem
##[error]Deploy execution failed ❌: PowerShell DSC resource MSFT_SPOTenantSettings failed to execute Set-TargetResource functionality with error message: Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1<Byte>)'.
##[error]PowerShell DSC resource MSFT_SPOTenantSettings failed to execute Set-TargetResource functionality with error message: Method not found: 'Int32 System.Text.Encodings.Web.TextEncoder.FindFirstCharacterToEncodeUtf8(System.ReadOnlySpan`1<Byte>)'.
##[error]PowerShell exited with code '1'.
Environment Information + PowerShell Version
Win11/PS5.1
It fails just after "Updating properties via REST PATCH call." which means it fails here on line 683
https://github.com/microsoft/Microsoft365DSC/blob/9b70c9980d4e68c0c11c0c19d554ac5a90ee6105/Modules/Microsoft365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1#L683
Just checked my logs from Oct 31 where it was "working", I can see that it went into the catch block because it displayed the text on line 691, not sure why but at least the deployment wasn't stopped because of the issue I reported above.
https://github.com/microsoft/Microsoft365DSC/blob/9b70c9980d4e68c0c11c0c19d554ac5a90ee6105/Modules/Microsoft365DSC/DSCResources/MSFT_SPOTenantSettings/MSFT_SPOTenantSettings.psm1#L691
Very very strange. I don't have any clue why, the parameters surely can't be the issue. And there weren't any updates to module loading or anything in that direction too, so I'm confused.
Was there a change in the .NET used on that machine and/or the PS Version ?
From the error message, seeing ReadOnlySpan
This is running on Azure DevOps through MSHosted agents
Just analyzed this. It is because there is an assembly conflict of the System.Text.Encodings.Web dll file of PnP.PowerShell as well as Mirosoft.Graph.Authentication. Now that we chose to always import the Microsoft.Graph.Authentication module before PnP.Powershell, it will always load the "incorrect" assembly, thus triggering the issue. Not sure how to fix this.
I tried to fix it with loading the assembly specifically during module startup, but that failed. PowerShell will load the newer version from the Microsoft.Graph.Authentication module despite already having one. Then, all commands are directed to the newer version. It is also impossible to remove a loaded assembly from PowerShell, making it even more difficult.
I fear the only solution here is to upgrade to PowerShell 7, where the module can hopefully be properly separated using the Assembly Load Context. I can try and see if this is possible using our internal compatibility layer for WinPS <-> PS7.
The module has an explicit condition to be loaded under PowerShell 7:
The PnP.PowerShell module, which is currently being used by the SharePoint Online and OneDrive for Business workloads, needs to be loaded using Windows PowerShell. In PowerShell 7+, this is done by running the Import-Module cmdlet using the -UseWindowsPowerShell switch, and requires the modules to be located under
C:\Program Files\WindowsPowerShell. In order for Microsoft365DSC to work for SharePoint Online and OneDrive for Business with PowerShell 7, you need to make sure that the PnP.PowerShell module is located underC:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell.
https://github.com/microsoft/MSCloudLoginAssistant/blob/ba4f7525e98a59b67469187301dd21c8a2f49528/Modules/MSCloudLoginAssistant/Workloads/PnP.ps1#L42
Running it in DevOps using pwsh results in the same error sadly.
Pipelines running an older DSC versions are not affected by this issue but almost every version since around September brought different issues and fixes with it for us which makes it very annoying not being able to update them. I guess we will have to handle SPOTenantSettings separate meanwhile...
This big is pretty annoying as SPOTenantSettings is used for a wide variety of non-related global settings. I just made a test with 1.26.128.1 and changing a single setting such as MarkNewFilesAsSensitiveByDefault from AllowExternalSharing to BlockExternalSharing ends up with an error. Could we mayne create separate resources? After all, SPOAccessControlSettings already exists whereas it taps into one oft same underlying cmdlet.
Whatever we do, without updating the module version, it won't work. I also tested it with our WinPS <-> PS7 compatibility layer, and I was able to make the connection to PnP work, but updating the resource still fails with an error because the Invoke-PnPSPRestMethod somehow does not work when running in the compatibility layer. We need to update the PnP.PowerShell module to probably 3.1.0 and require PowerShell Core to be installed on the machine. This is a breaking change (as would be to split up the resource).
At the moment PnP.PowerShell 3.1.0 is the latest version, but it doesn't work with Microsoft Graph modules loaded concurrently. I developed a way to use a separate workload that only runs in PowerShell 7 with the new module, so we could start migrating them to PowerShell 7 and make it work again. But first we have to wait for the new release of PnP.Powershell. No idea when that's going to be, apparently they cannot release at the moment due to certificate issues... See https://github.com/pnp/powershell/issues/3637
Any Updates on this issue so far? Got the same error with Version 1.26.603.1 in PowerShell 7
Unfortunately no. We're starting our work to update the PnP.PowerShell version for the next breaking change release in October. Until then, that error will most likely persist (sadly).
This will definitely be fixed with the October 2026 release. We updated the PnP.PowerShell dependency and were successful in testing it. Until then, it's waiting time sadly. I wish we had better news, but that's unfortunately it. I'll close it because we have it lined up.