I’ve inherited a large C# application that is giving me a run-time exception when debugging in Visual Studio 2022. The previous developers aren’t available to troubleshoot, but they reported that they hadn’t experienced the exception:
System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.WindowsAPICodePack.DirectX, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.'
The project is build settings are currently Debug
and x64
. It is using the Target framework .NET 6.0
. The Target OS Version has been tried as 7.0 and 10.0.19041.0. Both give the same exception.
In the *.csproj file, the HintPath provides a relative path:
<ItemGroup>
<Reference Include="Microsoft.WindowsAPICodePack.DirectX">
<HintPath>..LibraryDllsMicrosoft.WindowsAPICodePack.DirectX.dll</HintPath>
</Reference>
</ItemGroup>
It seems like this should just be a path issue. I have verified that the file (Microsoft.WindowsAPICodePack.DirectX
) is in the relative path indicated. Just in case, I removed the file from the project references and added it back to the project. The exception was unchanged. I also tried modifying the PATH environment variable in the project’s debug launch profile (screenshot below with sensitive information removed). Again, no change to the exception.
Debug environment PATH variable
I tried looking at Process Monitor to see if there was an issue loading the dll, but it looks like it loads successfully and from the debug folder (image below). All of the status results up to the exception were SUCCESS
or FILE LOCKED WITH ONLY READERS
that are followed by SUCCESS
.
Process monitor for the Microsoft.WindowsAPICodePack.DirectX.dll
Any suggestions would be greatly appreciated.