-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Make ResourceManagerCache check for alternative resource paths #4139
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
Make ResourceManagerCache check for alternative resource paths #4139
Conversation
} | ||
else | ||
{ | ||
newBaseName = assembly.GetName().Name + resourcesSubstring + baseName; // e.g. "System.Management.Automation.resources.FileSystemProviderStrings" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not concatenate strings, use a StringBuilder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A single call to string.Concat
with 4 or fewer arguments could be better than using a StringBuilder
- the length of the string can be pre-calculated, so there would only be 1 allocation instead of multiple for the StringBuilder
, the array of characters in StringBuilder
, and the final string allocation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to string.Concat
</TableControl> | ||
</View> | ||
</ViewDefinitions> | ||
</Configuration> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the test should not look anything like something that is built-in - otherwise it might cause problems with other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added newline;
renamed the format file to indicate relation to tests;
these tests are run in separate PowerShell/Runspace instances, so there should be no conflict with other tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Today there is no conflict.
You should write the test so there can never be a conflict, even if the code is reused.
It's really simple to use a type name specific to this scenario, so I see no reason to not do as I've suggested.
$ps.Invoke() | ||
$sma = [appdomain]::CurrentDomain.GetAssemblies() | ? { if ($_.Location) {$_.Location.EndsWith("System.Management.Automation.dll")}} | ||
$smaLocation = $sma.Location | ||
$ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should be $true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do:
$_.Exception.Message | Should Match $smaLocation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this fails with
parsing 'C:\Users\GitHub\PowerShell\New\src\powershell-win-core\bin\Debug\netcoreapp2.0\win10-x64\publish\System.Management.Automation.dll' - Unrecognized escape sequence \\U.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MatchExactly fails as well.
$ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should be $true } | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
$ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should be $true } | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test where we lookup are string resource which does not exist and expect an MissingManifestResourceException
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this last test is for when resource is not found;
I've added check for FullyQualifiedErrorId
|
||
// FYI: for a non-existing resource defined by {assembly,baseName,resourceId} | ||
// MissingManifestResourceException is thrown only at the time when resource retrieval method such as ResourceManager.GetString or ResourceManager.GetObject is called, | ||
// Not when you instantiate a ResourceManager object. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems 'FYI' abbreviation should be removed or expanded.
Please reformat and even a width of lines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed.
// Not when you instantiate a ResourceManager object. | ||
try | ||
{ | ||
// try with original baseName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment as a single is obvious. So we should combining the comment with next one (move from line 194) to give a reader a full description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed.
@@ -0,0 +1,88 @@ | |||
<Configuration> | |||
<SelectionSets> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should put the file in 'asserts' subfolder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moved it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed.
|
||
|
||
Describe "Update-FormatData with resources in CustomControls" -Tags "CI" { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The file has multiple wrong indentations. See raw view https://raw.githubusercontent.com/anmenaga/PowerShell/fd95dd19b90e7cb5d0094f52503b59c59ec1ca5b/test/powershell/Modules/Microsoft.PowerShell.Utility/Update-FormatData.Tests.ps1
It seems you copy-paste tabs.
Could you please reformat by first commit and put new code in next commits?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed indentations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closed.
@adityapatwardhan Can you update your review? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No blocking issues
$null = $ps.AddScript("Update-FormatData -PrependPath $formatFilePath") | ||
$ps.Streams.Error.Clear() | ||
$ps.Invoke() | ||
$ps.HadErrors | Should be $false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would testing $ps.Streams.Error
give a more meaningful error if something went wrong in the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea; updated.
$null = $ps.AddScript("Update-FormatData -PrependPath $formatFilePath") | ||
$ps.Streams.Error.Clear() | ||
$ps.Invoke() | ||
$ps.HadErrors | Should be $false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
This PR is for 2 things:
From WindowsPS to PSCore resource paths have changed like this example:
WindowsPS:
FileSystemProviderStrings
PSCore:
System.Management.Automation.resources.FileSystemProviderStrings
... and some existing modules use 'WindowsPS' syntax in their "format.ps1xml" files; for example:
<Text AssemblyName="System.Management.Automation" BaseName="FileSystemProviderStrings" ResourceId="DirectoryDisplayGrouping"/>
So in these cases resource is not found and Import-Module/Update-FormatData returns error on PSCore.
The fix is to check for alternative resource path if original fails.
when a resource is not found, currently error message has wrong assembly path which was tried for loading the resource; for example:
... resource NonExistingResource in assembly C:\System.Management.Automation is not found.
This is rather confusing, specifically because assembly, containing the resource, can be located anywhere in the filesystem. The fix makes error message accurate:
... resource NonExistingResource in assembly C:\GitHub\PowerShell\src\powershell-win-core\bin\Debug\netcoreapp2.0\win10-x64\publish\System.Management.Automation.dll is not found.
Results on PSCore after the fix:

Results on PSCore before the fix:

Fix #3057