Skip to content
Closed
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 @@ -1415,9 +1415,7 @@ private static InitialSessionState CreateRestrictedForRemoteServer()
// Ensure that only PowerShell core formats are included in the restricted session.
IncludePowerShellCoreFormats(iss);

List<string> allowedTypes = new List<string>();
allowedTypes.Add("types.ps1xml");
allowedTypes.Add("typesV3.ps1xml");
List<string> allowedTypes = new List<string>() { "types.ps1xml" };
RemoveDisallowedEntries(
iss.Types,
allowedTypes,
Expand Down
10 changes: 5 additions & 5 deletions src/System.Management.Automation/engine/TypeTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3497,7 +3497,7 @@ public TypeTable(IEnumerable<string> typeFiles) : this(typeFiles, null, null)
}

/// <summary>
/// Load types.ps1xml, typesv3.ps1xml into the typetable.
/// Load types.ps1xml into the typetable.
/// </summary>
/// <exception cref="System.Security.SecurityException">
/// if caller doesn't have permission to read the PowerShell registry key
Expand All @@ -3515,16 +3515,14 @@ public static TypeTable LoadDefaultTypeFiles()
public static List<string> GetDefaultTypeFiles()
{
string typesFilePath = string.Empty;
string typesV3FilePath = string.Empty;

var psHome = Utils.DefaultPowerShellAppBase;
if (!string.IsNullOrEmpty(psHome))
{
typesFilePath = Path.Combine(psHome, "types.ps1xml");
typesV3FilePath = Path.Combine(psHome, "typesv3.ps1xml");
}

return new List<string>() { typesFilePath, typesV3FilePath };
return new List<string>() { typesFilePath };
}

/// <summary>
Expand Down Expand Up @@ -4493,7 +4491,9 @@ private bool ProcessIsBuiltIn(string filePath, ConcurrentBag<string> errors, out
}
else if (string.Equals(Path.Combine(psHome, "typesv3.ps1xml"), filePath, StringComparison.OrdinalIgnoreCase))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method is used by public TypeTable(IEnumerable<string> typeFiles). This is a public API and this change is potentially a breaking change if the typeFiles passed to that public constructor contains types3.ps1xml.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I added new commit to partially address the breaking.

After that I hope the breaking change will be in gray area.
The only scenario that we cannot fix is ​​to load 'typesv3.ps1xml' file without 'types.ps1xml'. This scenario is incredible.

{
ProcessTypeData(filePath, errors, TypesV3_Ps1Xml.Get());
// Workaround for a scenario where we get the 'typesv3.ps1xml' file name from public API.
// Now all types from 'typesv3.ps1xml' is in 'types.ps1xml' so we load 'types.ps1xml'.
ProcessTypeData("types.ps1xml", errors, Types_Ps1Xml.Get());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This means types.ps1xml will be processed twice, which could potentially cause issue that I don't know of (conflicts?).

@iSazonov Ilya (iSazonov) Oct 10, 2019 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

There GetOrAdd() is used. (But it will slow down)

I'd prefer a breaking change (gray area) and get rid typesv3.ps1xml (and then types.ps1xml as James asked). It looks like very rarely edge case.
GitHub search https://github.com/search?q=TypeTable+typesv3.ps1xml&type=Code
This is certainly not an exhaustive test, but it returned nothing excluding PowerShell code.
This open way to make the code faster (currently ~30% in runspace creation).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This open way to make the code faster (currently ~30% in runspace creation).

I don't think merging those two source files and eliminating types3.ps1xml would help much on the perf here.
I will let the committee review the proposed change.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I don't think merging those two source files and eliminating types3.ps1xml would help much on the perf here.

My thought is that it opens a way for future optimizations.

@daxian-dbw Dongbo Wang (daxian-dbw) Oct 10, 2019 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just took a look at the code in TypeTable.cs, and duplicate TypeData will result in error during processing:

if (membersCollection[member.name] != null && !isOverride)
{
AddError(errors, typeName, TypesXmlStrings.DuplicateMember, member.name);
return;
}

The GetOrAdd() is only to get the member collection of the type. Error will happen when processing members of the type.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I tried the compiled artifact and get the error. If PowerShell Committee conclusion will be to have a workaround I will discover another workaround but I hope we will agree to remove.

result = true;
}
else if (string.Equals(Path.Combine(psHome, "GetEvent.types.ps1xml"), filePath, StringComparison.OrdinalIgnoreCase))
Expand Down
119 changes: 0 additions & 119 deletions src/System.Management.Automation/engine/TypesV3_Ps1Xml.cs

This file was deleted.

77 changes: 77 additions & 0 deletions src/System.Management.Automation/engine/Types_Ps1Xml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2009,6 +2009,83 @@ public static IEnumerable<TypeData> Get()
""$($this.Major).$($this.Minor).$($this.Build)""+$suffix
")));
yield return td252;

