none
How to install "System.Web.Script.Serialization"? RRS feed

  • Question

  • I has a line "using System.Web.Script.Serialization;' in my program but VC# complains

    Severity Code Description Project File Line Suppression State
    Error CS0234 The type or namespace name 'Script' does not exist in the namespace 'System.Web' (are you missing an assembly reference?) ulphoto D:\programs\SmartFace\ulphoto\ulphoto\Form1.cs 12 Active

    How can I do to conquer it?

    Wednesday, June 12, 2019 9:38 AM

Answers

  • I already installed Json.NET and I got suggestion to use that space from https://docs.microsoft.com/en-us/dotnet/api/system.web.script.serialization?view=netframework-4.8

    No, if it's not an ASP.NET solution, and you don't seem to be developing that, becuase you seem do be developing a Windows form based solution a Windows desktop solution, and you should be using the Newtonsoft json namespace. 

    https://www.nuget.org/packages/Newtonsoft.Json/

    Or you could use Json.NET too, other than using the namespace you are talking about, because 'Web' is for Web based solutions and not Windows desktop solutions.

    System.Web.Script.Serialization;

    In the tutorial below, do you see any mentioning of the namespace above you are talking about?

    https://riptutorial.com/json-net


    Wednesday, June 12, 2019 10:45 AM
  • In answer to your original question about why a using statement isn't sufficient.

    A using statement simply brings the identifiers that are defined in a namespace into the current scope so they can be referenced without using the fully qualified namespace name.

    namespace MyBusiness
    {
       public class MyType { }
    }
    
    namespace YourBusiness
    {
       //Error, MyType is not defined in YourBusiness or a parent namespace
       class NotInScope : MyType {}
    
       //OK, compiler knows there isn't a MyBusiness child namespace under YourBusiness but there is a root namespace called MyBusiness with MyType defined in it
       class FullName : MyBusiness.MyType {}  
    }
    
    using namespace MyBusiness;
    
    namespace ThereBusiness
    {
       //OK, the using brings in the identifiers from MyBusiness so MyType can now be found without the namespace qualifier
       public class Fine : MyType {} 
    }
    

    This is all compiler sugar to make your life easier (aka less typing). However the compiler doesn't auto-magically find assemblies during compilation. You must specify the assemblies you reference. If you don't you get the error you're seeing. To add a reference to a framework assembly (look in the docs to know this) right click the project in Solution Explorer and select `Add\Reference`. Then in the Reference dialog on the left side select `Assemblies` and then find the assembly you need (again, look at the docs). Check the box and the assembly is now a reference to the project. You can now use any of the public types within in (via using or fully qualified).

    As for why you would want to use System.Web.Script.Serialization then I don't know why you would. JSON.NET is the most common serializer for now but .NET is adding a formal JSON serializer in .NET Core 3 but in the meantime there is also the DataContractJsonSerializer that is built into the framework.



    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, June 12, 2019 1:49 PM
    Moderator
  • Hi Stan,

    Thank you for posting here.

    For your question, you want to install System.Web.Script.Serialization.

    I recommend you use vs2019, because it automatically recognizes the assembly you need.

    You could look at the following picture.

    Best Regards,

    Jack


    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.


    Thursday, June 13, 2019 2:35 AM
    Moderator
  • System.Web.Script.Serialization will be available after adding System.Web.Extensions reference.
    Thursday, June 13, 2019 8:58 AM
  • System.Web.Script.Serialization will be available after adding System.Web.Extensions reference.
    Thursday, June 13, 2019 8:59 AM

All replies

  • If you are not developing a Web based solution using ASP.NET, then your decision to use the namespace you have mentioned is not correct.

    You should be using Json.NET library.

    https://www.c-sharpcorner.com/UploadFile/manas1/json-serialization-and-deserialization-using-json-net-librar/

    Wednesday, June 12, 2019 9:56 AM
  • I already installed Json.NET and I got suggestion to use that space from https://docs.microsoft.com/en-us/dotnet/api/system.web.script.serialization?view=netframework-4.8
    Wednesday, June 12, 2019 10:00 AM
  • I already installed Json.NET and I got suggestion to use that space from https://docs.microsoft.com/en-us/dotnet/api/system.web.script.serialization?view=netframework-4.8

    No, if it's not an ASP.NET solution, and you don't seem to be developing that, becuase you seem do be developing a Windows form based solution a Windows desktop solution, and you should be using the Newtonsoft json namespace. 

    https://www.nuget.org/packages/Newtonsoft.Json/

    Or you could use Json.NET too, other than using the namespace you are talking about, because 'Web' is for Web based solutions and not Windows desktop solutions.

    System.Web.Script.Serialization;

    In the tutorial below, do you see any mentioning of the namespace above you are talking about?

    https://riptutorial.com/json-net


    Wednesday, June 12, 2019 10:45 AM
  • In answer to your original question about why a using statement isn't sufficient.

    A using statement simply brings the identifiers that are defined in a namespace into the current scope so they can be referenced without using the fully qualified namespace name.

    namespace MyBusiness
    {
       public class MyType { }
    }
    
    namespace YourBusiness
    {
       //Error, MyType is not defined in YourBusiness or a parent namespace
       class NotInScope : MyType {}
    
       //OK, compiler knows there isn't a MyBusiness child namespace under YourBusiness but there is a root namespace called MyBusiness with MyType defined in it
       class FullName : MyBusiness.MyType {}  
    }
    
    using namespace MyBusiness;
    
    namespace ThereBusiness
    {
       //OK, the using brings in the identifiers from MyBusiness so MyType can now be found without the namespace qualifier
       public class Fine : MyType {} 
    }
    

    This is all compiler sugar to make your life easier (aka less typing). However the compiler doesn't auto-magically find assemblies during compilation. You must specify the assemblies you reference. If you don't you get the error you're seeing. To add a reference to a framework assembly (look in the docs to know this) right click the project in Solution Explorer and select `Add\Reference`. Then in the Reference dialog on the left side select `Assemblies` and then find the assembly you need (again, look at the docs). Check the box and the assembly is now a reference to the project. You can now use any of the public types within in (via using or fully qualified).

    As for why you would want to use System.Web.Script.Serialization then I don't know why you would. JSON.NET is the most common serializer for now but .NET is adding a formal JSON serializer in .NET Core 3 but in the meantime there is also the DataContractJsonSerializer that is built into the framework.



    Michael Taylor http://www.michaeltaylorp3.net

    Wednesday, June 12, 2019 1:49 PM
    Moderator
  • Hi Stan,

    Thank you for posting here.

    For your question, you want to install System.Web.Script.Serialization.

    I recommend you use vs2019, because it automatically recognizes the assembly you need.

    You could look at the following picture.

    Best Regards,

    Jack


    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.


    Thursday, June 13, 2019 2:35 AM
    Moderator
  • System.Web.Script.Serialization will be available after adding System.Web.Extensions reference.
    Thursday, June 13, 2019 8:58 AM
  • System.Web.Script.Serialization will be available after adding System.Web.Extensions reference.
    Thursday, June 13, 2019 8:59 AM