简体   繁体   中英

NET 4.0 Installing Assembly in COM+ Loading Extra Dependencies

We have an assembly I will call COMPlusAssembly that references third party dlls. COMPlusAssembly is hosted in COM+ and installed using System.Enterprises.RegistrationHelper. Our clients may or may not install the third party software that is being referenced in COMPLusAssembly. In .NET 3.5 when installing COMPlusAssembly with RegistrationHelper it never even attempted to load the third party 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. Did something change in .NET 4.0 which causes it to load additional dependencies that were not loaded in .NET 3.5. Our third party assembly is a .NET 2.0 assembly. 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. 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. 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 . Using MEF, you can easily load and discover types which are then automatically composed into your depending types. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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