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

Created Unassigned: Performance issue in SmallSparseInitonlyArray [14611]

$
0
0
Hello,

I have found a significant performance issue when using lost of Shared parts. 50% of composition time is spent inside System.Composition.Hosting.Util.SmallSparseInitonlyArray.Add on string.Format calls. The error is obvious: the method has 2 calls like

```
Assumes.IsTrue(e.Index != index, string.Format("An item with the key '{0}' has already been added.", index));
```

No matter what the condition is, string.Format gets evaluated every time.

So, MEF is spending 50% time on producing garbage. Definitely not the task a high performance framework should do. :)

New Post: MEF and generic class

$
0
0
Hello. I use Autofac Mef integration framework in my windows service project. I define several modules
and bind them when service start. But don't know how I can move my Repository class in separate module.
In my program i define Repository class as generic.
For example
public class Repository<T>: IRepository<T>, IDisposable where T : class
{
.........
}

[InheritedExport]
public interface IRepository<T>
{
....
}

I define InheritedExportAttribute in my interface for export in MEF modules.
But AutofacMef Integration doesn't find default constructor for any class,
which I define in generic class.
Is it possible to use this way at all? thank for help

My error:
Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'SolarRadiationCell.Host.HostService' can be invoked with the available services and parameters:

Cannot resolve parameter 'SolarRadiationCell.Service.Shared.IRepository1[SolarRadiationCell.Data.History.IHistory] _repository' of constructor 'Void .ctor(SolarRadiationCell.Service.Shared.IRepository1[SolarRadiationCell.Data.History.IHistory])'.

at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)

New Post: The component (unknown) cannot be created outside the HttpContext sharing boundary.

$
0
0
Hi,
Had the same issue when using like this:
    [Shared("Session")] [Export]
    public sealed class SessionController : ApiController { ... }
tnx

Created Unassigned: Generic registration does not work [14612]

$
0
0
Generic registration does not work

Example:

RegistrationBuilder.ForTypesDerivedFrom(typeof(IRepository<>)).Export();

New Post: Ensuring cleanup when hosted in IIS

$
0
0
Using the lightweight composition version.
Successfully creating, discovering and initializing parts.
All is well, except in some cases, where IIS still has a lock on the part assembly, preventing subsequent rebuilds without restarting IIS - and sometimes even that doesn't seem to work.
Seems to happen most often when an exception has occurred somewhere in the application, though not always.
Happens both in a preproduction environment (no debugger attached) and in our development environments (using local IIS).
Code is in place to cleanup on application end.

Looking for advice on what more could be done to ensure the assemblies are unlocked so they don't cause a problem with rebuilding or publish.
And.... I guess I don't understand why this is behaving differently than Providers, which are also dynamically loaded but don't cause this locking issue?

Any feedback much appreciated!

New Post: Can't import Generic Types After Update from MEF 1 under .NET 4 to latest in .NET 4.5

$
0
0
Hi,

I have a project that was on .NET 4.0 using a MEF pre-release from about 2 years ago and we're trying to update it to .NET 4.5. The pre-release we were on doesn't work with .net 4.5, so we're attempting to update MEF to the latest, however it's failing while loading a generic interface type, that used to work:

[Import]
    public IRepository<HealthCareDomain, LookupListCategory> Categories { get; set; }
Here's the class definition that it should be loading:

[Export( typeof( IRepository<,> ) )]
[PartMetadata( ExportScope.Key, TransactionScope.Id )]
[PartCreationPolicy( CreationPolicy.Shared )]
public class Repository<TDomain,TEntity> : IRepository<TDomain,TEntity>, IRepository
    where TEntity : class
{
...
}

How can I work around this?

Thanks!

New Post: Composing/Ignoring different parts based on context

$
0
0
Hello,

We currently use MEF like this:

Machine A:
  • Server.exe
  • ServerOnlyStuff.dll
  • MEF.Extension1.Server.dll
  • Extension1.Shared.dll
Machine B:
  • Client.exe
  • ClientOnlyStuff.dll
  • MEF.Extension1.Client.dll
  • Extension1.Shared.dll
That is, we keep assemblies imported by the font end separate from those imported by the back end. This way, Server.exe doesn't need to know about ClientOnlyStuff.dll, and Client.exe doesn't need to know about ServerOnlyStuff.dll. It keeps out unnecessary dependency.

I'd like to do this instead:

Machine A:
  • Server.exe
  • ServerOnlyStuff.dll
  • MEF.Extension1.dll <-- Same DLL
Machine B:
  • Client.exe
  • ClientOnlyStuff.dll
  • MEF.Extension1.dll <-- Different Context
If I set this up, composition chokes (ReflectionTypeLoadException). On Machine A this is because MEF.Extension1.dll references ClientOnlyStuff.dll, which is not there. On Machine B it chokes because MEF.Extension1.dll references ServerOnlyStuff.dll, which is not there.

I would like to be able to compose only the parts whose dependencies are present. This way a single dll could provide context-appropriate functionality in a number of locations.

