Make ResourceManagerCache check for alternative resource paths#4139
Make ResourceManagerCache check for alternative resource paths#4139TravisEz13 merged 6 commits intoPowerShell:masterfrom
Conversation
| } | ||
| else | ||
| { | ||
| newBaseName = assembly.GetName().Name + resourcesSubstring + baseName; // e.g. "System.Management.Automation.resources.FileSystemProviderStrings" |
There was a problem hiding this comment.
Do not concatenate strings, use a StringBuilder.
There was a problem hiding this comment.
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.
| </TableControl> | ||
| </View> | ||
| </ViewDefinitions> | ||
| </Configuration> No newline at end of file |
There was a problem hiding this comment.
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.
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.
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.
Can you do:
$_.Exception.Message | Should Match $smaLocationThere was a problem hiding this comment.
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.
| $ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should be $true } | ||
| } | ||
| } | ||
| } No newline at end of file |
| $ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should be $true } | ||
| } | ||
| } | ||
| } No newline at end of file |
There was a problem hiding this comment.
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.
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.
It seems 'FYI' abbreviation should be removed or expanded.
Please reformat and even a width of lines.
| // Not when you instantiate a ResourceManager object. | ||
| try | ||
| { | ||
| // try with original baseName |
There was a problem hiding this comment.
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.
| @@ -0,0 +1,88 @@ | |||
| <Configuration> | |||
| <SelectionSets> | |||
There was a problem hiding this comment.
We should put the file in 'asserts' subfolder.
|
|
||
|
|
||
| Describe "Update-FormatData with resources in CustomControls" -Tags "CI" { | ||
|
|
There was a problem hiding this comment.
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?
|
@adityapatwardhan Can you update your review? |
| $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.
Would testing $ps.Streams.Error give a more meaningful error if something went wrong in the test?
| $null = $ps.AddScript("Update-FormatData -PrependPath $formatFilePath") | ||
| $ps.Streams.Error.Clear() | ||
| $ps.Invoke() | ||
| $ps.HadErrors | Should be $false |
This PR is for 2 things:
From WindowsPS to PSCore resource paths have changed like this example:
WindowsPS:
FileSystemProviderStringsPSCore:
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