Forum Xamarin.iOS

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Using HttpUtility.UrlEncode when targeting the 4.6.1 framework

TerryReeseTerryReese USMember ✭✭

I'm stuck. I have a program that uses dotnetrdf for doing SPARQL queries. One of the dependencies in the component is System.Web as it uses HttpUtility.UrlEncode to encode the SPARQL query. I've created a small sample:

void CmdSearch_Activated(object sender, EventArgs e)
        {

            SparqlRemoteEndpoint endpoint = null;

            endpoint = new SparqlRemoteEndpoint(new Uri(txtEndpoint.StringValue));
            //System.Web.Util.HttpEncoder.Current = System.Web.Util.HttpEncoder.Default;

            SparqlResultSet results = endpoint.QueryWithResultSet(txtQuery.Value);
            string _localtmp = "/tmp/saved.json";

            VDS.RDF.Writing.SparqlJsonWriter jwriter = new VDS.RDF.Writing.SparqlJsonWriter();
            jwriter.Save(results, _localtmp);
            string _innerText = System.IO.File.ReadAllText(_localtmp);
            txtResults.Value = _innerText;
        }

And I've attached this sample (it's easier to do this via a small gui to make providing the sparql query easier. I've given you the whole project file, including packages. Anyway -- you can see in the example, I've referenced the 4.6.1 framework -- but when I run the program, what I get is the following exception:

System.NullReferenceException: Object reference not set to an instance of an object
at System.Web.Util.HttpEncoder.GetCustomEncoderFromConfig () [0x00005] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/System.Web/System.Web.Util/HttpEncoder.cs:170
at System.Lazy1[T].CreateValue () [0x00081] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/Lazy.cs:443 at System.Lazy1[T].LazyInitValue () [0x00080] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/Lazy.cs:388
at System.Lazy`1[T].get_Value () [0x0003a] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/Lazy.cs:339
at System.Web.Util.HttpEncoder.get_Current () [0x00007] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/System.Web/System.Web.Util/HttpEncoder.cs:68
at System.Web.HttpUtility.UrlEncodeToBytes (System.Byte[] bytes, System.Int32 offset, System.Int32 count) [0x00005] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/System.Web/System.Web/HttpUtility.cs:425
at System.Web.HttpUtility.UrlEncode (System.String str, System.Text.Encoding e) [0x00094] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/System.Web/System.Web/HttpUtility.cs:368
at System.Web.HttpUtility.UrlEncode (System.String str) [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/System.Web/System.Web/HttpUtility.cs:338
at VDS.RDF.Query.SparqlRemoteEndpoint.QueryInternal (System.String sparqlQuery, System.String acceptHeader) [0x00088] in <71cf6801f6264da1b7babe9e11c2b11a>:0
at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultSet (VDS.RDF.ISparqlResultsHandler handler, System.String sparqlQuery) [0x00008] in <71cf6801f6264da1b7babe9e11c2b11a>:0
at VDS.RDF.Query.SparqlRemoteEndpoint.QueryWithResultSet (System.String sparqlQuery) [0x0000d] in <71cf6801f6264da1b7babe9e11c2b11a>:0
at sparqltest.ViewController.CmdSearch_Activated (System.Object sender, System.EventArgs e) [0x00019] in /Users/reeset/Projects/sparqltest/sparqltest/ViewController.cs:59
at AppKit.ActionDispatcher.OnActivated (Foundation.NSObject sender) [0x00015] in /Users/builder/data/lanes/5489/c4240f3f/source/xamarin-macios/src/AppKit/ActionDispatcher.cs:49
at at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/5489/c4240f3f/source/xamarin-macios/src/AppKit/NSApplication.cs:100
at sparqltest.MainClass.Main (System.String[] args) [0x00007] in /Users/reeset/Projects/sparqltest/sparqltest/Main.cs:10

I'm kind of stuck. I tried add the following link prior to the call into the library:
** System.Web.Util.HttpEncoder.Current = System.Web.Util.HttpEncoder.Default;

But this doesn't seem to have any effect. In fact, as soon as I make this call, the same NullReferenceException is called.

I'm wondering if anyone has any ideas.

Thanks,

--tr

Posts

Sign In or Register to comment.