Comments (11)
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.
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.
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.
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.
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.
@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.
Thanks Chris. Given that, I would call the behavior you're seeing here expected @WebbertSolutions.
from roslyn.
Ok, I think I understand but for clarity...
- 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?
- 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.
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.
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.
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)
- Collection Expression Compile Error after upgrading to SDK 8.0.3. HOT 4
- Reporting Roslyn analyzer name is inaccessible through Error list entry in VSSDK for VisualStudio 2022 17.10
- Programación HOT 2
- IDE0036 not raised for `protected private` and `internal protected` members HOT 1
- Visual Studio 2022 adds a duplicate "Option Strict On" to Code File When Pasting VB.NET Code HOT 1
- Account for partial properties at existing use sites of partial method symbol APIs HOT 3
- Change Workspace.Option setter to throw NotSupportedException HOT 1
- Version conflict detected for Microsoft.CodeAnalysis.Common Microsoft.CodeAnalysis.CSharp HOT 2
- Adding documents to a VisualStudioWorkspace in a subfolder fails if folder doesn't exist HOT 7
- IDE0100 (Remove unnecessary equality operator) catches `x == false` as redundant HOT 9
- csc.exe hangs on specific file
- Filesystem pollution in `/tmp/` HOT 4
- Adding/Removing space when toggling line comments HOT 2
- Methods with Optional String Parameters Won't Collapse HOT 1
- Method defining line move when adding code before method declaration HOT 1
- Error list goes crazy while doing a refactoring HOT 1
- Version 17.10.0 Preview 5.0 - Error list not showing all warnings HOT 1
- VS 17.10.0 preview 4 shows warnings where no Error is. HOT 1
- C# Syntax highlighting of type references is broken HOT 7
- Custom modifiers are not copied in array type collection expression lowering
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from roslyn.