Quantcast
Channel: Managed Extensibility Framework
Viewing all articles
Browse latest Browse all 265

Created Unassigned: MEF2 - troubles with exporting value types (bool, int, etc.) [14626]

$
0
0
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

Viewing all articles
Browse latest Browse all 265

Trending Articles