Dynamically Create Type By Version

G

Guest

Our software is interface based meaning that we don't add any references to
implemntation assemblies. All loading is done via
Activator.CreateInstance(assembly, class name). Our components that we are
instancing are loaded in the GAC.

In preparing for a version change in our software we are wondering how we
would be able to instance a particular version of a component. Say I know
the class name and assembly, yet there is a version 1.0.0.0 and a version
2.0.0.0 and I specifically want to load version 1.0.0.0. What can I do to
ensure this is the version that I get? There doesn't seem to be an overload
for loading a particular version of a component via Activator.

I thought I would create the type as well, but I can't fiure out how to
specify version. Any thoughts?

If there is a better newsgroup to post this question on, please let me know.

Thanks,
 
L

Lloyd Dupont

I think you could gave long assembly name, which includes the version.
something like SWF1.1.4300
but I'm not sure of the format though...
you could try to use the various name/evidence/fullname/and so on and print
them on the console to get an idea?!...
 
P

Peter Huang [MSFT]

Hi

Here is a code snippet from MSDN for your reference, the AssemblyName can
be a fully qualified assembly name.

Dim hdlSample As ObjectHandle
Dim myExtenderInterface As IMyExtenderInterface
Dim argOne As String = "Value of argOne"
Dim argTwo As Integer = 7
Dim args As Object() = {argOne, argTwo}
' Uses the UrlAttribute to create a remote object.
Dim activationAttributes() = {New
UrlAttribute("http://localhost:9000/MySampleService")}
' Activates an object for this client.
' You must supply a valid fully qualified assembly name here.
hdlSample = Activator.CreateInstance("Assembly text name, Version, Culture,
PublicKeyToken", "samplenamespace.sampleclass", True, BindingFlags.Instance
Or BindingFlags.Public, Nothing, args, Nothing, activationAttributes,
Nothing)
myExtenderInterface = CType(hdlSample.Unwrap(), IMyExtenderInterface)
Console.WriteLine(myExtenderInterface.SampleMethod("Bill"))

Activator.CreateInstance Method
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/
frlrfSystemActivatorClassCreateInstanceTopic9.asp


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top