Repository navigation
Description
In .net core 3.1, on wpf we are getting a ridiculous number of missing resource file FileNotFoundException. I have read this is a part of normal processing. If the resource file
cannot be found and it will be searched for somewhere else why throw an exception which
has a huge processing time, why not return a result that says not found. We are getting these
exceptions constantly yet we still see our resource strings. Below is an example. The worst part is the same missing resource file FileNotFoundException get thrown multiple. The delays in program startup are very noticeable. If there is something that can be done to fix this I would appreciate it.
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Failed to resolve C:\Repository\GtNext\bin\Debug\System.Configuration.ConfigurationManager.resources.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Failed to resolve C:\Repository\GtNext\bin\Debug\System.Configuration.ConfigurationManager.resources.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Failed to resolve C:\Repository\GtNext\bin\Debug\System.Data.SqlClient.resources.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Failed to resolve C:\Repository\GtNext\bin\Debug\System.Private.DataContractSerialization.resources.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Failed to resolve C:\Repository\GtNext\bin\Debug\System.Private.DataContractSerialization.resources.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Failed to resolve C:\Repository\GtNext\bin\Debug\System.ComponentModel.Composition.resources.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Failed to resolve C:\Repository\GtNext\bin\Debug\System.ComponentModel.Composition.resources.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Failed to resolve C:\Repository\GtNext\bin\Debug\System.Data.SqlClient.resources.dll
Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
Failed to resolve C:\Repository\GtNext\bin\Debug\System.Data.SqlClient.resources.dll
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
Dotnet-GitSync-Bot commentedon May 7, 2020
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label.
danmoseley commentedon May 7, 2020
@dgxhubbard can you please provide the callstack for the exception? Attach a debugger, if it's Visual Studio please swithc of "just my code" and load symbols.
tarekgh commentedon May 8, 2020
@dgxhubbard do you have a small sample to reproduce the issue so we can take a look? also, the stack trace will help too.
tarekgh commentedon May 8, 2020
CC @ericstj
danmoseley commentedon May 8, 2020
I am not sure where "Failed to resolve" comes from. I cannot find it in runtime/wpf/corefx/coreclr.
tarekgh commentedon May 8, 2020
I think this properly a wpf issue but wanted to get repro first to confirm. @danmosemsft does it repro with any simple wpf app?
dgxhubbard commentedon May 8, 2020
I have the debugger running. I will stop on the exception and get you a stack trace
dgxhubbard commentedon May 8, 2020
We are running 3.1.3 and when we load our assemblies for MEF using code below, and with "Just My Code" disabled we get a FileNotFound exception even though the path and assembly name are correct. At that point we added an assembly resolver to try and clear up the problem. This is where the errors come from. We get System.Private.DataContractSerialization.resources, Version=4.1.5.0, Culture=en-US, PublicKeyToken=b03f5f7f11d50a3a as the argument name and then add "dll" to it to try and resolve. Which causes an exception when LoadFrom is called. If I turn on "Enable Just My Code" and disable the assembly resolver then all problems with loading our assemblies for MEF using code below disappear. I had forgotten about the problem with creating the assembly catalog.
Stack Trace
at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly)
Assembly Resolver:
MEF Code to create assembly catalog:
`public static AssemblyCatalog GetCatalog( string assemblyName )
{
AssemblyCatalog assemblyCatalog = null;
33 remaining items
steveharter commentedon Aug 10, 2022
That seems like a reasonable approach however it is somewhat risky to do at this point in the release cycle. It should be done earlier.
Also adding a
File.Existsmay have to take into consideration embedded assemblies, as exists with browser\wasm scenarios.reijerh commentedon Aug 11, 2022
And even if you check for existence, you still need to catch the FNF exception because the file might not be there anymore.
ericstj commentedon Jan 2, 2024
For others landing on this issue - the most common cause of this problem is an AssemblyResolve handler which doesn't do an exists check before doing a loadfrom - those get invoked as part of the resource assembly resolution process (which itself tries to avoid raising exceptions).
This issue tracks fixing this for
Assembly.LoadFromResolveHandler. I see @tarekgh had some similar feedback in a related fix dotnet/coreclr#12329. @reijerh shared a great RCA in #36053 (comment). @jkotas what do you think about adding an exists check toLoadFromResolveHandlerto avoid these first-chance exceptions?jkotas commentedon Jan 2, 2024
Sounds good to me.
fowl2 commentedon Jan 4, 2024
Exists()beforeOpen()is an anti-pattern - it leads to TOCTOU races and wastes syscalls.This should block on #27217