I need to dynamically get the list of Controls in the PresentationFramework assembly. For now, I can load the assembly with this piece of code:
我需要动态获取PresentationFramework程序集中的控件列表。现在,我可以用这段代码加载程序集:
var asmName = new AssemblyName("PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35");
var asm = Assembly.Load(asmName);
However, if in the future the framework is updated to higher version, the above code won't be able to pick up the new assembly. Please show me how to do it the right way. Many thanks.
但是,如果将来框架更新到更高版本,上面的代码将无法获取新程序集。请告诉我如何以正确的方式做到这一点。非常感谢。
2 个解决方案
#1
I don't think that there is a way to automatically get the latest version of an assembly in the GAC, since that could lead to the whole "DLL Hell" problem all over again. Strong-named assemblies, which all assemblies in the GAC are required to be, include their version number in their name to ensure that you are loading exactly the version you expect. This will prevent a newer version of the assembly from breaking your application.
我不认为有一种方法可以在GAC中自动获取最新版本的程序集,因为这可能会导致整个“DLL Hell”问题再次出现。强名称程序集(GAC中的所有程序集都必须包含在其名称中)包含其版本号,以确保您正在加载您期望的版本。这将阻止较新版本的程序集破坏您的应用程序。
#2
It's depreciated but you can use:
它已折旧但您可以使用:
Assembly.LoadWithPartialName("PresentationFramework");
#1
I don't think that there is a way to automatically get the latest version of an assembly in the GAC, since that could lead to the whole "DLL Hell" problem all over again. Strong-named assemblies, which all assemblies in the GAC are required to be, include their version number in their name to ensure that you are loading exactly the version you expect. This will prevent a newer version of the assembly from breaking your application.
我不认为有一种方法可以在GAC中自动获取最新版本的程序集,因为这可能会导致整个“DLL Hell”问题再次出现。强名称程序集(GAC中的所有程序集都必须包含在其名称中)包含其版本号,以确保您正在加载您期望的版本。这将阻止较新版本的程序集破坏您的应用程序。
#2
It's depreciated but you can use:
它已折旧但您可以使用:
Assembly.LoadWithPartialName("PresentationFramework");