Bug 12565 - System.NullReferenceException:... with System.Web.HttpUtility.HtmlDecode
Summary: System.NullReferenceException:... with System.Web.HttpUtility.HtmlDecode
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: Master
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: master
Assignee: Timothy Risi
URL:
Depends on:
Blocks:
 
Reported: 2013-06-05 17:18 UTC by Gustavo Torrico
Modified: 2016-07-20 19:02 UTC (History)
5 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test Application with the problem (22.93 KB, application/x-zip-compressed)
2013-06-05 17:18 UTC, Gustavo Torrico
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED NOT_ON_ROADMAP

Description Gustavo Torrico 2013-06-05 17:18:17 UTC
Created attachment 4077 [details]
Test Application with the problem

At time to use System.Web.HttpUtility.HtmlDecode(string); in an application with the Mono Runtime included in the bundle, the method raises this exception:
Unhandled Exception::
    System.NullReferenceException: Object reference not set to an instance of an object
      at System.Web.Util.HttpEncoder.GetCustomEncoderFromConfig () [0x00000] in <filename unknown>:0 
      at System.Lazy`1[System.Web.Util.HttpEncoder].InitValue () [0x00000] in <filename unknown>:0 
    [ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object
      at System.Web.Util.HttpEncoder.GetCustomEncoderFromConfig () [0x00000] in <filename unknown>:0 
      at System.Lazy`1[System.Web.Util.HttpEncoder].InitValue () [0x00000] in <filename unknown>:0 

The problem can be solved adding this line before the call to the method:
HttpEncoder.Current = HttpEncoder.Default;
Comment 1 Sebastien Pouliot 2013-06-06 08:26:16 UTC
This is another case where System.Configuration is used. In this case it's not a linker issue (it fails without linking) but the fact that a .config file was not found to instruct System.Configuration on how to setup the decoder.

Still that code is not linker friendly (even with a valid .config file it would not work*) as it's based on config files and reflection). This dependency (on System.Configuration) was removed from iOS and Android products (the "mobile" profile) for this specific reason.

Note: a future version of the BCL will ship with Xamarin.Mac without a dependency on System.Configuration.

* without some workaround (like preserving additional types or your own, which sets a value, bypassing the configuration).
Comment 2 Aaron Bockover [MSFT] 2013-09-26 13:12:22 UTC

*** This bug has been marked as a duplicate of bug 12466 ***
Comment 3 Chris Hamons 2016-07-20 19:02:02 UTC
Modern Xamarin.Mac application support two different target frameworks:

https://developer.xamarin.com/guides/mac/advanced_topics/target-framework/

only one of which supports Linking, mobile. Mobile does not support System.Configuration, so this bug really only affects:

- Classic Applications
- Who have the linker enabled

which is not the most supported configuration.

Patching up this use case in Classic is not on our roadmap.

Please consider migrating to Xamarin.Mac Unified Mobile.