General Discussion

Support for C# source generators?

Started by niklaslundberg on 22,786 views

It doesn't seem like there is any interest in fixing this, making NCrunch unfortunately unusable for us. Maybe we will renew our licenses if it ever gets implemented, but this lack of responsiveness is worrying.
tkarlsen wrote:It doesn't seem like there is any interest in fixing this, making NCrunch unfortunately unusable for us. Maybe we will renew our licenses if it ever gets implemented, but this lack of responsiveness is worrying.


Would you be interested in providing us with a working sample solution that uses the latest version of source generation to produce working code?

I ask this as we again attempted to implement support for this feature about 3 weeks ago and had no luck in actually building a test solution that we could work with. Presently, MS's documentation for this area is lacking in consistency and the whole of source generation has a distinctly 'preview' feel to it. This is a new area and there's a lot we don't understand about it. If you have this working well for you, we'd really appreciate your support in helping us replicate this so that we can extend NCrunch support to it.
Hi @Remco,

Are you still looking for a working solution with the problem? I can probably cook one up if that helps.
Source generators have just been introduced in our solution, and I now find myself in the same situation as tkarlsen, with NCrunch now being simply unusable :-(.
ndeslandes wrote:
Are you still looking for a working solution with the problem? I can probably cook one up if that helps.
Source generators have just been introduced in our solution, and I now find myself in the same situation as tkarlsen, with NCrunch now being simply unusable :-(.


Yes!! We still need a self contained code sample that can work with source generators (and make NCrunch fail). It must be the latest version of the tooling. Our attempts on this side to build such a sample have so far failed.
Remco wrote:
ndeslandes wrote:
Yes!! We still need a self contained code sample that can work with source generators (and make NCrunch fail). It must be the latest version of the tooling. Our attempts on this side to build such a sample have so far failed.


Cool; there you go: https://github.com/nicodeslandes/SourceGenApp

That's about as basic as it gets; it has a console app and an NUnit project that both use the "CodeGenerator" project in the solution to generate a "HelloWorldGenerated.HelloWorld" class that gets called by them.

Visual studio and dotnet test are both fine with it. NCrunch fails to build both projects:
The name 'HelloWorldGenerated' does not exist in the current context

Edited

Would you be interested in trying the build below? We've implemented handling for the source generation. Note that it presently isn't possible for NCrunch to instrument the source generating project or track code coverage in it.

NCrunch_Console_4.9.0.3.msi
NCrunch_Console_4.9.0.3.zip
NCrunch_GridNodeServer_4.9.0.3.msi
NCrunch_GridNodeServer_4.9.0.3.zip
NCrunch_LicenseServer_4.9.0.3.zip
NCrunch_VS2010_4.9.0.3.msi
NCrunch_VS2010_4.9.0.3.zip
NCrunch_VS2012_4.9.0.3.msi
NCrunch_VS2012_4.9.0.3.zip
NCrunch_VS2013_4.9.0.3.msi
NCrunch_VS2013_4.9.0.3.zip
NCrunch_VS2015_4.9.0.3.msi
NCrunch_VS2015_4.9.0.3.msi.7z
NCrunch_VS2015_4.9.0.3.zip
NCrunch_VS2017_4.9.0.3.msi
NCrunch_VS2017_4.9.0.3.msi.7z
NCrunch_VS2017_4.9.0.3.zip
NCrunch_VS2019_4.9.0.3.msi
NCrunch_VS2019_4.9.0.3.msi.7z
NCrunch_VS2019_4.9.0.3.zip
NCrunch_VS2022_4.9.0.3.msi
NCrunch_VS2022_4.9.0.3.msi.7z
NCrunch_VS2022_4.9.0.3.zip


We're hoping to push this out as the official 4.9 release very soon, so it would be great if you could confirm whether it is working for you.
Great, thanks Remco!

It worked fine on my solution. I'm just getting these warnings, but they don't seem to cause any issues:


Microsoft.Net.Compilers Nuget package references are not currently supported by NCrunch.

Edited

Note that it presently isn't possible for NCrunch to instrument the source generating project or track code coverage in it.


Probably related, but another thing that's not working is that when a change is made to the generator, the "run impacted test" mode doesn't pick up the tests that need to be rerun.
Thanks for confirming! I don't think the compiler packages warning is related to this work. If you aren't getting any errors, it's nothing to worry about. There are use cases related to the compiler packages that can cause NCrunch to bomb out with weird errors. If you aren't seeing these, then you can ignore the warning.

ndeslandes wrote:
Probably related, but another thing that's not working is that when a change is made to the generator, the "run impacted test" mode doesn't pick up the tests that need to be rerun.


This is to be expected. Right now we don't have a way to instrument the generator assemblies, as the build system for these projects doesn't seem to support having references to additional assemblies. You'll need to manually execute your tests after changing the source generator, or rely on the automatic/aggressive execution mode instead.

Remco wrote:Would you be interested in trying the build below? We've implemented handling for the source generation. Note that it presently isn't possible for NCrunch to instrument the source generating project or track code coverage in it.

NCrunch_Console_4.9.0.3.msi
NCrunch_Console_4.9.0.3.zip
NCrunch_GridNodeServer_4.9.0.3.msi
NCrunch_GridNodeServer_4.9.0.3.zip
NCrunch_LicenseServer_4.9.0.3.zip
NCrunch_VS2010_4.9.0.3.msi
NCrunch_VS2010_4.9.0.3.zip
NCrunch_VS2012_4.9.0.3.msi
NCrunch_VS2012_4.9.0.3.zip
NCrunch_VS2013_4.9.0.3.msi
NCrunch_VS2013_4.9.0.3.zip
NCrunch_VS2015_4.9.0.3.msi
NCrunch_VS2015_4.9.0.3.msi.7z
NCrunch_VS2015_4.9.0.3.zip
NCrunch_VS2017_4.9.0.3.msi
NCrunch_VS2017_4.9.0.3.msi.7z
NCrunch_VS2017_4.9.0.3.zip
NCrunch_VS2019_4.9.0.3.msi
NCrunch_VS2019_4.9.0.3.msi.7z
NCrunch_VS2019_4.9.0.3.zip
NCrunch_VS2022_4.9.0.3.msi
NCrunch_VS2022_4.9.0.3.msi.7z
NCrunch_VS2022_4.9.0.3.zip


We're hoping to push this out as the official 4.9 release very soon, so it would be great if you could confirm whether it is working for you.


Thanks Remco. Unrelated to source generators as I'm not using them, but on this build the engine process is crashing almost immediately after loading all projects (in both VS2019 and VS2021). I've submitted a bug report via the menu.

Edited

jschreuder wrote:
Thanks Remco. Unrelated to source generators as I'm not using them, but on this build the engine process is crashing almost immediately after loading all projects (in both VS2019 and VS2021). I've submitted a bug report via the menu.


Thanks for sharing these reports. You may have just saved a great many people a lot of pain.

I'm sifting through the logs but cannot find a clear reason for why the engine process is crashing on you. I think this might be something more systemic. If this is still happening consistently for you, could you check the memory consumption of the process during your initialisation, and examine the contents of your windows event viewer to see if there is more detailed error information? I'm wondering if this might be an OutOfMemoryException or something similarly traumatic.

It would also be great if you could confirm whether this build of NCrunch works for you on different solutions (i.e. smaller ones). We aren't able to reproduce this issue on our side, so right now the focus is on narrowing it down. I really appreciate your help on this. I was hoping to release 4.9 today but will hold it back until we can be sure of shipping it without a critical crash issue.
Remco wrote:
jschreuder wrote:
Thanks Remco. Unrelated to source generators as I'm not using them, but on this build the engine process is crashing almost immediately after loading all projects (in both VS2019 and VS2021). I've submitted a bug report via the menu.


Thanks for sharing these reports. You may have just saved a great many people a lot of pain.

I'm sifting through the logs but cannot find a clear reason for why the engine process is crashing on you. I think this might be something more systemic. If this is still happening consistently for you, could you check the memory consumption of the process during your initialisation, and examine the contents of your windows event viewer to see if there is more detailed error information? I'm wondering if this might be an OutOfMemoryException or something similarly traumatic.

It would also be great if you could confirm whether this build of NCrunch works for you on different solutions (i.e. smaller ones). We aren't able to reproduce this issue on our side, so right now the focus is on narrowing it down. I really appreciate your help on this. I was hoping to release 4.9 today but will hold it back until we can be sure of shipping it without a critical crash issue.


FWIW I've been using 4.9.0.1 for a couple of weeks in VS2019 with no issues, so maybe something in .2 / .3?

I'll try a reinstall and reboot, and also try on some smaller projects too and see if that helps.
Remco wrote:
jschreuder wrote:
Thanks Remco. Unrelated to source generators as I'm not using them, but on this build the engine process is crashing almost immediately after loading all projects (in both VS2019 and VS2021). I've submitted a bug report via the menu.


Thanks for sharing these reports. You may have just saved a great many people a lot of pain.

I'm sifting through the logs but cannot find a clear reason for why the engine process is crashing on you. I think this might be something more systemic. If this is still happening consistently for you, could you check the memory consumption of the process during your initialisation, and examine the contents of your windows event viewer to see if there is more detailed error information? I'm wondering if this might be an OutOfMemoryException or something similarly traumatic.

It would also be great if you could confirm whether this build of NCrunch works for you on different solutions (i.e. smaller ones). We aren't able to reproduce this issue on our side, so right now the focus is on narrowing it down. I really appreciate your help on this. I was hoping to release 4.9 today but will hold it back until we can be sure of shipping it without a critical crash issue.


Reinstall and reboot didn't help - I initially suspected it might be due to the file locking issue I got when installing originally but it seems not.

There's nothing in Event Viewer when the process ends, so maybe it's not crashing?

Memory usage seems unlikely - system memory is sitting at 40% used.

I have tried a couple of smaller solutions in 2022 and both work without any issue.

My other thought was that maybe it was a corrupt cache or something, so I wiped the NCrunch cache directory completely, but the issue still happens on this particular solution of about 90 projects. The .crunchsolution.cache file did get generated before the process dies if that helps?

Based on the UI, it seems like it's dying at the "building..." stage, at least based on what the tests panel is telling me.

I'm going to try .1/.2 in 2019 and see if that narrows it down at all for you

Edited

Does setting your 'Max number of processing threads' setting to significantly lower value make any difference?
Remco wrote:Does setting your 'Max number of processing threads' setting to significantly lower value make any difference?


Unfortunately not. Setting this value to 1 did not seem to have any effect. I assume changing CPU cores assigned to NCrunch probably won't help either then?

I've tried all the combinations for older versions, here's the rundown:

VS2019
4.9.0.1 - working
4.9.0.2 - crashing
4.9.0.3 - crashing

VS2022
4.9.0.1 - N/A
4.9.0.2 - crashing
4.9.0.3 - crashing

So it looks like something between 4.9.0.1 and 4.9.0.2.

Contrary to my earlier bug report, VS2022 does appear to restart the engine process in a loop now. I'm not sure why it wasn't doing that when I first tried.

EDIT: I think I have made some sort of progress narrowing it down. Using a default .ncrunchsolution / .ncrunchsolution.user file does not produce the issue. I'll see if I can work out if it's a particular option.

Edited

jschreuder wrote:EDIT: I think I have made some sort of progress narrowing it down. Using a default .ncrunchsolution / .ncrunchsolution.user file does not produce the issue. I'll see if I can work out if it's a particular option.


Alright, I think I've narrowed it down. For this solution I'm using a custom build property TargetFrameworks = net48 to exclude any non-net48 projects from NCrunch and also skip cross-targeted netstandard building.
This was working ok in the earlier build but it seems like something is up with newer builds where this isn't working properly?

If I remove this setting (and only this setting) from .ncrunchsolution.user, the build engine doesn't crash or whatever it's doing. With it, it does.

Hope that helps @Remco!

Edited

jschreuder wrote:
jschreuder wrote:
Alright, I think I've narrowed it down. For this solution I'm using a custom build property TargetFrameworks = net48 to exclude any non-net48 projects and also cross-targeted projects (netstandard / net48) from NCrunch.
This was working ok in early builds but it seems like something is up with newer builds where this isn't working properly?


Gotcha!!!

As you posted this, I was just writing up a reply with a theory that our settings file sync could be causing this, and I was going to lead you down a path of removing settings files to figure out which setting was causing the problem. You beat me to the punch.

This is making sense to me now. I'm going to try and build a use case to reproduce it.
Thanks again for your help. Would you be interested in trying the build below to see if this works for you?

NCrunch_Console_4.9.0.4.msi
NCrunch_Console_4.9.0.4.zip
NCrunch_GridNodeServer_4.9.0.4.msi
NCrunch_GridNodeServer_4.9.0.4.zip
NCrunch_LicenseServer_4.9.0.4.zip
NCrunch_VS2010_4.9.0.4.msi
NCrunch_VS2010_4.9.0.4.zip
NCrunch_VS2012_4.9.0.4.msi
NCrunch_VS2012_4.9.0.4.zip
NCrunch_VS2013_4.9.0.4.msi
NCrunch_VS2013_4.9.0.4.zip
NCrunch_VS2015_4.9.0.4.msi
NCrunch_VS2015_4.9.0.4.msi.7z
NCrunch_VS2015_4.9.0.4.zip
NCrunch_VS2017_4.9.0.4.msi
NCrunch_VS2017_4.9.0.4.msi.7z
NCrunch_VS2017_4.9.0.4.zip
NCrunch_VS2019_4.9.0.4.msi
NCrunch_VS2019_4.9.0.4.msi.7z
NCrunch_VS2019_4.9.0.4.zip
NCrunch_VS2022_4.9.0.4.msi
NCrunch_VS2022_4.9.0.4.msi.7z
NCrunch_VS2022_4.9.0.4.zip
Remco wrote:Thanks again for your help. Would you be interested in trying the build below to see if this works for you?

NCrunch_Console_4.9.0.4.msi
NCrunch_Console_4.9.0.4.zip
NCrunch_GridNodeServer_4.9.0.4.msi
NCrunch_GridNodeServer_4.9.0.4.zip
NCrunch_LicenseServer_4.9.0.4.zip
NCrunch_VS2010_4.9.0.4.msi
NCrunch_VS2010_4.9.0.4.zip
NCrunch_VS2012_4.9.0.4.msi
NCrunch_VS2012_4.9.0.4.zip
NCrunch_VS2013_4.9.0.4.msi
NCrunch_VS2013_4.9.0.4.zip
NCrunch_VS2015_4.9.0.4.msi
NCrunch_VS2015_4.9.0.4.msi.7z
NCrunch_VS2015_4.9.0.4.zip
NCrunch_VS2017_4.9.0.4.msi
NCrunch_VS2017_4.9.0.4.msi.7z
NCrunch_VS2017_4.9.0.4.zip
NCrunch_VS2019_4.9.0.4.msi
NCrunch_VS2019_4.9.0.4.msi.7z
NCrunch_VS2019_4.9.0.4.zip
NCrunch_VS2022_4.9.0.4.msi
NCrunch_VS2022_4.9.0.4.msi.7z
NCrunch_VS2022_4.9.0.4.zip


Can confirm this build is working well on both 2019 and 2022, thanks Remco!
Seams the problem is back with https://github.com/nicodeslandes/SourceGenApp and 4.11.0.2 in VisualStudio 2022 Preview :(

Post a reply

Log in to reply.