Does not exist in the Namespace - Keeps returning - what am I missing?

William Zorn 5 Reputation points
2023-03-10T17:15:59.4966667+00:00

I'm editing a C# script in Visual Studio for an SSIS package.

 

I have two lines that give me errors:

var tokenResult = JsonSerializer.Deserialize<JsonElement>(result);

var token = new System.IdentityModel.Tokens.Jwt.JwtSecurityToken(accessToken);

 

The first one complains that "JsonSerializer" does not exist in the context and "JsonElement" couldn't be found.

The second has "System.IdentityModel.Tokens.Jwt" does not exist in the namespace.

 

 

If I open the package manager and run the following line, the errors go away and the script compiles cleanly.

PM> Install-Package System.IdentityModel.tokens.Jwt

If I save everything and run the package it fails at the script. Opening the script again reveals the errors are BACK.

Its almost like I'm not committing the changes somehow. Any help would be greatly appreciated. Thanks!

SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,525 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Jack J Jun 24,496 Reputation points Microsoft Vendor
    2023-03-13T02:20:07.5133333+00:00

    @William Zorn, Welcome to Microsoft Q&A,

    The first one complains that "JsonSerializer" does not exist in the context and "JsonElement" couldn't be found.

    For your first error, please install nuget-package System.Text.Json and don't forget to add the using statement on the left-top of your code using System.Text.Json;.

    The second has "System.IdentityModel.Tokens.Jwt" does not exist in the namespace.

    For your second error, I think you have already done for it (install nuget-package System.IdentityModel.Tokens.Jwt).

    The following is my result, which does not have the compiling error:

    User's image

    Hope my solution could help you.

    Best Regards,

    Jack


    If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments