简体   繁体   English

NET 4.0在COM +中安装程序集加载额外的依赖项

[英]NET 4.0 Installing Assembly in COM+ Loading Extra Dependencies

We have an assembly I will call COMPlusAssembly that references third party dlls. 我们有一个程序集,我将称其为引用第三方dll的COMPlusAssembly。 COMPlusAssembly is hosted in COM+ and installed using System.Enterprises.RegistrationHelper. COMPlusAssembly托管在COM +中,并使用System.Enterprises.RegistrationHelper安装。 Our clients may or may not install the third party software that is being referenced in COMPLusAssembly. 我们的客户可能会也可能不会安装COMPLusAssembly中引用的第三方软件。 In .NET 3.5 when installing COMPlusAssembly with RegistrationHelper it never even attempted to load the third party dll. 在.NET 3.5中,使用RegistrationHelper安装COMPlusAssembly时,它甚至从未尝试加载第三方dll。 Now that we have upgraded to .NET 4.0 it is loading the assembly and throwing a FileLoadException could not load file or assembly or one of its dependencies error during the registration. 现在我们已经升级到.NET 4.0,它正在加载程序集,并且在注册过程中抛出FileLoadException无法加载文件或程序集或其依赖项错误之一。 Did something change in .NET 4.0 which causes it to load additional dependencies that were not loaded in .NET 3.5. .NET 4.0中发生了什么变化,导致它加载了.NET 3.5中未加载的其他依赖项。 Our third party assembly is a .NET 2.0 assembly. 我们的第三方程序集是.NET 2.0程序集。 Is there a way to tell the framework not to load the dependency? 有没有办法告诉框架不要加载依赖项?

Thanks! 谢谢!

-Tammy -塔米

I don't really have an exact answer, yet (though it could evolve), however I have some pointers. 我还没有确切的答案(尽管它可能会演变),但是我有一些建议。

As far as I know, dependencies are not loaded (still, in .Net 4.0) until they are required by the JITter. 据我所知,依赖项直到JITter要求时才加载(仍然在.Net 4.0中)。 Perhaps somehow, previously delayed codepaths are now eagerly JITted and the dependencies thus attempted to be loaded. 也许以某种方式,现在急切地延迟了先前延迟的代码路径,并因此尝试加载依赖项。

Probably the best way to handle this is to manually take over the loading and resolution of the dependency by using AppDomain.Load before the code path which requires the dependency is JITted. 解决此问题的最佳方法可能是在需要依赖项的代码路径被JITted之前,通过使用AppDomain.Load手动接管依赖项的加载和解析。 You can then determine if the load succeeded, and if not, make an explicit decision not to execute the now unavailable code. 然后,您可以确定加载是否成功,如果不成功,则可以做出明确的决定,不执行现在不可用的代码。

Furthermore, since you are using .Net 4.0 you may also consider using a different way to satisfy dependencies by using the type resolution framework called MEF which lives in System.ComponentModel.Composition . 此外,由于使用的是.Net 4.0,因此您还可以考虑使用另一种方法来满足依赖关系,即使用位于System.ComponentModel.Composition称为MEF的类型解析框架。 Using MEF, you can easily load and discover types which are then automatically composed into your depending types. 使用MEF,您可以轻松加载和发现类型,然后将它们自动组合成您依赖的类型。 In this case, after you run a discovery, you'd find that the dependency was not satisfied (perhaps the property value remained null ), and then you can take the appropriate action. 在这种情况下,运行发现后,您会发现不满足依赖关系(也许属性值保持为null ),然后可以采取适当的措施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM