FastEndpoints: ReflectionGenerator generates and uses wrong namespaces for multi-project solution

I am doing a PoC for a solution that has an SDK project library per Feature (not packable).

Features\Feature1 Features\Feature2 Features\Feature3 Features\Feature4 Features\Feature5 Features\Feature6 Features\Feature7 Api

Each Feature references FastEndpoints.Generation package. Api references all of the Feature* projects, but doesn’t have to.

When trying to build Api project occasionally there is a hiccup where generated ReflectionData.g.cs for some features ends up using namespaces of another feature (either class level namespace and/or the using t0 = ). Happens with CLI dotnet build and VS2022.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 17 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@SjorsGoering your problem seems to be a different one. tomorrow i’ll update the discovered types generator to get rid of the static stuff there. only had the time to update the reflection source generator today.

@omon77 can you pls try v5.35.0.602-beta and let me know if it’s sorted now? haven’t had a chance to look at your repro project yet. i don’t have visual studio, so it would be best if you can give the latest beta a shot with visual studio.

v5.35.0.602-beta also seems to fix for me the build errors related to the Source Generator for ‘DiscoveredTypes’.

@dj-nitehawk, I believe this is fixed with v5.35.0.602-beta!

Thank you!!!

P.S. Also, it wasn’t just in VS2022, btw. Doing dotnet build via CLI was having the same effect.

thanks will have a look as soon as #909 is completed.

@SjorsGoering did v5.35.0.3-beta improve anything at all for you? just trying to figure out if it’s something in @omon77 's environment/setup that’s causing the trouble.

source generators are a bloody pain in the *ss. pain to make, pain to maintain, pain to troubleshoot. 😒

Perhaps the issue is not with the generators, but either the 9.0.200 SDK or Roslyn or all of the above…

After a while of trying different things and building and rebuilding in IDE and command line, my machine became unresponsive and CPU was pinned at 100%. With few hundred “.NET Host” background processes, that kept spawning up on their own, with IDE closed.

Image

After killing them all (via taskkill /FI "IMAGENAME eq dotnet.exe" /F) and trying again, I noticed that the dependencies (the Features* projects) were being built in parallel (observed from CLI build).

Doing some research, what seems to help, is to set environment variable: MSBUILDDISABLENODEREUSE = 1.

This setup results in consistent builds from CLI and mostly stable builds in IDE.

Another item to consider was the post-build step for swagger generation, taken verbatim from documentation as dotnet run --exportswaggerjson true

That was triggering the rebuild and exhaserbating the issue… Changing it to dotnet $(OutputPath)/$(AssemblyName).dll --exportswaggerjson true (along with the environment variable) seems to have made it more stable…

If anyone needs the post-build step, here it is:

    <Target Name="PostBuild" AfterTargets="Build">
      <Exec Command="dotnet $(OutputPath)/$(AssemblyName).dll --exportswaggerjson true" />
    </Target>

You might want to keep this issue open for a bit to see if anyone else has similar experiences or can provide a bit more info.

I also noticed this issue since a while. Cleaning and rebuilding the solution makes the issue disappear after some attempt. My solution structure looks something like this: Host (.Net 9.0)

  • Invoicing (CommandHandlers and EventHandlers)
    • Invoicing.Contracts (Commands, Events and result classes)
  • Ordering (CommandHandlers and EventHandlers)
    • Ordering.Contracts (Commands, Events and result classes)

I’ll see later if I can create a minimal zip with the reproducible issue.