I wrote an own data abstraction layer, able to sit on different real dals
using interfaces as datadefinitions. as first base dal I used
fluentnhibernate and ran into a big problem.
nhibernate needs a datatype with a parameterless constructor in a loadable
assembly but with assemblybuild run you cannot emit anything matching this
needs if you cannot write assemblies to disk. so i extended the
ReflectHelper.cs a bit.
didn't knew where to post this, so I choosed this group
public static System.Type TypeFromAssembly(AssemblyQualifiedTypeName name,
bool throwOnError)
{
try
{
// Try to get the type from an already loaded assembly
System.Type type = System.Type.GetType(name.ToString());
if (type != null)
{
return type;
}
if (name.Assembly == null)
{
// No assembly was specified for the type, so just fail
string message = "Could not load type " + name + ".
Possible cause: no assembly name specified.";
log.Warn(message);
if (throwOnError) throw new TypeLoadException(message);
return null;
}
// first search appdomain for the assembly and check for
the type, since proxygenerators can generate more assemblies of the same
name. they even have not not to be loadable.
Assembly assembly =
AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.FullName ==
name.Assembly && a.GetType(name.Type) != null);
// if the assembly is not found, try to load it
if(assembly == null)
assembly = Assembly.Load(name.Assembly);
if (assembly == null)
{
log.Warn("Could not load type " + name + ". Possible
cause: incorrect assembly name specified.");
return null;
}
type = assembly.GetType(name.Type, throwOnError);
if (type == null)
{
log.Warn("Could not load type " + name + ".");
return null;
}
return type;
}
catch (Exception e)
{
if (log.IsErrorEnabled)
{
log.Error("Could not load type " + name + ".", e);
}
if (throwOnError) throw;
return null;
}
}
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/nhusers.
For more options, visit https://groups.google.com/groups/opt_out.