Could not load file or assembly â€˜xâ€™ or one of its dependencies. Strong name validation failed.
In some of the work I’m doing right now, I’m manipulating an assembly after compile time - having it disassembled into IL, tweaked, then re-compiled back into an assembly. The assembly is signed and what is being done to the assembly is breaking the strong name. This is quite comforting to know; the strong name wouldn’t be so strong if it was that easy to hack an assembly with a strong name. When trying to load the hacked assembly, I am getting an exception (FileLoadException in this case but I’m guessing this may differ depending on your assembly load method) with the message “Could not load file or assembly ‘MyAssemblyName’ or one of its dependencies. Strong name validation failed.”. The first interesting thing here is that the assembly named in the error message isn’t the hacked assembly; the hacked assembly is one of MyAssemblyName’s dependencies and is what’s triggering the error. Make sure that you check the dependencies of the assembly named in the exception message when troubleshooting. The problem may be with one of the dependencies. In my case the exception isn’t a surprise because of what’s being done to the assembly. But until I resolve that, how can I get around this for now? You can exclude an assembly from strong name validation for development purposes using the Microsoft ® .NET Framework Strong Name Utility tool aka sn.exe: ”%ProgramFiles%Microsoft SDKsWindowsv6.0Abinsn.exe” -Vr “C:PathToAssembly.dll” Make sure you change the sn.exe path depending on which version of the .NET Framework SDK you have installed. If you’re having trouble, get into the � “%ProgramFiles%Microsoft SDKsWindows” dir and search for sn.exe, and use the newest one you can find. You might find it handy to add this as a Post-build event command-line for your project from within Visual Studio in Project Properties > Build Events: ”%ProgramFiles%Microsoft SDKsWindowsv6.0Abinsn.exe” -Vr “$(TargetPath)” So how do you switch the strong name validation back on for your assembly? Use the -Vu switch: ”%ProgramFiles%Microsoft SDKsWindowsv6.0Abinsn.exe” -Vu “C:PathToAssembly.dll”