Bug 5543 - Linker fails with XmlElement attribute on generic type
Summary: Linker fails with XmlElement attribute on generic type
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.2
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-06-06 02:59 UTC by Matthijs Koopman
Modified: 2012-06-06 14:50 UTC (History)
2 users (show)

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

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 FIXED

Description Matthijs Koopman 2012-06-06 02:59:31 UTC
When using the XmlElementAttribute on a generic type the linker will fail when deploying to device.

When I try to compile and deploy the following class to my iPhone the linker will fail with the error message: "Could not link all assemblies MT2001"

Code that will cause the linker to fail:

[Serializable]
[XmlRoot("rsp", IsNullable = false)]
[MonoTouch.Foundation.Preserve(AllMembers = true)]
public class XmlResult<T>
{
    [XmlAttribute("stat")]
    string StatusCode { get; set; }

    [XmlElement("photos")]
    [XmlElement("photosets")]
    public T Result { get; set; }
}

But when I use this code everything will work fine:

[Serializable]
[XmlRoot("rsp", IsNullable = false)]
[MonoTouch.Foundation.Preserve(AllMembers = true)]
public class XmlResult<T>
{
    [XmlAttribute("stat")]
    string StatusCode { get; set; }

    public T Result
    {
        get { return (ResultWrapper ?? new List<T>()).FirstOrDefault(); }
        set
        {
            (ResultWrapper = new List<T>()).Add(value);
        }
    }

    [XmlElement("photos")]
    [XmlElement("photosets")]
    public List<T> ResultWrapper { get; set; }
}

The error message doesn't give any feedback at all about this failure, just that the linking failed.
Comment 1 Sebastien Pouliot 2012-06-06 13:37:51 UTC
The build output "error MT2001: Could not link assemblies" for generic linker errors.
If you add "-v -v" to your project options you'll have a stack trace (with more details).
Comment 2 Sebastien Pouliot 2012-06-06 14:50:41 UTC
Matthijs, thanks for the test case. Note that using [Preserve] for types decorated with [Xml...Attribute]* is not required anymore (5.1+) -> http://spouliot.wordpress.com/2011/11/12/linker-vs-serialization/

* except [XmlIgnore]

The workaround, until new releases with this fix are available, is not to link the assembly containing this type (e.g. --linkskip=MyAssembly).


master: 5563f6847405c3ffae1e5c7d148e53fc520ad5c4
5.2-series: 78498021f918749035a601fd296f6fa858b002e1
QA: unit tests added in master.