How do I use two versions of the same assembly inside an ASP.NET application?
I have an old version of an asp.net component. I would like to use a newer version alongside the old version.
I put both assemblies in the GAC using the gacutil.exe
command. Now, I would like to load a specific version of the component inside each .aspx
page.
How can I do this?
Can I use this code?
<%@ Register assembly="<dllname>, Version=2.5.0.0, Culture=neutral,
PublicKeyToken=......开发者_运维百科." Namespace="<dllNamespace>." TagPrefix="WG" %>
You can use create an object of version you want in runtime using the following code
Object obj = Activator.CreateInstance("dllName","dllNameSpace.ClassName");
you can refer to Activator.CreateInstance or Use Activator.CreateInstance to Create Objects from a String Name
Technicly yes, It's possible with the Register
property you are asking about. It is however not a really easy path to walk as it will be riddled with strange limitations.
My suggestion would be to either not do it at all if possible or else isolate the controls of different versions in usercontrols that can live in separate class libraries. You'd get assembly names like: controls_for_1_5
and controls_for_2_5
and in here you create references to the assembly. (The names are of course for you to choose). This way can still cause strange errors like Can't cast 'Namespace.ClassA' to 'Namespace.ClassA'
(Yes they are the same, it's not a typo) if your not carefull.
Still my advise would be to not do it unless you have a real strong understanding of the deeper parts of the .NET framework.
精彩评论