none
NewGuid() is not recognized by the intellisense in VS 2019 as a valid function RRS feed

  • Question

  • System.Guid does not provide access to NewGuid() function. It is not recognized by intellisence in VS 2019 Professional, v 16.4.29728.190, C#.

    In my new installation of VS 2019 Professional, when tried to create a new Guid in C# code: Guid.NewGuid(), the NewGuid() function was not recognized by intellisense. The message when hovered over 'NewGuid()' was: "The type name 'NewGuid' does not exist in the type 'Guid'". But NewGuid() function exists in the metadata of the System.Guid structure. Do I miss an assembly reference in addition to System (which is the default and should be enough)?



    • Edited by P Tomov Tuesday, February 11, 2020 4:55 PM
    Tuesday, February 11, 2020 4:41 PM

All replies

  • I can not reproduce this in VS Community 2019, Version 16.4.4,
    targetting .NET Framework 4.8 (but his should not make a difference)
    Maybe a namespace mixup?
    Do you also get this when you write
    var guid = System.Guid.NewGuid();
    Guid class is in mscorlib assembly (when targetting the .NET Framework)
    Tuesday, February 11, 2020 5:15 PM
  • Hello,

    This means you don't have a using statement for System e.g.

    using System;

    If you did then the variable would look like this, note how System is greyed out, because the using statement above is there.

    Which means System is not needed.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, February 11, 2020 5:48 PM
    Moderator
  • I have already tried all these approaches you proposed. Thank you.

    I tried both: without and with reference to System. The problem persists.

    Please see the snapshot attached.


    Pavel Tomov


    • Edited by P Tomov Tuesday, February 11, 2020 6:10 PM
    Tuesday, February 11, 2020 6:04 PM
  • I have already tried all these approaches you proposed. Thank you.

    I tried bot without reference and with reference to System. The problem persists.

    Please see the snapshot attached.


    Pavel Tomov

    What type of project is this?

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, February 11, 2020 6:10 PM
    Moderator
  • Please look at this more detailed snapshot showing the problem. Thanks.nks.

    Pavel Tomov

    Tuesday, February 11, 2020 6:24 PM
  • What type of project is this ???

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, February 11, 2020 6:33 PM
    Moderator
  • This is a basic .NET Framework Console project for testing purposes.

    Even after the latest VS 2019 (v 16.4.5) updates this problem persists.

    I don't see this problem in an another VS 2017 installation. The assemblies

    included are the same.


    Pavel Tomov

    Tuesday, February 11, 2020 9:00 PM
  • from your screenshot:
           var guid = new System.Guid.NewGuid();
    that doesn't make any sense.
    Tuesday, February 11, 2020 9:24 PM
    • Try starting Visual Studio in safe mode
    • Try doing other operations in the console project to see if its just the GUID or not.
    • Try opening the VS2019 project in VS2017
    • Try restarting your computer

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, February 11, 2020 9:40 PM
    Moderator
  • Please see the screenshot below. This expression should work. But the problem persists.

    Pavel Tomov

    Tuesday, February 11, 2020 9:40 PM
  • Also try under tools menu just to see if a Guid can be created outside of code.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange


    Tuesday, February 11, 2020 9:45 PM
    Moderator
  • your screenshot still shows invalid syntax.
    Your code tries to create a new object of type NewGuid.
    again: the correct syntax is:
    var guid = System.Guid.NewGuid();

    • Edited by EckiS Tuesday, February 11, 2020 10:15 PM
    Tuesday, February 11, 2020 9:46 PM
  • Tools->Create GUID works fine but the problem in the coding persists. Please see the screenshot.

    Pavel Tomov

    Tuesday, February 11, 2020 10:19 PM
  • Please skip using "new" and use this

    var guid = Guid.NewGuid();

    Or

    var guid = System.Guid.NewGuid();


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Wednesday, February 12, 2020 12:25 AM
    Moderator

  • Hi P Tomov
    Guid.NewGuid method  is a convenient static method that you can call to get a new Guid.
    So you don't need use New keyword.

    Guid g = Guid.NewGuid();

    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 12, 2020 1:33 AM
  • After the latest VS 2019 updates I created a new project and now var guid = Guid.NewGuid() works correctly.

    Thank you for your support.


    Pavel Tomov


    • Edited by P Tomov Wednesday, February 12, 2020 1:56 AM
    Wednesday, February 12, 2020 1:56 AM
  • Hi P Tomov,
    I am glad you have got your solution, we suggest that you mark it as the answer. So it can help other people who have the same problem find a solution quickly.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 12, 2020 2:01 AM