After making the changes detailed recently where I upgraded the .csproj project file format for a personal project, I found that the command line tool compiled by the project failed to work.

When run, it gave the following error:

PS> .\dfcmd.exe
Document Factory
No mode specified

Could not load file or assembly 'System.Reflection, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 

(I’ve elided some of the detail to highlight the actual error.)

Clearly, this isn’t satisfactory, so I need to resolve the issue pretty quickly - this is a tool I use all the time. The good news is that all of the unit and integration tests run properly, so I have some confidence the problem was just with the dfcmd project - which is a fairly simple console application over the rest of the system.

As I write this, I don’t know what the solution is going to be - this blog post is just following along as I investigate the problem.

In my experience, the “or one of its dependencies” part of the above error message often conceals hide a whole lot of detail, so I need to know more about the exact problem the program encounters.

I’ll use the Assembly Binding Log Viewer (also known as the fusion log viewer) - a tool that’s been around since the start of .NET to dig into this. It’s a part of your Visual Studio installation.

Running “Developer Command Prompt for VS 2017” in elevated (Administrator) mode, I run fuslogvw.exe:

To capture the error, I pressed “Settings” and selected “Log bind failures to disk”. (I need to remember to come back and set this to “Log Disabled” when I’m finished, otherwise I’ll start filling my disk with useless log files.) I neglected to run this from an elevated command prompt the first time and I couldn’t change any of the settings.

To start with a clean slate, I pressed “Delete All”, reproduced the error, then pressed “Refresh” to see what errors had occurred.

Opening the first log entry in a browser showed a very readable log that clearly explained what had happened. Here are the relevant lines (lightly edited for display):

LOG: Using application configuration file: dfcmd.exe.Config
LOG: Redirect found in application configuration file: 4.0.0.0 redirected to 4.1.2.0.
LOG: Post-policy reference: System.Runtime.Extensions, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Checking my project in Visual Studio, the project was referencing the System.Runtime.Extensions NuGet package, but at version 4.3.0.0. Digging further, I find the error in my app.config file; as reported above, it appears to be redirecting to the wrong version:

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

Changing this to reflect the version of the NuGet package (v4.3.0.0) is my first fix; after a rebuild of the application, that error no longer appeared in the fusion log viewer.

Unfortunately, the application still crashed with exactly the same error:

PS> .\dfcmd.exe
Document Factory
No mode specified

Could not load file or assembly 'System.Reflection, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies.

Clearly, the second error showing in the log viewer needed to be addressed as well. That one wasn’t so easy to fix.

Comments

blog comments powered by Disqus