[Mono-list] Using late-bound dynamic assembly
Andrus
kobruleht2 at hot.ee
Fri Jun 20 04:13:41 EDT 2008
One of my WinForms application assemblies, EntityExtension is not
distributed with application.
This assembly is created (compiled) dynamically in AppDomain AssemblyResolve
event and placed to Windows temporary directory every time when application
starts.
Under .NET it works OK.
Under MONO my application does not start:
** (myapp.exe:4140): WARNING **: The following assembly referenced from ...
Business.dll could not be loaded:
Assembly: EntityExtension (assemblyref_index=1)
Version: 0.0.0.0
Public Key: (none)
The assembly was not found in the Global Assembly Cache, a path listed in
the MONO_PATH environment variable, or in the location of the executing
assembly (....).
** (myapp.exe:4140): WARNING **: Could not load file or assembly
'EntityExtension, Version=0.0.0.0, Culture=neutral' or one of its
dependencies.
** (myapp.exe:4140): WARNING **: Could not load file or assembly
'EntityExtension, Version=0.0.0.0, Culture=neutral' or one of its
dependencies.
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or
assembly 'EntityExtension, Version=0.0.0.0, Culture=neutral' or one of its
dependencies.
File name: 'EntityExtension, Version=0.0.0.0, Culture=neutral'
at (wrapper managed-to-native) System.Reflection.Assembly:GetTypes (bool)
at System.Reflection.Assembly.GetTypes () [0x00000]
at DbLinq.Factory.Implementation.ReflectionObjectFactory.Parse
(System.Reflection.Assembly assembly, IDictionary`2
interfaceImplementations) [0x00000] ...
DbLinq.Factory.Implementation.ReflectionObjectFactory.Parse method contains
typical AOP pattern:
protected virtual void Parse(Assembly assembly, IDictionary<Type,
IList<Type>> interfaceImplementations)
{
try
{
var assemblyTypes = assembly.GetTypes();
foreach (Type type in assemblyTypes)
{
if (type.IsAbstract)
continue;
foreach (Type i in type.GetInterfaces())
{
if
(i.Assembly.GetCustomAttributes(typeof(DbLinqAttribute), false).Length > 0)
{
IList<Type> types;
if (!interfaceImplementations.TryGetValue(i, out
types))
interfaceImplementations[i] = types = new
List<Type>();
types.Add(type);
}
}
}
}
catch (ReflectionTypeLoadException)
{
}
}
It seems that this causes MONO to crash since EntityExtension.dll assembly
does not exist as this moment (it is created later).
In .NET it causes ReflectionTypeLoadException which this code ignores so it
works OK.
How to fix ?
To fix this I tried to use Microsoft assemblies in Windows but got error
** (myapp.exe:5208): WARNING **: Missing method
System.Reflection.Emit.DynamicMethod::.ctor(string,Type,Type[],bool) in
assembly C:\PROGRA~1\MONO-1~1.1\lib\mono\2.0\mscorlib.dll, referenced in
assembly C:\myapp\System.Core.dll
Unhandled Exception: System.MissingMethodException: Method not found:
'System.Reflection.Emit.DynamicMethod..ctor'.
at System.Linq.Expressions.ExpressionCompiler.CompileDynamicLambda
(System.Linq.Expressions.LambdaExpression lambda) [0x00000]
at System.Linq.Expressions.ExpressionCompiler.Compile
(System.Linq.Expressions.LambdaExpression lambda) [0x00000]
at System.Linq.Expressions.LambdaExpression.Compile () [0x00000]
Are there any plans to implement
System.Reflection.Emit.DynamicMethod class in Mono mscorlib ?
Andrus.
More information about the Mono-list
mailing list