Very interesting, I was never aware of collectible assemblies and I've 
already got some ideas of how to use them in an upcoming project. :)

Anyways, my only other suggestion would be to investigate creating your 
dynamic assembly as non-collectible. I have no knowledge of the Mono.CSharp 
library so I don't even know if that is possible but one could hope that 
they implemented something like the AssemblyBuilderAccessRunAndCollect flag 
that allows specifying whether the assembly is collectible or not as noted 
here: http://msdn.microsoft.com/en-us/library/dd554932.aspx

Update: It looks like they have implemented this flag/enum, see the Mono 
documentation here: 
http://docs.go-mono.com/?link=T%3aSystem.Reflection.Emit.AssemblyBuilderAccess

Let me know if that helps you and good luck!

Cheers,
--Randy


On Tuesday, February 5, 2013 2:22:32 PM UTC-6, Leo wrote:
>
> Thank you for the suggestion. I did try to use the 
> AppDomain.ResolveAssembly method but I get a completely different 
> exception: "Resolving to a collectible assembly is not supported".
>
> This error is generated by the call to System.Type type = System.Type.
> GetType(name.ToString()); in the ReflectHelper.cs file on line 267. It 
> appears that the assembly generated using Mono.CSharp is a collectible 
> assembly. The documentation for System.Type.GetType does mention that it 
> doesn't work with dynamically loaded assemblies.
>
> After many hours of trying different options, I am left with modifying the 
> source code. A colleague pointed out how naive my simple modification was 
> and we enhanced it as follows.
>
> 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;
> }
>
> // See if the assembly is already loaded in the current AppDomain. 
> var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies();
>
> Assembly assembly = null;
>
> foreach (var loadedAssembly in loadedAssemblies)
> {
> var assemblyName = new AssemblyName(loadedAssembly.FullName);
>
> if (loadedAssembly.FullName == name.Assembly || assemblyName.Name == 
> name.Assembly)
> {
> assembly = loadedAssembly;
> }
> }
>
> 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;
> }
> }
>
> Any other suggestions would be appreciated.
>
>
> On Monday, February 4, 2013 10:40:34 PM UTC-7, Randy Burden wrote
>>
>> You don't have to modify the NHibernate source. You should be able to 
>> leverage the .NET frameworks AppDomain.ResolveAssembly event which will 
>> call whenever Assembly.Load or any other time when runtime attempts to load 
>> and assembly. See the following MSDN link for more info: 
>> http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to