One way to do this would be to allow developers to specify which namespace, within the target assembly, they're after.

Is there anything like what I'm talking about that I've missed, or is this a feature request?

Thanks for taking the time to read this, and thanks in advance for any advice you have for me.

New Post: How to build Hierarchical ViewModel using MEF

$
0
0
Hi,
I've been trying to build hierarchical view model for the purpose of using WPF Treeview in my application but no success. I use Prism+MEF as framework for my application and I tried very hard to include Treeview control as per Josh Smith article here but I don't know how to build that nested structure with MEF and without using new operator.
So I wish that some guru here can show us how to do it based on that example.
Thanks in advance

New Post: How to build Hierarchical ViewModel using MEF

$
0
0
What exactly are you looking for? Do you want the tabs in the UI to be plugins?

New Post: How to build Hierarchical ViewModel using MEF

$
0
0
Based On that sample how can I build the hierarchy of the View Models for example in the LoadOnDemand tree how to build CountryViewModel which wrap the RegionViewModel which wrap the StateViewModel ... etc. how to build such nested structure using MEF and eliminating the new operator.

New Post: How to build Hierarchical ViewModel using MEF

$
0
0
at least could anybody implement the following two classes using MEF and I will follow up for rest of the sample
public class CountryViewModel
{
readonly ReadOnlyCollection<RegionViewModel> _regions;
public ReadOnlyCollection<RegionViewModel> Regions
{
get { return _regions; }
}
//---------------------------------------------------------
public CountryViewModel(Region[] regions)
{
_regions = new ReadOnlyCollection<RegionViewModel>(
(from region in regions
select new RegionViewModel(region))
.ToList());
}
}


public class RegionViewModel : TreeViewItemViewModel
{
readonly Region _region;
public RegionViewModel(Region region)
: base(null, true)
{
_region = region;
}
public string RegionName
{
get { return _region.RegionName; }
}
protected override void LoadChildren()
{
foreach (State state in Database.GetStates(_region))
base.Children.Add(new StateViewModel(state, this));
}
}

New Post: Is there a way to tell if MEF created a instace for a Type I exported

$
0
0
My goal is to find any of my viewmodels that are dirty and when they exit the app , I should let them notify.

I can get to an instance based on type by below code but problem is its going to create instances for all view models as I am only interested in the ones which were already created by MEF container
List<Type> viewModelInterfaces = new List<Type>();
    viewModelInterfaces .Add(typeof(IAddressViewModel));
    viewModelInterfaces .Add(typeof(ICustomerNameViewModel));
    viewModelInterfaces .Add(typeof(IBudgetSummaryViewModel));

    foreach (var appInterface in viewModelInterfaces )
    {
        var obj = Container.GetExports(appInterface, ull,appInterface.FullName).FirstOrDefault();
        if (obj != null)
        {
            var viewModel = obj.Value as IViewModelBase;
            if (viewModel != null)
            {
                if (viewModel.IsDirty)
                {
                    Show Dialog
                }
            }
         }
     }

Created Unassigned: AtomicComposition encountered an unexpected Exception [14613]

$
0
0
Getting the following error occasionally


