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.

conflict in generated code if imported in multiple projects

See original GitHub issue

im unable to use Mediator.SourceGenerator in project, that is referencing different project which is already using Mediator.SourceGenerator - second project will throw at me this message: (CS0436)

Error CS0436 The type 'MediatorDependencyInjectionExtensions' in 'Mediator.SourceGenerator.Roslyn40\Mediator.SourceGenerator.IncrementalMediatorGenerator\Mediator.g.cs' conflicts with the imported type 'MediatorDependencyInjectionExtensions' in 'ProjectA'. Using the type defined in 'Mediator.SourceGenerator.Roslyn40\Mediator.SourceGenerator.IncrementalMediatorGenerator\Mediator.g.cs'.

(technically it is ‘only’ warning, but i have TreatWarningsAsErrors enabled and therefore my build fails… )

affected types:

Mediator.MediatorOptions
Mediator.MediatorOptionsAttribute
Microsoft.Extensions.DependencyInjection.MediatorDependencyInjectionExtensions

ideas how to fix this:

  • move Mediator.MediatorOptions and Mediator.MediatorOptionsAttribute to Mediator.Abstractions package - they looks like they do not need to be generated
  • generate MediatorDependencyInjectionExtensions in namespace defined by MediatorOptions:Namespace property - this way i can use multiple generated AddMediator() methods

-or-

make all 3 affected classes internal - this will force to call AddMediator method from within project, that generated it but is simple fix

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
michaeljfarrcommented, Jan 9, 2023

Ah, ok - yes that does solve the issue I was having - thanks.

It has meant that all my handlers need to be public accessible to the Program though. They are marked as internal, so I have just included an InternalsVisibleTo(Program) in Assembly1 and Assembly2. This is so the generated Mediator can add the services and associated RequestClassHandlerWrapper.

It would be slightly better if I could keep those handlers private within their respective Assemblies. However, it does seem more convenient to have one source generator. It is not a bother for the moment, my project still isn’t big enough to worry too much about these kinds of things.

Thanks again.

1reaction
CzBuCHicommented, Jan 5, 2023

hello, sorry for late reply

im experimenting with onion architecture / domain driven developement so my project structure is probably wrong …

im using single DI provided by asp.net core. my host project is basically program.cs from aspnet core minimal api template; modules are registered here plan is to have separate modules, that can be enabled in host in random order each module is using mediator internaly for CQRS and exporting extension methods to register itself in host project module may be dependent on another module domain / use internal parts of that module

PS: now im also with te idea of making mediator classses internal - theyere implementation details after all …

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to generate imported code with conflicting method ...
I am working on a software which generates a generic Python source code through a set of inputs(methods and variables) by the user...
Read more >
Resolving dependency conflicts when importing node ...
When resolving an import target in a node module, it is an error to ... For proper external modules, there are no conflicts...
Read more >
MSB3277: Found conflicts between different versions of ' ...
This error occurs during a build when more than one version of the same dependent assembly is referenced in a build of the...
Read more >
Import "[module]" could not be resolvedPylance ...
I am learning a Python book, so I created folder for each chapter to storage code. Working directory is as follows: book └─chapter1 ......
Read more >
Merging Projects - ATLAS.ti 9 Windows - User Manual
Before you merge, the recommendation is that you import all project bundle files first and take a look at the projects. If a...
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