Skip to content

bug: Could not load type 'System.Diagnostics.PerformanceCounter' #4295

Closed

Description

@mi-hol

Steps to reproduce

the script error.ps1 is attached.

  1. download WinSCP .Net assembly from https://winscp.net/download/WinSCP-5.9.6-Automation.zip
  2. unzip in a directory named C:\PS_B4)
    Note:
    in case a different directory name is choosen, script code below needs to be adapted before running it!
    $WinSCPnet_dll = ("C:\PS_B4\WinSCPnet.dll")
  3. copy attached script: error.ps1 inthe the same directory
  4. run powershell.exe
    .\error.ps1

Expected behavior

no error

and text:
script: ended successfully

Actual behavior

error gets

thrown:

Exception calling ".ctor" with "0" argument(s): "Could not load type 'System.Diagnostics.PerformanceCounter' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'."

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.0.0-beta
PSEdition                      Core
GitCommitId                    v6.0.0-beta.4
OS                             Microsoft Windows 10.0.14393
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Question
    on Jul 19, 2017
  2. iSazonov commented on Jul 19, 2017

    @iSazonov
    Collaborator

    mi-hol Thanks for your report! Please add a sample script to repo the error.

  3. changed the title [-]bug: Could not load type 'System.Diagnostics.PerformanceCounter[/-] [+]bug: Could not load type 'System.Diagnostics.PerformanceCounter'[/+] on Jul 19, 2017
  4. mi-hol commented on Jul 19, 2017

    @mi-hol
    Author

    Ilya (@iSazonov) error.ps1.txt is now available to repo bug

  5. iSazonov commented on Jul 20, 2017

    @iSazonov
    Collaborator

    mi-hol Thanks!
    I tried WinSCP module https://github.com/dotps1/WinSCP - it use the same dll and loads well. I manually load the dll from the module - loads well. I download WinSCP-5.9.6-Automation.zip and mannually load the dll from the package - loads well.

    Calling a WinSCP cmdlet raise an exception:

    Exception             : System.Management.Automation.MethodInvocationException:
                             Exception calling ".ctor" with "0" argument(s):
                            "Could not load type
                            'System.Diagnostics.PerformanceCounter' from assembly
                            'System, Version=4.0.0.0, Culture=neutral,
                            PublicKeyToken=b77a5c561934e089'." --->
                            System.TypeLoadException: Could not load type
                            'System.Diagnostics.PerformanceCounter' from assembly
                            'System, Version=4.0.0.0, Culture=neutral,
                            PublicKeyToken=b77a5c561934e089'.
                               at WinSCP.Logger..ctor()
                               at WinSCP.Session..ctor()
                               --- End of inner exception stack trace ---
                               at System.Management.Automation.DotNetAdapter.Auxili
                            aryConstructorInvoke(MethodInformation
                            methodInformation, Object[] arguments, Object[]
                            originalArguments) in C:\Users\sie\Documents\GitHub\iSa
                            zonov\PowerShell\src\System.Management.Automation\engin
                            e\CoreAdapter.cs:line 3776
                               at System.Management.Automation.DotNetAdapter.Invoke
                            ResolvedConstructor(MethodInformation bestMethod,
                            Object[] newArguments, Object[] arguments) in C:\Users\
                            sie\Documents\GitHub\iSazonov\PowerShell\src\System.Man
                            agement.Automation\engine\CoreAdapter.cs:line 3940
                               at System.Management.Automation.DotNetAdapter.Constr
                            uctorInvokeDotNet(Type type, ConstructorInfo[]
                            constructors, Object[] arguments) in C:\Users\sie\Docum
                            ents\GitHub\iSazonov\PowerShell\src\System.Management.A
                            utomation\engine\CoreAdapter.cs:line 3930
                               at Microsoft.PowerShell.Commands.NewObjectCommand.Ca
                            llConstructor(Type type, ConstructorInfo[]
                            constructors, Object[] args) in C:\Users\sie\Documents\
                            GitHub\iSazonov\PowerShell\src\Microsoft.PowerShell.Com
                            mands.Utility\commands\utility\new-object.cs:line 71
    TargetObject          :
    CategoryInfo          : InvalidOperation: (:) [New-Object],
                            MethodInvocationException
    FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell.C
                            ommands.NewObjectCommand
    ErrorDetails          :
    InvocationInfo        : System.Management.Automation.InvocationInfo
    ScriptStackTrace      : at New-WinSCPSession, C:\Program Files\WindowsPowerShel
                            l\Modules\winscp\Public\New-WinSCPSession.ps1: line 128
                            at <ScriptBlock>, <No file>: line 1
    PipelineIterationInfo : {}
    
  6. mi-hol commented on Jul 20, 2017

    @mi-hol
    Author

    Ilya (@iSazonov) do the comments mean that you can't reproduce the error using my error.ps1 script?

  7. iSazonov commented on Jul 20, 2017

    @iSazonov
    Collaborator

    mi-hol I edited my message.

    It seems CoreFX don't implement System.Diagnostics.PerformanceCounter
    See https://github.com/dotnet/corefx/issues/3906
    and dotnet/corefx#17898 - "Only refs adjusted!"

    /cc Dongbo Wang (@daxian-dbw) Is it problem for PowerShell Core RTM?

  8. mi-hol commented on Jul 20, 2017

    @mi-hol
    Author

    Also #4272 & #4303 seem related to the same issue.
    From my view PerformanceCounter is frequently used and all metrics are defined in
    PowerShell/src/Microsoft.PowerShell.Commands.Diagnostics/CoreCLR/Stubs.cs
    i.e. to calculate

    ' /// A difference timer that shows the total time between when the component
    /// or process started and the time when this value is calculated.
    ///
    ElapsedTime = 807666944,'

  9. daxian-dbw commented on Jul 20, 2017

    @daxian-dbw
    Member

    https://github.com/dotnet/corefx/issues/3906 is labelled with Future milestone, so it won't be available in .NET Core 2.0.
    mi-hol please feel free to leave comments in that corefx issue, so as to let them know the user demands.

  10. added
    Resolution-External
    on Jul 20, 2017
  11. iSazonov commented on Jul 20, 2017

    @iSazonov
    Collaborator

    I wonder what is plans for our counter cmdlets? Should we make a workaround in the repo until we have CoreFX implementations? Have we a tracking Issue?

    /cc Travis Plunk (@TravisEz13)

  12. TravisEz13 commented on Jul 20, 2017

    @TravisEz13
    Member

    #4306 is tracking the lack of counter CmdLets.
    I'm not aware of a workaround.

  13. mi-hol commented on Jul 20, 2017

    @mi-hol
    Author

    Dongbo Wang (@daxian-dbw) in light of Joey Aiello's public community request to 'tell us what does and doesn’t work for you on github' I'm a bit puzzled by the unexpected close of a confirmed incompatibility.
    We have been told numerous times that user feedback counts, now #4306 doesn't mention the error message a user will receive due to this incompatibly, hence I wonder how user feedback for this specific issue will be properly gathered?

  14. daxian-dbw commented on Jul 20, 2017

    @daxian-dbw
    Member

    mi-hol We do welcome feedbacks and I appreciate you brought up this issue.
    This issue was closed because the problem was understood and the resolution is out of the scope of powershell. The API/assembly it depends on is not available in .NET Core 2.0 and netstandard2.0, and thus nothing can be done on the powershell side unless dotnet/corefx#3906 is fixed.

  15. daxian-dbw commented on Jul 20, 2017

    @daxian-dbw
    Member

    mi-hol I edited your comment related to this issue in #4062 to add the root cause of this issue. That will help get all information we need in one place. See #4062 (comment)

  16. mi-hol commented on Jul 20, 2017

    @mi-hol
    Author

    Dongbo Wang (@daxian-dbw) Thanks! Hopefully the effort I put into opening & reproducing this bug is not wasted.

  17. daxian-dbw commented on Jul 21, 2017

    @daxian-dbw
    Member

    mi-hol Your effort is truly appreciated. When reviewing comments reported in #4062, people can easily get here via the link to learn more information about the issue.

    Thanks for bringing up your concern about this issue being closed. I should have better explained the "why" when closing it. Lesson learned :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-QuestionResolution-External

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions