-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FileNotFoundException resource files is slowing things down ridiculously #36053
Comments
I couldn't figure out the best area label to add to this issue. Please help me learn by adding exactly one area label. |
@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. |
@dgxhubbard do you have a small sample to reproduce the issue so we can take a look? also, the stack trace will help too. |
CC @ericstj |
I am not sure where "Failed to resolve" comes from. I cannot find it in runtime/wpf/corefx/coreclr. |
I think this properly a wpf issue but wanted to get repro first to confirm. @danmosemsft does it repro with any simple wpf app? |
I have the debugger running. I will stop on the exception and get you a stack trace |
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 )
|
This is the source of your exception:
Perhaps you should do an exists check before calling Assembly.LoadFrom. Return null (fall through) if the file doesn't exist. |
I would think the point of this is why is new AssemblyCatalog failing for something that exists. I admit that got buried because of the problem with exception. |
Tagging subscribers to this area: @ViktorHofer |
AssemblyCatelog at the end is calling Assembly.Load and Assembly.LoadFrom. Maybe the assembly trying to load is not listed in deps.json of the app which makes the loader not loading it? just a guess. |
Since this is not a regression it's unlikely to make it in 5.0.0 due to the bar. Let's consider for 6.0. |
We are also seeing this issue in the Microsoft Test Platform. There's no such file System.Private.DataContractSerialization.resources.dll ANYWHERE on the system. Leave alone version 4.1.5.0 which also appears not to have been published on Nuget (I'm assuming resources file usually shares the version of the main assembly). This actually breaks the Test Platform (error intermittent and causes Azure DevOps agent to hang and the pipeline never completes. Is there a workaround? BTW, we are using .Net Core 3.1. TpTrace Error: 0 : 9328, 9, 2021/04/07, 12:34:13.303, 6021418487030, testhost.dll, LengthPrefixCommunicationChannel: MessageReceived: Exception occurred while calling handler of type Microsoft.VisualStudio.TestPlatform.CommunicationUtilities.TestRequestHandler for MessageReceivedEventArgs: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. |
Do you have an Lines 12 to 17 in 2e12730
The same was true in 3.1. The problem comes when others hook AssemblyResolve . If their handler attempts it's own load it can trigger the FileNotFoundException. Check the stack trace for those exceptions to find the problematic AssemblyResolve handler. You should be able to do this by enabling break on first-chance-exceptions for FileNotFoundException and examining the stack trace. Let us know if you find some framework assembly at fault, or even if it's the test runner and we can help route.
|
I'm getting this with a Workaround is to specify Here is the stacktrace (@ericstj it seems the AssemblyResolve handler in this case is from the CoreLib itself:
I suppose the handler is registered when I call Caused by: |
I believe the fix here is for
So the fix here is to add an exists check here (and we might be able to delete that catch FNF 😆) runtime/src/libraries/System.Private.CoreLib/src/System/Reflection/Assembly.cs Lines 323 to 339 in 9a0b8f3
Looks like there are other exists checks in this neighborhood so it should be a reasonable change to make. |
Tagging subscribers to this area: @dotnet/area-system-reflection Issue DetailsIn .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 Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll Exception thrown: 'System.IO.FileNotFoundException' in System.Private.CoreLib.dll
|
@dotnet/area-system-reflection this is a good candidate for 7.0.0 |
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 |
And even if you check for existence, you still need to catch the FNF exception because the file might not be there anymore. |
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 |
Sounds good to me. |
This should block on #27217 |
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
The text was updated successfully, but these errors were encountered: