none
Assembly error for System.Management.Automation in .NET Framework 4.0, but not in .NET Framework 4.5 RRS feed

  • Question

  • I have a C# .NET Framework 2 application with the following configuration:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <startup>
        <supportedRuntime version="v4.0"/>
        <supportedRuntime version="v2.0.50727"/>
      </startup>
    </configuration>

    Using Assembly Binding Log Viewer (fuslogvw.exe) I get failures like this with .NET Framework 4.0:

    The operation failed.

    Bind result: hr = 0x80070002. The system cannot find the file specified.

    ...

    LOG: Start binding of native image System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35. WRN: No matching native image found.

    Using .NET Framework 2.0 and 4.5 the operation is successful.

    I tried: Adding in the .csproj file:

        <Reference Include="System.Management.Automation">

    Adding this entries in the registry: reg add hklm\software\microsoft.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1 reg add hklm\software\wow6432node\microsoft.netframework /v OnlyUseLatestCLR /t REG_DWORD /d 1

    Referencing C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll in the project.

    Adding

    <startup useLegacyV2RuntimeActivationPolicy="true"   in the application config.

    Any suggestions are appreciated.

    Thank you

    Friday, February 28, 2014 7:29 PM

Answers

  • Hi Dynamicmindset,

    System.Management.Automation.dll is installed by PowerShell into GAC (there is no copy outside of GAC, unlikely the NET Framework assemblies). NET 2 GAC has an Explorer extension, you need to use a command or PowerShell prompt to search it. NET 4 has a different GAC without an Explorer extension.

    If you install the Windows SDK a reference copy is placed in C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\v3.0.

    I would suggest first looking at your assembly that runs the scripts (i.e. where you reference PowerShell types like Runspace) with ildasm.exe or .NET Reflector to check exactly what System.Management.Automation.dll assembly you are referencing.

    If this reference is OK, then make use of the Assembly Binding Log Viewer (Fuslogvw.exe) to see where the .NET loader is trying to load System.Management.Automation.dll.

    Hope useful.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 3, 2014 5:13 AM
    Moderator
  • Check Fusion log's probing paths and make sure the file really exists on your machine and that the path is being probed by Fusion.

    BTW: only switch (for CLR testing purposes). You should never use in production as it affects all applications on the machine.

    -Karel

    Thursday, March 6, 2014 8:49 PM
    Moderator

All replies

  • Hi Dynamicmindset,

    System.Management.Automation.dll is installed by PowerShell into GAC (there is no copy outside of GAC, unlikely the NET Framework assemblies). NET 2 GAC has an Explorer extension, you need to use a command or PowerShell prompt to search it. NET 4 has a different GAC without an Explorer extension.

    If you install the Windows SDK a reference copy is placed in C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell\v3.0.

    I would suggest first looking at your assembly that runs the scripts (i.e. where you reference PowerShell types like Runspace) with ildasm.exe or .NET Reflector to check exactly what System.Management.Automation.dll assembly you are referencing.

    If this reference is OK, then make use of the Assembly Binding Log Viewer (Fuslogvw.exe) to see where the .NET loader is trying to load System.Management.Automation.dll.

    Hope useful.

    Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, March 3, 2014 5:13 AM
    Moderator
  • Check Fusion log's probing paths and make sure the file really exists on your machine and that the path is being probed by Fusion.

    BTW: only switch (for CLR testing purposes). You should never use in production as it affects all applications on the machine.

    -Karel

    Thursday, March 6, 2014 8:49 PM
    Moderator