我有一个C#.NET Framework 2应用程序,具有以下配置:

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

使用程序集绑定日志查看器(fuslogvw.exe)我在.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.

使用.NET Framework 4.5,操作成功 .

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

我试过:添加.csproj文件 .

在注册表中添加以下条目: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

在项目中引用C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ WindowsPowerShell \ v1.0 \ System.Management.Automation.dll .

添加

<startup useLegacyV2RuntimeActivationPolicy="true">

在应用程序配置中 .

奇怪的是,这只发生在.NET Framework 4.0,2.0和4.5的工作中 .

任何建议表示赞赏 .

谢谢