.net console app lifecycle - working around a pre-start initialization error from BuildManager.GetReferencedAssemblies

前端 未结 2 2058
隐瞒了意图╮
隐瞒了意图╮ 2021-01-15 17:09

I\'m trying to iterate through the referenced assemblies in my console app. I have been doing this with BuildManager.GetReferencedAssemblies in other projects, but in my co

2条回答
  •  无人及你
    2021-01-15 17:39

    AppDomain.CurrentDomain.GetAssemblies() didn't quite do the trick. There were some assemblies that were not included, though they were referenced. What I did was this:

    allAssemblies = (from name in Assembly.GetEntryAssembly().GetReferencedAssemblies()
            select Assembly.Load(name)).ToList();
    

    This didn't return as many assemblies as AppDomain.CurrentDomain.GetAssemblies(), but it returned the ones I needed. Not sure why there was a discrepancy. Cerebrate, thank you for the reply though. You got me on the track I needed, and I upvoted your reply.

提交回复
热议问题