Keeping NuGet packages up to date is a recommended practice for most development teams. Package updates can provide security fixes, bug fixes, performance improvements, and new features. However, updating NuGet packages can sometimes introduce assembly version mismatches or missing dependencies, which may only become visible at runtime.
In this blog, we will look at one such issue that occurred in a .NET Framework 4.8 application hosted in IIS, where the error message pointed to the missing assembly.
Prerequisites:
The issue described in this blog occurred in,
.NET Framework 4.8
ASP.NET application hosted in IIS
NuGet packages updated to newer versions
IIS application configured for application auto-start/preloading
The Problem
After updating the NuGet packages in our project, the application started failing during application startup in IIS.
The following error was reported.
There was an error during processing of the managed application service auto-start for configuration path: 'MACHINE/WEBROOT/APPHOST/mysite/'. The error message returned is: 'An error occurred while executing Preload method.
Exception: System.IO.FileNotFoundException
Message: Could not load file or assembly 'Azure.Storage.Common, Version=12.28.0.0, Culture=neutral, PublicKeyToken=92742159e12e44c8' or one of its dependencies. The system cannot find the file specified.
Initial Investigation
The first assumption was that the required Azure.Storage.Common.dll was either missing from the application's bin directory, or an incompatible version had been deployed.
We checked the IIS application's bin directory and confirmed that Azure.Storage.Common.dll was present.
We also checked the NuGet dependencies and verified that the required dependencies were deployed with the application, including Azure.Storage.Common.dll , Azure.Core.dll , System.IO.Hashing.dll. The versions were also verified.
At this point, the error became confusing.
The Actual Problem
The error message was misleading. The actual problem was caused by a System.ValueTuple package version change that occurred as part of the NuGet package updates. After the package update, the required System.ValueTuple.dll was not being copied to the application's bin directory during deployment.
As a result, when the application was starting, the .NET Framework assembly loader attempted to load Azure.Storage.Common. While loading Azure.Storage.Common and resolving its dependency chain, another required assembly could not be found.
The loader ultimately reported the failure as,
Could not load file or assembly
'Azure.Storage.Common, Version=12.28.0.0'
or one of its dependencies.
Lesson learned
When an error message says that a DLL or one of its dependencies is missing, “dependency” does not necessarily mean a direct dependency of that DLL. The missing assembly can be any dependency further down the dependency chain. Therefore, when troubleshooting such errors, the entire dependency chain should be considered, not just the immediate dependencies.
No comments:
Post a Comment