Home
Options

Linqpad throws exception when my app calls AppDomain.CurrentDomain.GetAssemblies

I have an app which uses reflection a lot - it is based on https://github.com/nikkilocke/CodeFirstWebFramework.

The framework has the following line of code:

            Type ns = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes().Where(t => t.Namespace == server.Namespace && !t.IsAbstract && t.IsSubclassOf(typeof(Namespace)))).FirstOrDefault();

This fails when run in LinqPad 6.4.10 (X64) with the exception:

System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Method 'GetSequencePoints' in type 'LINQPad.Reflection.PortablePdbDebugInfoProvider' from assembly 'LINQPad.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=21353812cd2a2db5' does not have an implementation.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at CodeFirstWebFramework.Namespace.<>c__DisplayClass19_0.<Create>b__0(Assembly a)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at CodeFirstWebFramework.Namespace.Create(ServerConfig server)
   at CodeFirstWebFramework.WebServer.registerServer(ServerConfig server)
   at CodeFirstWebFramework.WebServer..ctor()
System.TypeLoadException: Method 'GetSequencePoints' in type 'LINQPad.Reflection.PortablePdbDebugInfoProvider' from assembly 'LINQPad.Runtime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=21353812cd2a2db5' does not have an implementation.

The same code used to work in an earlier version of LinqPad 6.

Can you help here at all?

Comments

  • Options

    I can't reproduce that... do get the same error when you run that query in LINQPad?

    FWIW, the expression AppDomain.CurrentDomain.GetAssemblies() is .NET Framework-specific, and so will not give correct results on .NET Core and .NET 5, which do not have application domains and instead use ALCs for isolation. To get correct results on .NET Core and .NET 5, you must do this instead:

    AssemblyLoadContext.GetLoadContext (Assembly.GetExecutingAssembly()).Assemblies
    
Sign In or Register to comment.