var td253 = new TypeData(@"System.Security.Cryptography.X509Certificates.X509Certificate2", true);
td253.Members.Add("EnhancedKeyUsageList",
new ScriptPropertyData(@"EnhancedKeyUsageList", GetScriptBlock(@",(new-object Microsoft.Powershell.Commands.EnhancedKeyUsageProperty -argumentlist $this).EnhancedKeyUsageList;"), null));
td253.Members.Add("DnsNameList",
new ScriptPropertyData(@"DnsNameList", GetScriptBlock(@",(new-object Microsoft.Powershell.Commands.DnsNameProperty -argumentlist $this).DnsNameList;"), null));
td253.Members.Add("SendAsTrustedIssuer",
new ScriptPropertyData(@"SendAsTrustedIssuer", GetScriptBlock(@"[Microsoft.Powershell.Commands.SendAsTrustedIssuerProperty]::ReadSendAsTrustedIssuerProperty($this)"), GetScriptBlock(@"$sendAsTrustedIssuer = $args[0]
[Microsoft.Powershell.Commands.SendAsTrustedIssuerProperty]::WriteSendAsTrustedIssuerProperty($this,$this.PsPath,$sendAsTrustedIssuer)")));
yield return td253;

var td254 = new TypeData(@"System.Management.Automation.Remoting.PSSenderInfo", true);
td254.Members.Add("ConnectedUser",
new ScriptPropertyData(@"ConnectedUser", GetScriptBlock(@"$this.UserInfo.Identity.Name"), null));
td254.Members.Add("RunAsUser",
new ScriptPropertyData(@"RunAsUser", GetScriptBlock(@"if($null -ne $this.UserInfo.WindowsIdentity)
{
$this.UserInfo.WindowsIdentity.Name
}"), null));
yield return td254;

var td255 = new TypeData(@"System.Management.Automation.CompletionResult", true);
td255.SerializationDepth = 1;
yield return td255;

var td256 = new TypeData(@"Deserialized.System.Management.Automation.CompletionResult", true);
td256.TargetTypeForDeserialization = typeof(Microsoft.PowerShell.DeserializingTypeConverter);
yield return td256;

var td257 = new TypeData(@"System.Management.Automation.CommandCompletion", true);
td257.SerializationDepth = 1;
yield return td257;

var td258 = new TypeData(@"Deserialized.System.Management.Automation.CommandCompletion", true);
td258.TargetTypeForDeserialization = typeof(Microsoft.PowerShell.DeserializingTypeConverter);
yield return td258;

var td259 = new TypeData(@"Microsoft.PowerShell.Commands.ModuleSpecification", true);
td259.SerializationDepth = 1;
yield return td259;

var td260 = new TypeData(@"Deserialized.Microsoft.PowerShell.Commands.ModuleSpecification", true);
td260.TargetTypeForDeserialization = typeof(Microsoft.PowerShell.DeserializingTypeConverter);
yield return td260;

var td261 = new TypeData(@"System.Management.Automation.JobStateEventArgs", true);
td261.SerializationDepth = 2;
yield return td261;

var td262 = new TypeData(@"Deserialized.System.Management.Automation.JobStateEventArgs", true);
td262.TargetTypeForDeserialization = typeof(Microsoft.PowerShell.DeserializingTypeConverter);
yield return td262;

var td263 = new TypeData(@"System.Exception", true);
td263.SerializationDepth = 1;
yield return td263;

var td264 = new TypeData(@"System.Management.Automation.Remoting.PSSessionOption", true);
td264.SerializationDepth = 1;
yield return td264;

var td265 = new TypeData(@"Deserialized.System.Management.Automation.Remoting.PSSessionOption", true);
td265.TargetTypeForDeserialization = typeof(Microsoft.PowerShell.DeserializingTypeConverter);
yield return td265;

var td266 = new TypeData(@"System.Management.Automation.DebuggerStopEventArgs", true);
td266.Members.Add("SerializedInvocationInfo",
new CodePropertyData("SerializedInvocationInfo", GetMethodInfo(typeof(Microsoft.PowerShell.DeserializingTypeConverter), "GetInvocationInfo"), null) { IsHidden = true });
td266.SerializationMethod = "SpecificProperties";
td266.SerializationDepth = 2;
td266.PropertySerializationSet =
new PropertySetData(new[] { "Breakpoints", "ResumeAction", "SerializedInvocationInfo" }) { Name = "PropertySerializationSet" };
yield return td266;

var td267 = new TypeData(@"Deserialized.System.Management.Automation.DebuggerStopEventArgs", true);
td267.TargetTypeForDeserialization = typeof(Microsoft.PowerShell.DeserializingTypeConverter);
yield return td267;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,7 @@ internal static PSSnapInInfo ReadCoreEngineSnapIn()
ReadRegistryInfo(out assemblyVersion, out publicKeyToken, out culture, out architecture, out applicationBase, out psVersion);

// System.Management.Automation formats & types files
Collection<string> types = new Collection<string>(new string[] { "types.ps1xml", "typesv3.ps1xml" });
Collection<string> types = new Collection<string> { "types.ps1xml" };
Collection<string> formats = new Collection<string>(new string[]
{"Certificate.format.ps1xml","DotNetTypes.format.ps1xml","FileSystem.format.ps1xml",
"Help.format.ps1xml","HelpV3.format.ps1xml","PowerShellCore.format.ps1xml","PowerShellTrace.format.ps1xml",
Expand Down Expand Up @@ -1006,7 +1006,7 @@ internal static Collection<PSSnapInInfo> ReadEnginePSSnapIns()
{"Certificate.format.ps1xml","DotNetTypes.format.ps1xml","FileSystem.format.ps1xml",
"Help.format.ps1xml","HelpV3.format.ps1xml","PowerShellCore.format.ps1xml","PowerShellTrace.format.ps1xml",
"Registry.format.ps1xml"});
Collection<string> smaTypes = new Collection<string>(new string[] { "types.ps1xml", "typesv3.ps1xml" });
Collection<string> smaTypes = new Collection<string>() { "types.ps1xml" };

// create default mshsnapininfo objects..
Collection<PSSnapInInfo> engineMshSnapins = new Collection<PSSnapInInfo>();
Expand Down