UnhandledException in Alternet.Syntax.CodeCompletion.ReflectionRepository.RegisterAssembly(String name) (v8.1.9)

Hello Support,

there exists an unhandled exception that cannot be catched in ReflectionRepository:
Description: The process was terminated due to an unhandled exception.
Exception Info: System.IO.FileLoadException: Could not load file or assembly ‘System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e’.
at System.Runtime.Loader.AssemblyLoadContext.g____PInvoke|5_0(IntPtr ptrNativeAssemblyBinder, UInt16* ilPath, UInt16* niPath, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Alternet.Syntax.CodeCompletion.ReflectionRepository.RegisterAssembly(String name)
at Alternet.Syntax.CodeCompletion.ReflectionRepository.<>c__DisplayClass42_0.b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
— End of stack trace from previous location —
at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
— End of stack trace

It would be helpful if we could catch this exception.

Thanks,
Andreas

Hi Andreas,

We can certainly put try/catch code around assembly loading; however since System.Private.CoreLib is a part of the .NET Core, I suspect there might be some other issue here.

Could I ask you to provide more details of what is the assembly you’re trying to register and what .NET Framework/.NET Core version your project is compiled with?

Kind regards,
Dmitry

Hi Dmitry,

the diagnostic problem is that I don’t try to register something, but the exception occurs maybe 20 seconds after the user is working with the app. From the stack trace we see that it is a thread pool thread, but I don’t know the caller. The FrameworkPath is ‘C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.3’. What can I do to isolate the point?

Hi Andreas,

Thank you for providing these additional details. It seems to be related to the asynchronous assembly loading of default assemblies for code completion purposes for the advanced C# or Visual Basic parser.

We could not reproduce the problem with .NET 7 yet; however, we will add code to suppress exceptions when loading these assemblies and will push an update to NuGet with this fix shortly.

Kind regards,
Dmitry

Hi Dmitry,

thank you, that’s good. One more question - is there any logging you can configure or any other way to know about such occurrences?

Hi Andreas,

We will look at adding logging so you can see errors like that when running the project from the Visual Studio debugger.

Kind regards,
Dmitry

Hi Andreas,

We have just published a new version (8.1.10) to NuGet, which should address this issue.

Kind regards,
Dmitry

Hi Dmitry,

thank you.

Andreas