Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exclude -Comobject parameter of New-Object cmdlet on unsupported platforms #4922

Merged
merged 5 commits into from
Sep 29, 2017

Conversation

iSazonov
Copy link
Collaborator

Fix #4897.

New-Object -Comobject is not supported on

  • Linux and MacOs - fix is remove the code.
  • Windows Core and IoT - fix is throw NotSupportedException exception.

First commit reformat test file.

else // Parameterset -Com
{
if (!Platform.IsWindowsDesktop)
{
Exception exc = new NotSupportedException(NewObjectStrings.ComObjectPlatformIsNotSupported);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COM works on NanoServer as well, as long as it has a workable COM component
PS: the COM support was enabled when powershell core was still NanoServer powershell.

Copy link
Collaborator Author

@iSazonov iSazonov Sep 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I based on current tests. 😕
So should we exclude the parameter only on Unix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The COM components we use in our tests are not available in NanoServer and IoT.
Yes, we should exclude the parameter only for Unix plats.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does "Shell.Application" work on NanoServer and IoT? can I use this in a test?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shell itself is not available on NanoServer and IoT. You can use it as a test, but just follow the existing tests in test\powershell\engine\COM.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why shouldn't we targeting our test to NanoServer and IoT?

@@ -465,7 +474,7 @@ private object CreateComObject()
return null;
}
}

#endif
#endregion Com
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the entire "com" region here should be under the #if !UNIX.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Copy link
Contributor

@PaulHigin PaulHigin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

if ($IsLinux -or $IsMacOs ) {
{ New-Object -ComObject "Shell.Application" } | ShouldBeErrorId "NamedParameterNotFound,Microsoft.PowerShell.Commands.NewObjectCommand"
} else {
{ New-Object -ComObject "Shell.Application" } | Should Not Throw
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will fail when running tests on NanoServer ... Maybe change it to check if New-Object has the parameter ComObject instead of creating the Shell.Application object?

$s = gcm New-Object
$s.Parameters.ContainsKey("ComObject")
True

@daxian-dbw daxian-dbw merged commit b07f24e into PowerShell:master Sep 29, 2017
@iSazonov iSazonov deleted the comobject-exclude branch September 29, 2017 03:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

-ComObject should not be exposed on systems where it is not supported
3 participants