This project has moved. For the latest updates, please go here.
1
Vote

MEF2 - troubles with exporting value types (bool, int, etc.)

description

Hi,

I'm trying export properties with types like boolean or integer, but I'm getting this exception:

Expression of type 'System.Boolean' cannot be used for return type 'System.Object'

I find out problem with building export expression in System.Composition.TypedParts.Discovery.DiscoveredPropertyExport. For now it looks like:
var activator = Expression.Lambda<CompositeActivator>(
                Expression.Property(
                    Expression.Convert(Expression.Call(Expression.Constant(partActivator), s_activatorInvoke, args), _property.DeclaringType),
                    _property),
                args);
but I guess it could be fixed by changing convert type
var activator = Expression.Lambda<CompositeActivator>(
                Expression.Property(
                    Expression.Convert(Expression.Call(Expression.Constant(partActivator), s_activatorInvoke, args), _property.DeclaringType.IsValueType ? typeof(object) : _property.DeclaringType),
                    _property),
                args);
However, I've no idea about impact of that change to other parts of MEF2. Could someone say something about how big deal is that change?

I attached simple project reproducing bug.

greetings

file attachments

comments