Connect-PnPOnline -lose connection in case there is whitespaces in web url #1250
Comments
Can you try this without the -Web parameter? This parameter is only required if you want to connect to a different subweb without wanting to issue a new Connect-PnPOnline. So just use: Connect-PnPOnline -Url $url -UseWebLogin
$contentType = Get-PnPContentType -List "Documents" -Identity "your ct name" Optionally you can specify the If I execute the cmdlets as shown in your screenshot I receive a different error message, related to different origins of the object. As such that's an issue to that needs to be addressed. Nevertheless, having spaces in the URL should not be a problem (and I am also not able to reproduce that). |
Hi!
And thank you for helping.
I run
$url = "https://xxxx.sharepoint.com/sites/xxxx/Light Beer/"
Connect-PnPOnline $url -UseWebLogin
After that
$contentType = Get-PnPContentType -InSiteHierarchy -Identity "Document"
Returns
Get-PnPContentType : Object reference not set to an instance of an object.
At line:1 char:16
+ ... ontentType = Get-PnPContentType -InSiteHierarchy -Identity "Document"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Get-PnPContentType],
NullReferenceException
+ FullyQualifiedErrorId :
EXCEPTION,SharePointPnP.PowerShell.Commands.ContentTypes.GetContentType
Get-PnPContentType : Object reference not set to an instance of an object.
At line:1 char:16
+ ... ontentType = Get-PnPContentType -InSiteHierarchy -Identity "Document"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-PnPContentType],
NullReferenceException
+ FullyQualifiedErrorId :
System.NullReferenceException,SharePointPnP.PowerShell.Commands.ContentTypes.GetContentType
Actually if i run
$url = "https://xxxx.sharepoint.com/sites/xxxx/Light Beer/"
Connect-PnPOnline $url -UseWebLogin
Get-PnPContentType -InSiteHierarchy
i got
Get-PnPContentType : Object reference not set to an instance of an object.
At line:1 char:1
+ Get-PnPContentType -InSiteHierarchy
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Get-PnPContentType],
NullReferenceException
+ FullyQualifiedErrorId :
EXCEPTION,SharePointPnP.PowerShell.Commands.ContentTypes.GetContentType
Get-PnPContentType : Object reference not set to an instance of an object.
At line:1 char:1
+ Get-PnPContentType -InSiteHierarchy
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-PnPContentType],
NullReferenceException
+ FullyQualifiedErrorId :
System.NullReferenceException,SharePointPnP.PowerShell.Commands.ContentTypes.GetContentType
And with
$url = "https://xxxx.sharepoint.com/sites/xxxx/Light Beer/"
Connect-PnPOnline $url -UseWebLogin
Get-PnPListItem -List Documents
Get-PnPListItem : Object reference not set to an instance of an object.
At line:1 char:1
+ Get-PnPListItem -List Documents
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Get-PnPListItem],
NullReferenceException
+ FullyQualifiedErrorId :
EXCEPTION,SharePointPnP.PowerShell.Commands.Lists.GetListItem
Get-PnPListItem : Object reference not set to an instance of an object.
At line:1 char:1
+ Get-PnPListItem -List Documents
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-PnPListItem],
NullReferenceException
+ FullyQualifiedErrorId :
System.NullReferenceException,SharePointPnP.PowerShell.Commands.Lists.GetListItem
BR,
Timo
…On Tue, Dec 5, 2017 at 2:20 AM, Erwin van Hunen ***@***.***> wrote:
Can you try this without the -Web parameter? This parameter is only
required if you want to connect to a different subweb without wanting to
issue a new Connect-PnPOnline.
So just use:
Connect-PnPOnline -Url $url -UseWebLogin$contentType = Get-PnPContentType -List "Documents" -Identity "your ct name"
Optionally you can specify the -InSiteHierarchy parameter which will
include content types in the root web of the site collection.
If I execute the cmdlets as shown in your screenshot I receive a different
error message, related to different origins of the object. As such that's
an issue to that needs to be addressed. Nevertheless, having spaces in the
URL should not be a problem (and I am also not able to reproduce that).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1250 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AgeaYO8dUkeaj9RN-riKLdRPpOMagoarks5s9Iw9gaJpZM4Qu4Oy>
.
|
Something else I noticed with my workaround: Switching from one cmdlet to another requires me to reopen the connection. Example: The example above throws an Unauthenticated exception on the |
Passing the web + conn doesn't help me. `$url ="https..." $contentType = Get-PnPContentType -Web $web -Connection $conn -Identity "Document" Everything goes fine until running Get-PnpContentType second time. Then i got error. Maybe i should stop this and build console application using the OfficeDevPnP.Core like you did. |
@Huuhaa500 Is this still an issue? |
I have the same issue. I have installed via Install-Module from the gallery. Currently I have version "3.0.1808.1" installed. I can also confirm that the error only happens if the subsite has spaces in the URL |
I haven't debugged the cmdlets but I belive the error might be in the following code. I've also checked this theory with Get-PnPConnection and Get-PnPContext. The ClientContext.Url is URL decoded. So "SPOnlineConnection.CurrentConnection.Context.Url" is URL decoded but "SPOnlineConnection.CurrentConnection.Url" is URL encoded since that value is initialized with the AbsoluteUri value here, which get's URL encoded https://github.com/SharePoint/PnP-PowerShell/blob/25a81012962fa721ab1897e8820bbb602e4f4a59/Commands/Base/SPOnlineConnection.cs#L96 So the "SPOnlineConnection.CurrentConnection.Context.Url != SPOnlineConnection.CurrentConnection.Url" condition evaluates to true and will be called and the already URL encoded URL will be passed to the function. https://github.com/SharePoint/PnP-PowerShell/blob/25a81012962fa721ab1897e8820bbb602e4f4a59/Commands/Base/PnPWebCmdlet.cs#L66 |
@DanielHirschTpg good work, and feel free to submit a PR for fixing this before we get a chance to look at it further :) |
So i was able to debug this now. The issue only occures with using the web login. As suspected, the error lies in the following lines: When using web login, the "SPOnlineConnection.CurrentConnection.Context.Url" is URL decoded but without the web login it's URL encoded. Since "SPOnlineConnection.CurrentConnection.Url" is always URL encoded (because of using Uri.AbsoluteUri) the IF condition evaluates TRUE and the context will be set NULL in "SPOnlineConnection.CurrentConnection.RestoreCachedContext" because of the reencoding of the passed URL encoded URL. Generally we should compare URI instances instead of strings so we don't have this mess of double encoding or comparing encoded urls to the same unencoded one. Also here we should use Uris for comparisons |
@DanielHirschTpg care to submit a PR on this? |
@wobba I only applied a "band-aid" kinda fix by comparing URI instances at the relevant positions that caused problems. The proper way would be to change the code to have Uri properties where it was strings before and generally always work with URIs. I sadly don't have anymore time to spend on this issue and to improve the code. |
@DanielHirschTpg No problem, and we'll keep the issue open until someone have time to fix i :) |
I came across this same bug. This happens under WebLogin and with a URL having a space on it. |
any update on this issue This happens under WebLogin and with a URL having a space on it. |
@sachinwalunjb4 this issue is still open to be fixed, and we'll close it once done. |
We've been faced with that problem after we moved to ADFS on an SP 2016 Server. On that configuration Connect-PnPOnline runs with switch -UseAdfs only. But then that issue appears on sites having blank spaces in their url. Almost none of the PnP commands work. Is there any progress on that issue? |
I still face the same issue. My site URL contains a "%20" like "/sites/test-activity%20test" and PnP Powershell breaks the connection after some commands. |
@Huuhaa500 finally got around to this one and should be included in the next release. |
Reporting an Issue or Missing Feature
Make connect with
Connect-PnPOnline $url -UseWebLogin
where
$url = "https://timopertila.sharepoint.com/sites/wiki/Light%20Beer/"
You can make one operation, but after that connection is lost and you get exception.
Like:
$contentType = Get-PnPContentType -Web $web -List Documents -Identity "Timo Doc"
is fine, but after that running same (or any else operation) like
$contentType = Get-PnPContentType -Web $web -List Documents -Identity "Timo Doc"
gives you:
Get-PnPContentType : Object reference not set to an instance of an object.
At line:2 char:16
If i do same thing with site url having no whitespaces, then everything works fine.
Expected behavior
Excpected that i can run more than one command after establishing connection.
Actual behavior
Steps to reproduce behavior
can seen on screenshot above
Which version of the PnP-PowerShell Cmdlets are you using?
What is the version of the Cmdlet module you are running?
2.20.17..
How did you install the PnP-PowerShell Cmdlets?
The text was updated successfully, but these errors were encountered: