Is Uri available in some other assembly than Syste

2019-08-13 04:12发布

问题:

I am trying to get a bare bones bit of RestSharp into my Windows CE / Compact Framework 3.5 app.

This minimalistic code:

RestClient client = new RestClient("http://192.164.144.42:72921/");
RestRequest request = new RestRequest("api/vendorItems/", Method.GET);
RestResponse response = client.Execute(request) as RestResponse;
string content = response.Content; // raw content as string

...first caused a problem because I had to change this:

RestResponse response = client.Execute(request);

...to this:

RestResponse response = client.Execute(request) as RestResponse;

...but notwithstanding that minor victory, this line still won't compile:

RestRequest request = new RestRequest("api/vendorItems/", Method.GET);

...telling me, "The type 'System.Uri' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=2.0.0.0"

I do have System referenced, but it is version 3.5.0.0 (Runtime version == v2.0.50727)

What can I do to get that line to compile without downgrading my System reference (which would doubtless cause the compiler to squawk about other lines of code)?

UPDATE

In VS 2008, I get lots of err msgs emanating from the compiler scratching its head about new language constructs, such as async things; In VS 2013, I get:

...then:

And in VS 2013 RC it says: "(incompatible) [crlf+Tab] This project is incompatible iwth the current edition of Visual Studio"

回答1:

The latest versions of RestSharp use SimpleJson for serialization and deserialization. SimpleJson doesn't have a CF build, however it does have an FFX 2.0 build so it's pretty close to CF-compliant. There are a few TryParse calls that you have to replace, but all-in-all not bad.

My suggestion is to:

  1. Pull the RestSharp source from GitHub
  2. Create a brand-new Smart Device project targeting CF 3.5 called RestSharpCF or whatever
  3. Add the existing code files from the RestSharp root folder to your project
  4. Compile
  5. Fix the compiler errors
  6. Iterate on 4 & 5 until it actually builds clean
  7. Deploy
  8. Do a pull request to get your changes back into the stream. Forewarning, your have to pull request back to SimpleJson, not RestSharp.

I'll likely do these steps myself in the next month or so (I've got through #7 actually, but I also have other changes and additions as well) but it's probably not best to hang out waiting on me to find time for this. I have to finish an ORM implementation that is using RestSharp to make sure I have all the needed changes before I'll do my pull request.