FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Make ResourceManagerCache check for alternative resource paths by anmenaga · Pull Request #4139 · PowerShell/PowerShell · GitHub

Make ResourceManagerCache check for alternative resource paths - #4139

Merged
Travis Plunk (TravisEz13) merged 6 commits into
PowerShell:masterfrom
anmenaga:ResourceManagerCachePatch
Aug 4, 2017
Merged

Make ResourceManagerCache check for alternative resource paths#4139
Travis Plunk (TravisEz13) merged 6 commits into
PowerShell:masterfrom
anmenaga:ResourceManagerCachePatch

Conversation

Copy link
Copy Markdown

This PR is for 2 things:

  1. 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.

  2. 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

}
else
{
newBaseName = assembly.GetName().Name + resourcesSubstring + baseName; // e.g. "System.Management.Automation.resources.FileSystemProviderStrings"

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Do not concatenate strings, use a StringBuilder.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated to string.Concat

</TableControl>
</View>
</ViewDefinitions>
</Configuration> No newline at end of file

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Missing newline

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think the test should not look anything like something that is built-in - otherwise it might cause problems with other tests.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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 }

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you do:

$_.Exception.Message | Should Match $smaLocation

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

MatchExactly fails as well.

$ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should be $true }
}
}
} No newline at end of file

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Missing newline

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

updated

$ps.Streams.Error | %{ $_.Exception.Message.Contains($smaLocation) | Should be $true }
}
}
} No newline at end of file

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can we add a test where we lookup are string resource which does not exist and expect an MissingManifestResourceException

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It seems 'FYI' abbreviation should be removed or expanded.
Please reformat and even a width of lines.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Closed.

// Not when you instantiate a ResourceManager object.
try
{
// try with original baseName

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Updated.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Closed.

@@ -0,0 +1,88 @@
<Configuration>
<SelectionSets>

Ilya (iSazonov) Jul 15, 2017
edited
Loading

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We should put the file in 'asserts' subfolder.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

moved it.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Closed.



Describe "Update-FormatData with resources in CustomControls" -Tags "CI" {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

fixed indentations.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Closed.

Copy link
Copy Markdown
Member

Aditya Patwardhan (@adityapatwardhan) Can you update your review?

Travis Plunk (TravisEz13) left a comment

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No blocking issues

$null = $ps.AddScript("Update-FormatData -PrependPath $formatFilePath")
$ps.Streams.Error.Clear()
$ps.Invoke()
$ps.HadErrors | Should be $false

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Would testing $ps.Streams.Error give a more meaningful error if something went wrong in the test?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

good idea; updated.

$null = $ps.AddScript("Update-FormatData -PrependPath $formatFilePath")
$ps.Streams.Error.Clear()
$ps.Invoke()
$ps.HadErrors | Should be $false

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

See previous

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

updated.

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.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM

Travis Plunk (TravisEz13) changed the title Making ResourceManagerCache check for alternative resource paths Make ResourceManagerCache check for alternative resource paths Aug 4, 2017
Travis Plunk (TravisEz13) merged commit 99236b1 into PowerShell:master Aug 4, 2017
Andrew (anmenaga) deleted the ResourceManagerCachePatch branch October 31, 2018 21:20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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.

Errors occurred while loading the format data file

6 participants


Back | FazBrowse Home | New Git URL