Json does not exist in the namespace System - json

In this tutorial: http://www.asp.net/web-api/videos/getting-started/custom-validation Jon uses
dynamic error = new JsonObject();
with
using System.Json;
I guess it's the JsonObject here: http://msdn.microsoft.com/en-us/library/system.json.jsonobject(v=vs.110).aspx located in:
Namespace: System.Json
Assembly: System.Runtime.Serialization (in System.Runtime.Serialization.dll)
I've added System.Runtime.Serialization a reference but still cannot find System.Json.
Am I reading the Microsoft docs wrong? (I'm using .NET 4.5)

Try this:
PM> Install-Package System.Json -Version 4.0.20126.16343
Per: http://nuget.org/packages/System.Json
It worked!
If you have questions on how to add enter nuget code, please follow the link below:
http://docs.nuget.org/docs/start-here/using-the-package-manager-console

http://www.webcosmoforums.com/asp/32551-type-namespace-name-json-does-not-exist-namespace-system-runtime-serialization.html
Most likely you are missing a reference to System.ServiceModel.Web
Make sure your application is targeting the .Net 4.5 framework in the project properties.
The System.Json objects are only available in 4.5
Edit:
Use Nuget to install system.json : 'Install-Package System.Json'
How to parse JSON without JSON.NET library?

The Json object works only from Controller class and not outside. Even if we refer System.Web.MVC outside controller, we have access only to JsonResult and not to Json as Json object is protected object of JsonResult. Please refer the below documentation which explains that,
http://msdn.microsoft.com/en-us/library/dd504936(v=vs.118).aspx

If you want to use other .Net json serializer, you can use the following:
go to manage nuget package.
search json.net.
click install.
for more details, follow - http://netfx.codeplex.com/

Using System.json will not work for .Net 4 framework. The library is deprecated.
To check it try:
Go Add reference... to project.
On .Net Tab, Search System.json, you will not find any.
That means, it is deprecated.

Related

Library class doesn't know of ConfigureWebHostDefaults extension method

I'm building a suite of REST micro-services using .Net Core 3.0 Preview 6. All these services will have the same start up logic. So, I'm trying to place all the code in a .Net Standard library.
The goal is to have the IHostBuilder:CreateHostBuilder method, as well as the Startup:Configure and Startup:ConfigureServices class and methods in the library. The library will also contain error handling logic, customized http response messages, etc.
However, I can't seem to find the correct package that contains the ConfigureWebHostDefaults method. I tried adding the Microsoft.AspNetCore package 2.2.0, but that didn't resolve the issue.
I added the Microsoft.Extensions.Hosting (3.0.0-preview-6) package, that also doesn't resolve the issue.
Is what I'm attempting even possible?
Thanks
-marc
I resolved it, not the best way, but it works. I decided to make the library targeted specifically for .NET Core 3.0. So, I changed the targetframework in the project file. That change automatically resolved my other issue.
Import the Microsoft.AspNetCore package, and use WebHost.CreateDefaultBuilder() instead. According to the code it is built from, both CreateDefaultBuilder() and ConfigureWebHostDefaults() call the same internal method: ConfigureWebDefaults().
The only downside of this is that the returned host will be an IWebHost instead of an IHost.

'Application' doesn't exist in System.Windows namespace (in library project)

I'm working on .net standard 2.0 library project for my solution.
It have to include this method:
public Task ShutdownAsync()
{
Application.Current.Shutdown();
}
Problem is it gives me an error:
The name 'Application' does not exist in the current context
It also doesn't exist in System.Windows.
As answers to similar questions suggests I tried to add reference to PresentationFramework. But it isn't on the list.
Looks like it have something to do with the fact I'm doing it in a library project targeted at .net standard 2.0.
Is here any way to add proper reference to this project?
.Net standard 2.0 was the problem.
This class is platform-specific so I should target .Net Platform instead.

Unable to find ProcessingReport class in the Json-schema-validator 2.1.6 but the method JsonSchema.validate returns an object of that type

I am trying to validate a json schema using the json-schema-validator 2.1.6. The class JsonSchema has a method validate(jsonfile) which returns the class ProcessingReport but there is no as ProcessingReport or i am not able to spot it. I tried with 2.1.8 as well but same issue. Can anyone who has used it before pt out what i am missing ?
ProcessingReport report; // No such Class is present in the jar
report = schema.validate(good);
This code is given in one of there examples.
I got the jar from here . I was looking for the version 2.0.1 (which is the stable version) but there was no binary available of that version so i am forced to use a development version.
The ProcessingReport class is present in json-schema-core ( http://fge.github.io/json-schema-core/stable/index.html )
You'll need to add https://github.com/fge/json-schema-core binaries to your path.

JObject jo = new JObject() (Windows Phone 8)

I'm looking for some information about how to work with Azure Mobile Services, in a Windows Phone Client. As we can check at this link, there's some examples about how to work with mobile services.
In my case, I want to delete an ID from my SQL database. For this, we can use the example code from MSDN Documentation:
JObject jo = new JObject();
jo.Add("Id", "37BBF396-11F0-4B39-85C8-B319C729AF6D");
await table.DeleteAsync(jo);
When i paste this code into my function, I cant compile it because JObject.
This is the error I got at JObject jo = new JObject(); line:
The type or namespace name 'JObject' could not be found (are you missing a using directive or an assembly reference?)
I just can't instance a new JObject object, but the Newtonsoft.JSON are referred in my project. So I think it should work fine, but I cant instance a JObject.
This JObject class belongs to JSON.NET library (Newtonsoft).
Here's the full namespace:
Newtonsoft.Json.Linq.JObject
If you can't compile, probably you don't have the JSON.NET library in your project. Add Newtonsoft library to your project using Nuget Package.
In your VS, open your solution, open the menu Tools -> Library package manager -> package manager console
PM> Install-Package Newtonsoft.Json
When working with Windows Azure Mobile Services and Windows Phone 8. I recommend on starting from downloading the template project right from Mobile Service dashboard.
If you want to use existing project then follow the guide from dashboard how to get started.

How to set the read and write providers for JSON using JAX-RS in Apache Tomee plus

I can return simple text from my Pojo but it fails when I changed to return JSON. I have the correct annotations for produces and consumes in my methods and I checked that the content negotation between Jquery and the server is correct.
It seems to be that the conversion to JSON just fails. I copied the Jackson jars in webapps/tomee/lib. I also tried the lib folder of my application.
The error message when doing a GET:
No message body writer has been found for response class <myClass>
This error is fired by the JAXRSOut Intercepter class
The error when doing a Post is:
No message body reader has been found for request class <myClass>
This error is fired by the JAXRSUtils class
Thanks
I made this work by listing the JAX-RS providers in conf/system.properties file of TomEE. Then I added the jars to TomEE's lib folder. The documentation in the website states that one should drop the jars on webapp/tomee/lib, but that did not work for me.
conf/system.properties
openejb.cxf.jax-rs.providers = org.codehaus.jackson.jaxrs.JacksonJsonProvider, org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider
Jars I dropped:
jackson-mapper-asl-1.9.9.jar
jackson-core-asl-1.9.9.jar
jackson-jaxrs-1.9.9
If you use jersey you could try Genson library http://code.google.com/p/genson/.
Latest version 0.92 provides automatic detection of json support in jax-rs web services with jersey.
You should only have to drop the jar and voila! :)