Greg Finzer
Greg Finzer

Reputation: 7054

How do I get the type with a type string when the version has changed?

I am saving a list of type strings to be instantiated dynamically. Using reflection, how do I get the type with a type string when the version number has changed?

Example, I have a type string defined as:

AcmeCorporation.BusinessObjects.Customer, AcmeCorporation.BusinessObjects, Version=2.0.0.0, Culture=neutral, PublicKeyToken=dccbd7ce7d6a58c0

//This works fine
Type type = Type.GetType(typeString, false);

However when my assembly version changes to 2.0.0.1 the saved type string does not work because the version numbers are diferent.

Can I find the assembly by name and then find the type by name?

How would I do this?

Upvotes: 1

Views: 44

Answers (1)

Matti Virkkunen
Matti Virkkunen

Reputation: 65116

If you don't care about the version, why include it in your type string? All parts except the first one are optional in the string passed to Type.GetType:

Type t = Type.GetType("AcmeCorporation.BusinessObjects.Customer, AcmeCorporation.BusinessObjects");

Upvotes: 2

Related Questions