Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,8 @@ internal static string SingleQuote(string str)
/// <returns>The host window, if it is present or null if it is not.</returns>
internal static Window GetHostWindow(PSCmdlet cmdlet)
{
PSPropertyInfo windowProperty = cmdlet.Host.PrivateData.Properties["Window"];
// The value of 'PrivateData' property may be null for the default host or a custom host.
PSPropertyInfo windowProperty = cmdlet.Host.PrivateData?.Properties["Window"];
if (windowProperty == null)
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
To update these Help topics, start PowerShell by using the "Run as Administrator" command, and try running Update-Help again.</value>
</data>
<data name="GraphicalHostAssemblyIsNotFound" xml:space="preserve">
<value>To use the {0}, install Windows PowerShell ISE by using Server Manager, and then restart this application. ({1})</value>
<value>To use the {0}, make sure your application uses 'Microsoft.NET.Sdk.WindowsDesktop' as the project SDK and the corresponding assembly 'Microsoft.PowerShell.GraphicalHost' is available. ({1})</value>
</data>
<data name="RemotingNotSupportedForFeature" xml:space="preserve">
<value>{0} does not work in a remote session.</value>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private GraphicalHostReflectionWrapper()
/// <exception cref="RuntimeException">When it was not possible to load Microsoft.PowerShell.GraphicalHost.dlly.</exception>
internal static GraphicalHostReflectionWrapper GetGraphicalHostReflectionWrapper(PSCmdlet parentCmdlet, string graphicalHostHelperTypeName)
{
return GraphicalHostReflectionWrapper.GetGraphicalHostReflectionWrapper(parentCmdlet, graphicalHostHelperTypeName, parentCmdlet.CommandInfo.Name);
return GetGraphicalHostReflectionWrapper(parentCmdlet, graphicalHostHelperTypeName, parentCmdlet.CommandInfo.Name);
}

/// <summary>
Expand All @@ -73,9 +73,9 @@ internal static GraphicalHostReflectionWrapper GetGraphicalHostReflectionWrapper
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Assembly.Load has been found to throw unadvertised exceptions")]
internal static GraphicalHostReflectionWrapper GetGraphicalHostReflectionWrapper(PSCmdlet parentCmdlet, string graphicalHostHelperTypeName, string featureName)
{
GraphicalHostReflectionWrapper returnValue = new GraphicalHostReflectionWrapper();
GraphicalHostReflectionWrapper returnValue = new();

if (GraphicalHostReflectionWrapper.IsInputFromRemoting(parentCmdlet))
if (IsInputFromRemoting(parentCmdlet))
{
ErrorRecord error = new ErrorRecord(
new NotSupportedException(StringUtil.Format(HelpErrors.RemotingNotSupportedForFeature, featureName)),
Expand All @@ -87,9 +87,10 @@ internal static GraphicalHostReflectionWrapper GetGraphicalHostReflectionWrapper
}

// Prepare the full assembly name.
AssemblyName graphicalHostAssemblyName = new AssemblyName();
AssemblyName smaAssemblyName = typeof(PSObject).Assembly.GetName();
AssemblyName graphicalHostAssemblyName = new();
graphicalHostAssemblyName.Name = "Microsoft.PowerShell.GraphicalHost";
graphicalHostAssemblyName.Version = new Version(3, 0, 0, 0);
graphicalHostAssemblyName.Version = smaAssemblyName.Version;
graphicalHostAssemblyName.CultureInfo = new CultureInfo(string.Empty); // Neutral culture
graphicalHostAssemblyName.SetPublicKeyToken(new byte[] { 0x31, 0xbf, 0x38, 0x56, 0xad, 0x36, 0x4e, 0x35 });

Expand Down Expand Up @@ -124,7 +125,7 @@ internal static GraphicalHostReflectionWrapper GetGraphicalHostReflectionWrapper

returnValue._graphicalHostHelperType = returnValue._graphicalHostAssembly.GetType(graphicalHostHelperTypeName);

Diagnostics.Assert(returnValue._graphicalHostHelperType != null, "the type exists in Microsoft.PowerShell.GraphicalHost");
Diagnostics.Assert(returnValue._graphicalHostHelperType != null, "the type should exist in Microsoft.PowerShell.GraphicalHost");
ConstructorInfo constructor = returnValue._graphicalHostHelperType.GetConstructor(
BindingFlags.NonPublic | BindingFlags.Instance,
null,
Expand Down
Loading