I was able to hack NHibernate by commenting out the AssemblyKeyFile attribute in AssemblyInfo.cs everywhere it was set to NHibernate.snk. I also had to rebuild everything referenced by NHibernate (NHibernateContrib, Nullables2, etc.) in order for those DLLs to accept NHibernate without a strong name. There has to be a better way ...
Anyway, here is the code to fix the problem. In Util\ReflectHelper.cs, make the following changes:
1. Add the following new method:
Code:
public static System.Type FindLoadedType(string assemblyQualifiedTypeName)
{
System.Type foundType = System.Type.GetType(assemblyQualifiedTypeName, false);
if (foundType != null)
{
return foundType;
}
//
// If we get here, the type is probably in a dynamically loaded assembly.
// For some reason, Type.GetType() can't find these.
// Just look through the loaded assemblies to find it.
//
// If the type name is not assembly-qualified, then just search through
// all loaded assemblies and return the first matching one found.
//
// TODO: Respect any assembly version number, culture or public key token
// requested in the type name
//
int firstCommaPosition = assemblyQualifiedTypeName.IndexOf(",");
bool usingAssemblyQualifiedName = (firstCommaPosition >= 0);
string namespaceQualifiedTypeName = assemblyQualifiedTypeName;
string searchAssemblyFullName = String.Empty;
if (usingAssemblyQualifiedName)
{
namespaceQualifiedTypeName =
assemblyQualifiedTypeName.Substring(0, firstCommaPosition);
searchAssemblyFullName =
assemblyQualifiedTypeName.Substring(firstCommaPosition + 1).Trim();
}
System.Reflection.AssemblyName loadedAssemblyName;
string loadedAssemblyFullName;
System.Reflection.Assembly[] loadedAssemblies =
System.Threading.Thread.GetDomain().GetAssemblies();
foreach (Assembly loadedAssembly in loadedAssemblies)
{
loadedAssemblyName = loadedAssembly.GetName();
loadedAssemblyFullName = loadedAssemblyName.FullName;
if (!usingAssemblyQualifiedName ||
loadedAssemblyFullName == searchAssemblyFullName)
{
foundType = loadedAssembly.GetType(namespaceQualifiedTypeName);
if (usingAssemblyQualifiedName || foundType != null)
{
break;
}
}
}
return foundType;
}
2. Change ClassForName to
Code:
public static System.Type ClassForName(string name)
{
System.Type foundType = FindLoadedType(name);
if (foundType == null)
{
throw new TypeLoadException(String.Format("Type '{0}' is not loaded.", name));
}
return foundType;
}
3. In TypeFromAssembly and GetConstantValue, change Type.GetType to FindLoadedType.