Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 05:10
    davidwengier synchronize #58152
  • 04:28

    dibarbet on main

    Respond to changes in project c… Merge pull request #58195 from … (compare)

  • 04:28
    msftbot[bot] milestoned #58195
  • 04:28
    dibarbet closed #58195
  • 04:23
    jmarolf unlabeled #3994
  • 04:13
    pawchen commented #58194
  • 03:38
    cston review_requested #58203
  • 03:38
    cston review_requested #58203
  • 03:22
    dibarbet auto_merge_enabled #58195
  • 03:18
    CyrusNajmabadi review_requested #57979
  • 03:18
    CyrusNajmabadi review_requested #57979
  • 03:18
    CyrusNajmabadi review_request_removed #57979
  • 03:11
    CyrusNajmabadi synchronize #57979
  • 03:03
    CyrusNajmabadi synchronize #57979
  • 02:56
    CyrusNajmabadi synchronize #57979
  • 02:56
    CyrusNajmabadi synchronize #57979
  • 02:50

    tmat on main

    OmniSharp options (#58208) * C… (compare)

  • 02:50
    msftbot[bot] milestoned #58208
  • 02:50
    tmat closed #58208
  • 02:42
    davidwengier edited #58209
arturohernandez10
@arturohernandez10
@ltcmelo Awesome!!!
still, feel free to create an GH issue if you'd like
thanks @arturohernandez10
Atul Sharma
@atksharma_twitter
Folks - For some reason , After updating to the latest version of roslyn dependencies, the documents are not loading inside the solution after opening the workspace .. Any body else facing this issue ?

Folks - For some reason , After updating to the latest version of roslyn dependencies, the documents are not loading inside the solution after opening the workspace .. Any body else facing this issue ?

These are the version of nugets we are currently using - -Microsoft.Build.Locator 1.4.1
Microsoft.CodeAnalysis.Analyzers 3.3.2
Microsoft.CodeAnalysis.CSharp 3.11.0
Microsoft.CodeAnalysis.CSharp.Workspaces 3.11.0
Microsoft.CodeAnalysis.Workspaces.MSBuild 3.11.0

Hugh Gleaves
@Korporal
VS has always been limited when it comes to being able to rename namespaces, I wonder if VS 2022 will offer improvements in this area...
2 replies
CyrusNajmabadi
@CyrusNajmabadi
can you give an example of what you mean?
Hugh Gleaves
@Korporal
Yes, if I have a new project and I just dream up a temp name like 'HolidayAPI' intending to refine that later, well later, I'd like to open one of the source files and click the namespace name "HolidayAPI" and rename it to say "Nep.Scheduling" but it never lets you, it hates you trying to introduce new periods into the name.
1 reply
I'm sure there are reasons but I wonder if there's scope for revisiting this.
CyrusNajmabadi
@CyrusNajmabadi
you can definitely file suggestion on this.
Hugh Gleaves
@Korporal
alright, I'll do that later, thanks Cyrus.
timiil
@timiil
hi,hi , i am trying do a task:
walk through a Lambda, get all MemberAccessSyntax
ExpressionSyntax es = SyntaxFactory.ParseExpression(expr); //expr is a string
any simple way to walkthough the 'es' that get all MemberAccessExpressionSyntax inside it ? we know that the a great deal of kind XXXXSyntax inside the tree...
Martin Vseticka
@MartyIX

Guys, I'm working on an analyzer which bans some APIs. So it basically goes through syntaxTree.GetRoot().DescendantNodes().OfType<IdentifierNameSyntax>() and checks INamespaceSymbol namespaceSymbol = semanticModel.GetSymbolInfo(node).Symbol?.ContainingNamespace;.

The function that does this is public IEnumerable<(IdentifierNameSyntax, INamespaceSymbol )> FindForbiddenIdentifiers(SemanticModel semanticModel). My implementation of the method does "yield return (node, @namespace);" so that FindForbiddenIdentifiers returns as soon as possible and a diagnostic can be reported to a Visual Studio user. My colleague would prefer FindForbiddenIdentifiers to return a list (as it is computed faster 240ms as opposed to 300ms with yield return- the intervals are taken from unit tests). Is there some recommendation what is better? I would expect that yield return should be used by default as I understand I don't really need an allocation for the returning list but still my implementation is "slower" in total.

Joe4evr
@Joe4evr

@MartyIX first consider: use of yield return will create a compiler-generated state machine, and you'll allocate that at runtime

the difference likely comes from the fact that the List can utilize a struct enumerator and all the items in the list are pre-computed, as opposed to yield return which lazily evaluates the next item in the sequence for every MoveNext

Martin Vseticka
@MartyIX
@Joe4evr Good point. So what is the preferred solution? Or what solution would you pick? (As a rule of thumb rather than "depends on the situation")
12 replies
Bernd Baumanns
@bernd5
If I query the IOperation of an FunctionPointer-InvocationExpressionSyntax, is it intended that I get a "NoneOperation"?
something like: functionPtrVariable(someArg1, someArg2)
I would expect an IInvocationOperation
Jesper Hansen
@jespersh
Hi, I'm having some success with Source Generators and I'm wondering where I can find the generated source in the Solution Explorer? I've been able to F12 to some source, but not all source has a call (signalr hub)
Oh, there in the Dependencies->Analysers->Project-with-source-generator. I swear it wasn't there a moment ago :)
Martin Vseticka
@MartyIX

Hi, I wonder, is it better to have as a rule of thumb:

#1 Dictionary<Key1, Dictionary<Key, Value>>

or

#2 Dictionary <string, Value> where key is string myKey = $"{enumValue1}-{enumValue2}"

?

First variant requires typically more code, the second is typically more comfortable to work with. That's one view. However, I wonder if I keep allocating myKeys again and again or if some string interning is helping me here...?

CyrusNajmabadi
@CyrusNajmabadi
You will keep allocating keys.
2 replies
Alternative 3:
Dictionary<(string key1, string key2), Value>
43 replies
Martin Vseticka
@MartyIX
Thanks!
Hugh Gleaves
@Korporal
I have a solution that contains two projects, a library targeting netstandard 2.0 and a console app targeting .Net 5 that exercises the library.
The library when used from within the console app, generates source code, small files that contain a single class definition.
The console app can include these generated class files and can build and execute the code.
Now I want to dynamically load and execute the generated source within the console app (rather than building the console app with the file included)
But I get compile errors:
(19,34): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Hugh Gleaves
@Korporal
I already add a bunch of references including C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\System.Private.CoreLib.dll and C:\Program Files\dotnet\shared\Microsoft.NETCore.App\5.0.11\netstandard.dll
Hugh Gleaves
@Korporal
ok its working
I basically do dthis
                var colRefLocation = AppDomain.CurrentDomain.GetAssemblies().Single(a => a.GetName().Name == "System.Collections").Location;
                var stdRefLocation = AppDomain.CurrentDomain.GetAssemblies().Single(a => a.GetName().Name == "netstandard").Location;
                var sysrLocation = AppDomain.CurrentDomain.GetAssemblies().Single(a => a.GetName().Name == "System.Runtime").Location;
Antony Male
@canton7
@Korporal Using Roslyn, presumably? Look at https://github.com/jaredpar/basic-reference-assemblies for the correct set of reference assemblies for a given target
jamespgatt
@jamespgatt

Hi there, I have a solution that contains 3 projects:

  • a library (netstandard 2.0) that is using ISourceGenerator
  • a WebAPI project (net5.0) that has some controllers with actions
  • a Test (net5.0 with xunit) that has unit tests

Basically the flow I want to achieve is that the SourceGenerator class will analyse all action methods and generate a sample unit test [fact] for each action method.
However what I am realising is that SyntaxTrees only accesses one executing assembly at a time - i.e. if the source generator is being executed on the Test proj (even with WebAPI proj referenced), syntaxtrees for WebAPI are not accessible.

Is there a way around this?

CyrusNajmabadi
@CyrusNajmabadi
Nope
That's fundamental to analyzer and sg design.
They operate on one compilation at a time.
This models how compilation actually works. When you are compiling a project X, it's dependencies are passed to it as metadata references, not source code.
Yair Halberstadt
@YairHalberstadt
@jamespgatt you shouldn't need syntax trees for what you're doing - just MethodSymbols
jamespgatt
@jamespgatt
Thanks will check it out
suresh palepu
@satyasuresh:matrix.org
[m]

Hi All

I am trying to disable the "SA1101" stylecop warning in .net core

added below line the .ediitorconfig, but still showing the warining

Please help me on this

dotnet_diagnostic.SA1101.severity = none

a

Martin Vseticka
@MartyIX

Guys, I have NLog as dependency in my analyzer: https://github.com/dotnet/roslyn/discussions/56643#discussioncomment-1378880.

Now I wonder about this line <PackageReference Include="NLog" Version="4.7.5" PrivateAssets="all" GeneratePathProperty="true" /> in my analyzer project. Is it recommended to add PrivateAssets="all" or not? My fear is that NLog dependency ends up in CUSTOMER's project by transitivity rule. Is that reasonable fear or is it a nonsense?

Yair Halberstadt
@YairHalberstadt
Why don't you test. Setup a local folder as a nuget source, generate a nuget package and copy to that folder, reference the analayzer froma seperate project, and see what happens.
1 reply
Joe4evr
@Joe4evr
:arrow_up: