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

StackOverflow https://stackoverflow.com/questions/22102374

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:

*** Assembly Binder Log Entry  ***

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

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\myprog.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = WINDOWS\Administrator
LOG: DisplayName = System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = myprog.exe
Calling assembly : myprog, Version=20.0.17510.0, Culture=neutral, PublicKeyToken=null.
===
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 4.5 the operation is successful.

*** Assembly Binder Log Entry  (2/28/2014 @ 3:35:59 AM) ***

The operation was successful. Bind result: hr = 0x1. Incorrect function.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll Running under executable  C:\myprog.exe

--- A detailed error log follows. 

BEGIN : Native image bind.
END   : Incorrect function. (Exception from HRESULT: 0x00000001 (S_FALSE))


*** Assembly Binder Log Entry  (2/28/2014 @ 3:35:59 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\myprog.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = WINDOWS2\Administrator
LOG: DisplayName = System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = myprog.exe
Calling assembly : myprog, Version=20.0.17510.0, Culture=neutral, PublicKeyToken=null.
===
WRN: No matching native image found.


*** Assembly Binder Log Entry  (2/28/2014 @ 3:35:59 AM) ***

The operation was successful.
Bind result: hr = 0x0. The operation completed successfully.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework64\v4.0.30319\clr.dll
Running under executable  C:\myprog.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: User = WINDOWS2\Administrator
LOG: DisplayName = System.Management.Automation, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = myprog.exe
Calling assembly : myprog, Version=20.0.17510.0, Culture=neutral, PublicKeyToken=null.
===
WRN: No matching native image found.

I tried: Adding in the .csproj file.

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.

The strange thing is that this happens only with .NET Framework 4.0, 2.0 and 4.5 work.

Any suggestions are appreciated.

Thank you

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top