ProcessEntry() failed. InvalidOperationException: AtomicComposition encountered an unexpected Exception, review InnerException for details.
Stack Trace:
at System.ComponentModel.Composition.Hosting.AtomicComposition.FinalComplete()
at System.ComponentModel.Composition.Hosting.AtomicComposition.Complete()
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.DetermineRejection(ComposablePartDefinition definition, AtomicComposition parentAtomicComposition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.IsRejected(ComposablePartDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.InternalGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.InnerCatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.AggregateExportProvider.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.CompositionContainer.GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.TryGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition, IEnumerable`1& exports)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExports(ImportDefinition definition, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportsCore(Type type, Type metadataViewType, String contractName, ImportCardinality cardinality)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValueCore[T](String contractName, ImportCardinality cardinality)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValue[T](String contractName)
at System.ComponentModel.Composition.Hosting.ExportProvider.GetExportedValue[T]()

--------------------------Inner Exception--------------------------
AggregateException: One or more errors occurred.

NullReferenceException: Object reference not set to an instance of an object.
Stack Trace:
at Microsoft.Internal.Collections.WeakReferenceCollection`1.<CleanupDeadReferences>b__0(WeakReference w)
at System.Collections.Generic.List`1.RemoveAll(Predicate`1 match)
at Microsoft.Internal.Collections.WeakReferenceCollection`1.CleanupDeadReferences()
at Microsoft.Internal.Collections.WeakReferenceCollection`1.Add(T item)
at System.ComponentModel.Composition.Hosting.ImportEngine.StartSatisfyingImports(PartManager partManager, AtomicComposition atomicComposition)
at System.ComponentModel.Composition.Hosting.ImportEngine.EngineContext.Complete()
at System.ComponentModel.Composition.Hosting.AtomicComposition.FinalComplete()

Created Unassigned: AmbiguousMatchException when resolving a class with generic void overloads [14614]

$
0
0
Hi,

To reproduce this problem, consider the following class:

``` C#
public class Test
{
public void Execute() { }

public void Execute<T>() { }
}
```

The following code will fail with an AmbiguousMatchException:

``` C#
var conventions = new ConventionBuilder();

conventions.ForType<Test>().Export();

var container = new ContainerConfiguration()
.WithAssembly(typeof(Test).Assembly, conventions)
.CreateContainer();
```

The stack trace is:

```
System.Reflection.AmbiguousMatchException: Ambiguous match found.
at System.DefaultBinder.SelectMethod(BindingFlags bindingAttr, MethodBase[] match, Type[] types, ParameterModifier[] modifiers)
at System.RuntimeType.GetMethodImpl(String name, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)
at System.Type.GetMethod(String name, Type[] types)
at System.Reflection.RuntimeReflectionExtensions.GetRuntimeMethod(Type type, String name, Type[] parameters)
at System.Composition.Convention.PartConventionBuilder.BuildOnImportsSatisfiedNotification(Type type, List`1& configuredMembers)
at System.Composition.Convention.ConventionBuilder.EvaluateThisTypeInfoAgainstTheConvention(TypeInfo typeInfo)
at System.Composition.Convention.ConventionBuilder.GetCustomAttributes(Type reflectedType, MemberInfo member)
at System.Composition.Convention.AttributedModelProviderExtensions.GetDeclaredAttribute[TAttribute](AttributedModelProvider convention, Type reflectedType, MemberInfo member)
at System.Composition.TypedParts.Discovery.TypeInspector.InspectTypeForPart(TypeInfo type, DiscoveredPart& part)
at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types, AttributedModelProvider attributeContext)
at System.Composition.Hosting.ContainerConfiguration.CreateContainer()
...
```

This affects the current release of MEF 2 (Microsoft.Composition 1.0.27).

Created Unassigned: Bug in Open Generics with IBiz [14615]

$
0
0
In the code below x gets 0 results but it should get one.

```
class Program
{
static void Main(string[] args)
{
var cat = new AssemblyCatalog(typeof (Program).Assembly);
var con = new CompositionContainer(cat);
var x = con.GetExportedValues<Buz<int>>();
}
}

interface IBiz<T, U> { }

[Export(typeof(IBiz<,>))]
class Biz<T, U> : IBiz<T, U> { }

[Export(typeof(Buz<>))]
class Buz<T>
{
public IBiz<T, int> Biz { get; private set; }

[ImportingConstructor]
public Buz(IBiz<T, int> biz)
{
Biz = biz;
}
}
```

New Post: Alternative to icons in ExportMetadata

$
0
0
I have a project that uses the MEF to provide controls from plugins. In order to use display the controls from the plugin to the user I need to have also an icon associated with the control.
Since ExportMetadata can not support icons are there any alternative to this requirement?
Is there a way to know the location of the assembly from where the metadata was loaded?

Created Unassigned: Open Generic types won't register in the catalog on Test Project [14616]

$
0
0
Hi folks, I'm facing the same problem described at http://stackoverflow.com/questions/18147371/open-generic-types-wont-register-in-the-catalog/22114304#22114304.

I use a Library that use MEF. This library is working fine when I use it on Console/Web applications but the catalog doesn't load data when is inside Test project.

Can you guys give me a clue to fix this?

Thanks in advance !!

New Comment on "Standalone Web API dependency resolver using Microsoft.Composition"

$
0
0
Doesn't work with Visual Studio 2013. Useless. Wasted a whole day. Tried MEF Contrib, ASP.NET WEBAPI Contrib, Kenny Tourder's solution, and pretty much all the other buggy attempts. I can't find a single example simple enough to implement so I can use Web API and my current libraries that use Prism MEF. It's more complex than the WCF app.config!!! Isn't that what we're trying to move away from.

Commented Unassigned: Performance issue in SmallSparseInitonlyArray [14611]

$
0
0
Hello,

I have found a significant performance issue when using lost of Shared parts. 50% of composition time is spent inside System.Composition.Hosting.Util.SmallSparseInitonlyArray.Add on string.Format calls. The error is obvious: the method has 2 calls like

```
Assumes.IsTrue(e.Index != index, string.Format("An item with the key '{0}' has already been added.", index));
```

No matter what the condition is, string.Format gets evaluated every time.

So, MEF is spending 50% time on producing garbage. Definitely not the task a high performance framework should do. :)
Comments: Very true - this should be a debug-only assertion, thanks for the note. Hopefully someone on the current team's spotted this one too :) Cheers!

Created Unassigned: Global Container for MEF [14617]

$
0
0
I have a solution file with multiple projects. I have exported a class in a particular project and imported it in the other projects.

Is it necessary to use DirectoryCatalog or is there a way where I can satisfy all the imports without doing this such as a global container on which I can call SatisfyImportsOnce()?

The reason I am working towards this approach is because I do not know where to bootstrap the MEF code.


Viewing all 265 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>