Giter Site home page Giter Site logo

Comments (11)

jaredpar avatar jaredpar commented on July 1, 2024

Depending on the computer, you may or may not get constructors returned for private constructors.

Do these private members exist in source or metadata?

from roslyn.

WebbertSolutions avatar WebbertSolutions commented on July 1, 2024

Source. They exist before the generator runs.
The generator gets the information about the constructors and then generates code given what type of parameters and scope it has. The second picture above shows what it looks like.

from roslyn.

333fred avatar 333fred commented on July 1, 2024

Issue with generating code involving Private Constructors

Rather than sharing screenshots, it would be much more helpful if you could just share a dump of the process. You can save a dump from the Debug menu when you're paused on a breakpoint. This will be very helpful as I've been unable to reproduce your failure condition locally.

Issue when running unit tests involving Private Constructors

I'm entirely unsure what you're saying with this part of the issue; why would the debugger have anything to do with the live IDE state? Are you simply running into the fact that VS cannot pick up changes to source generator project references without a restart (and restart of the build servers)? Either way, let's please keep separate issues in separate issues, rather than a single issue, so that we can properly track things.

from roslyn.

WebbertSolutions avatar WebbertSolutions commented on July 1, 2024

Ok. Let's deal with the first: Issue with generating code involving Private Constructors

Here is the dump of the generation issue as requested, however the dump exceeded upload max of 25M.
Had to store on ondrive here: https://1drv.ms/f/c/1e01d4a72dbe2024/Emp2GT-VlG5AmpVE1xlGB8YBB3eNb6wSWh0ySpJRsfEMOQ?e=bt01uN

from roslyn.

333fred avatar 333fred commented on July 1, 2024

Alright, so your source generator is indeed getting PrivateWith from a metadata reference, not from source. Specifically, it's coming from this assembly: D:\Coding\GitHub\SourceGenerators\Generators\GenerateObjectMother\GenerateObjectMotherTest.Models\obj\Debug\net6.0\ref\GenerateObjectMotherTest.Models.dll. private constructors are not put into the ref assemblies. It seems likely that your source generator will need to handle this case in general.

@chsienki, I would have somewhat expected IsRoslynComponent to pass project references as project references, but it looks like that's not the case? Is that expected behavior?

from roslyn.

chsienki avatar chsienki commented on July 1, 2024

@333fred IsRoslynComponent just takes the command line of whatever would be passed to CSC and runs it as the debug target. It doesn't consider project/package references as they dont exist at that level, everything is just a regular reference to an assembly on disk.

from roslyn.

333fred avatar 333fred commented on July 1, 2024

Thanks Chris. Given that, I would call the behavior you're seeing here expected @WebbertSolutions.

from roslyn.

WebbertSolutions avatar WebbertSolutions commented on July 1, 2024

Ok, I think I understand but for clarity...

  1. Because I'm debugging, the process running is the generator. As such, it is then referencing back to the project/DLL where the class code exists, which is being done through metadata. Private constructors are not available in the metadata and that is why INamedTypeSymbol.Constructors is returning an empty list.

Is that correct?

  1. Under normal circumstances where I'm adding the attribute to a class and the generator runs automatically, then I'm in the context of the source and therefore I do have access to the constructor information through INamedTypeSymbol.Constructors.

Is that correct?

from roslyn.

333fred avatar 333fred commented on July 1, 2024

Not quite correct, no. IsRoslynComponent is mimicking the exact semantics you will see with dotnet build. The only time you will see project references as anything other than dll references is in the IDE.

from roslyn.

WebbertSolutions avatar WebbertSolutions commented on July 1, 2024

hmm.... Not sure of the difference in how it runs then.
Either way, I think I understand enough and have an idea how to work around the first issue and will see what I can do on the second.

Thanks for your assistance.

I should also mention, while frustrating at times, I've really enjoyed working with the Source Generator. It has allowed me to do somethings much easier than other ways in the past. Looking forward to seeing what other problems I can solve.

from roslyn.

333fred avatar 333fred commented on July 1, 2024

Thanks for the feedback! Feel free to come talk to us on discord as well: https://discord.gg/csharp, a number of us hang out in the roslyn channel and talk to a lot of people about source generators.

from roslyn.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.