代码之家  ›  专栏  ›  技术社区  ›  Soleil

双重异常不一致(System.IO.FileNotFoundException/System.Runtime程序集版本)

  •  0
  • Soleil  · 技术社区  · 6 年前

    在WPF应用程序中,我正在创建 Prism.Unity.UnityBootstraper 子类,此上下文中的引导程序:

    protected override void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        var bootstapper = new Bootstrapper();
        bootstapper.Run();
    }
    

    构建是很好的,但是,在过度的时候,我有一个双重的例外:

    System.IO.FileNotFoundException:'无法加载文件或程序集 'System.Runtime,版本=4.1.1.0,区域性=中性, publicKeyToken=b03f75f7f11d50a3a'或其依赖项之一。这个 系统找不到指定的文件。'

    我有以下内部异常,其中版本不同:

    FileNotFoundException:无法加载文件或程序集 'System.Runtime,版本=4.0.0.0,区域性=中性, publicKeyToken=b03f75f7f11d50a3a'或其依赖项之一。这个 系统找不到指定的文件。

    我重新安装了nuget包,并试图用这段代码来创建一个独立的用例,但是我无法重现这个异常。

    发生了什么事,我怎么才能解决这个问题?


    为了进一步调查,我激活了FusionLog:

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion]
    "ForceLog"=dword:00000001
    "LogFailures"=dword:00000001
    "LogResourceBinds"=dword:00000001
    "LogPath"="C:\\Logs\\Fusion\\"
    

    但是效用 fuslogvs.exe 相当不实用;所以我使用PowerShell:

    select-string "operation failed" *htm -ca | % {"$($_.filename):$($_.line)"}
    

    从程序集的日志目录中, c:/logs/fusion . 我发现了3个问题,尤其是:

    system.runtime,版本=4.0.0.0,区域性=中性, publickeytoken=b03f75f7f11d50a3a.htm:操作失败。

    在文件中,我得到:

    LOG: AppName = ShutterModeler.exe
    Calling assembly : Prism, Version=6.3.0.0, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59.
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: C:\Users\soleil\Documents\Visual Studio 2017\Projects\ShutterModeler\x64\Debug\ShutterModeler.exe.Config
    LOG: Using host configuration file: 
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.1.0.
    LOG: Post-policy reference: System.Runtime, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
    LOG: GAC Lookup was unsuccessful.
    LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime.DLL.
    LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime/System.Runtime.DLL.
    LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime.EXE.
    LOG: Attempting download of new URL file:///C:/Users/soleil/Documents/Visual Studio 2017/Projects/ShutterModeler/x64/Debug/System.Runtime/System.Runtime.EXE.
    LOG: All probing URLs attempted and failed.
    

    事实上,没有 System.Runtime.DLL 目录生成目标中的文件。

    然而, System.Runtime 已安装(v4.3),并出现在 $(SolutionDir)\packages . 在里面我找不到dotnet 4.7.2目标:

    Name
    ----
    MonoAndroid10
    MonoTouch10
    net45
    net462
    portable-net45+win8+wp80+wpa81
    win8
    wp80
    wpa81
    xamarinios10
    xamarinmac20
    xamarintvos10
    xamarinwatchos10
    

    我的WPF项目的目标是.NET 4.7.2。


    如Alex Ghionda-MSFT建议

    我搬走了:

    <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.1.0" newVersion="4.1.1.0" />
    

    app.config ,并且不再需要构建后的手动副本作为解决方案:

     xcopy /y "$(SolutionDir)packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll" "$(TargetDir)"
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   Alex Ghiondea - MSFT    6 年前