Assembly.GetAssembly assumes you have an instance of the type, and Type.GetType assumes you have the fully qualified type name which includes assembly name.
If you only have the base type name, you need to do something more like this:
public static String GetAssemblyNameContainingType(String typeName)
{
foreach (Assembly currentassembly in AppDomain.CurrentDomain.GetAssemblies())
{
Type t = currentassembly.GetType(typeName, false, true);
if (t != null) {return currentassembly.FullName;}
}
return "not found";
}
This also assumes your type is declared in the root. You would need to provide the namespace or enclosing types in the name, or iterate in the same manner.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…