question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Attribute [Export] is exported twice

See original GitHub issue

Here’s my config, I think everything except the last line is irrelevant to the issue at hand:

      var container = new DependencyInjectionContainer(c => c.AutoRegisterUnknown = false);
      container.Configure(c =>
      {        
        // Register one ILogger per container with automatic job context
        c.ExportFactory((IExportLocatorScope scope) => Log.ForContext("Job", scope.ScopeName))
         .Lifestyle.SingletonPerScope();

        c.ExportFactory(A).AsKeyed<IDbConnection>("a");
        c.ExportFactory(B).AsKeyed<IDbConnection>("b");

        c.AddInspector(new ConfigInspector());

        // [Export] from this assembly
        c.ExportAssemblyContaining<JobSchedulerService>().ExportAttributedTypes();
      });

ExportAttributedTypes does export all classes in my assembly that have [Export], or [ExportByInterfaces], etc.

But when I look at activation strategies, or simply at WhatDoIHave output, I notice that all [Export] exports are actually exported twice. They have the AsType: XY line listed twice for every type they are exported as.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ipjohnsoncommented, Jan 6, 2023

Hi @jods4

Version 8 is about removing deprecated code and deprecated targets, I’ll put together list of changes this weekend.

1reaction
jods4commented, Sep 19, 2019

@ipjohnson I was reading the code trying to see if I can figure out why. This is a complex codebase so I might be completely off… but could it be:

  1. CreateExportStrategiesForTypes will process the types found in my assemblies. Notice that this method looks for IExportAttribute and will add those types to exportTypes right here: https://github.com/ipjohnson/Grace/blob/39d4afb781a4b3b1634d33c6fd6b1165aac633a7/src/Grace/DependencyInjection/Impl/ExportTypeSetConfiguration.cs#L357 Because we have types in exportTypes, the method will then call CreateExportStrategyForType, here: https://github.com/ipjohnson/Grace/blob/39d4afb781a4b3b1634d33c6fd6b1165aac633a7/src/Grace/DependencyInjection/Impl/ExportTypeSetConfiguration.cs#L373

  2. CreateExportStrategyForType does two unfortunate things. It exports everything in exportTypes, right here: https://github.com/ipjohnson/Grace/blob/39d4afb781a4b3b1634d33c6fd6b1165aac633a7/src/Grace/DependencyInjection/Impl/ExportTypeSetConfiguration.cs#L402 I think this might be our first AsType export Later it goes on to process attributes here: https://github.com/ipjohnson/Grace/blob/39d4afb781a4b3b1634d33c6fd6b1165aac633a7/src/Grace/DependencyInjection/Impl/ExportTypeSetConfiguration.cs#L421

  3. I’m skipping a few indirections and intermediate methods. The default IActivationStrategyAttributeProcessor will end up right here, inside ProcessClassAttributes: https://github.com/ipjohnson/Grace/blob/e6853c7fb3b23a27824b9b2e17ad860b9b4a403b/src/Grace/DependencyInjection/Impl/ActivationStrategyAttributeProcessor.cs#L126 I think this is where we are AsType exported for the second time

Maybe I found the reason why attributes are exported twice. I am not sure what the fix is, though.

Gut feeling is that exportTypes at step 1 should not conflate exported types and types that are of interest because they have attributes.

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Duplicate Exports
This explains your double exports. Guidelines can be found on section "Using a Custom Export Attribute" from MEF's Documentation in CodePlex ...
Read more >
Why do field values change when exporting from QGIS?
I have a table with two fields which are defined as Double, with a Length of 20 and a Precision of 0. Some...
Read more >
Popup shows the data twice when exporting a specific ...
I've got a problem when exporting a specific layer to OpenLayers with QGIS2Web. This specific layer is a Parcel or Lot and has...
Read more >
Export Attributes
The Export Attributes function exports all selected attribute information from the current MAP Layer to a delimited text file—comma, semi-colon, space or tab ......
Read more >
Does exporting a video twice in premiere pro create ...
Exporting a video twice in Premiere Pro may cause a slight decrease in quality, depending on the compression settings an. Continue reading.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found