question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

System.InvalidOperationException: System.Xml.Linq.XElement cannot be used as: 'xml text'

See original GitHub issue

Hi. Im running into the same problem as #2150 .

System.InvalidOperationException: There was an error reflecting type ‘ZregService.ManifestType’. —> System.InvalidOperationException: There was an error reflecting property ‘Reference’. —> System.InvalidOperationException: There was an error reflecting type ‘ZregService.ReferenceType’. —> System.InvalidOperationException: There was an error reflecting property ‘DigestMethod’. —> System.InvalidOperationException: There was an error reflecting type ‘ZregService.DigestMethodType’. —> System.InvalidOperationException: There was an error reflecting property ‘Any’. —> System.InvalidOperationException: There was an error reflecting type ‘System.Xml.Linq.XElement’. —> System.InvalidOperationException: System.Xml.Linq.XElement cannot be used as: ‘xml text’. at System.Xml.Serialization.XmlReflectionImporter.CheckContext(TypeDesc typeDesc, ImportContext context) at System.Xml.Serialization.XmlReflectionImporter.ImportSpecialMapping(Type type, TypeDesc typeDesc, String ns, ImportContext context, RecursionLimiter limiter) at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel, RecursionLimiter limiter) — End of inner exception stack trace —

Here is the wsdl wsdl.zip

And here is the generated reference Reference.zip

Seems like it does not like the System.Xml.Linq.XElement Any properties like in:


    [System.CodeDom.Compiler.GeneratedCodeAttribute("dotnet-svcutil","0.5.0.0")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.w3.org/2000/09/xmldsig#")]
    public partial class DigestMethodType
    {
        
        private System.Xml.Linq.XElement[] anyField;
        
        private string algorithmField;
        
        /// <remarks/>
        [System.Xml.Serialization.XmlTextAttribute()]
        [System.Xml.Serialization.XmlAnyElementAttribute(Order=0)]
        public System.Xml.Linq.XElement[] Any
        {
            get
            {
                return this.anyField;
            }
            set
            {
                this.anyField = value;
            }
        }
        
        /// <remarks/>
        [System.Xml.Serialization.XmlAttributeAttribute(DataType="anyURI")]
        public string Algorithm
        {
            get
            {
                return this.algorithmField;
            }
            set
            {
                this.algorithmField = value;
            }
        }
    }

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ps2goatcommented, Jan 15, 2019

I can confirm that svcutil version 1.0.4 generated a service class that used XElement instead of XmlNode. I [wrongly] thought this was the new way of doing it in dotnet core 2, so I updated my code to match. It broke with a reflection error: there was a problem reflecting type <property>, where property was of type XElement.

I updated the generated service to use XmlNode, and reverted my code changes back to XmlNode, and the service is working, again. How long before this is fixed? It’s not going to impact me much, going forward, but the issue was confusing and this fix is not the best solution (e.g., "fix the generated code every time you regenerate it).

0reactions
dasetsercommented, Nov 8, 2019

@cjbush I’m sorry this change broke you. There is not a way to generate it using XElement in the latest version. I’d recommend installing the dotnet-svcutil 2.0.0 and using that to generate your service reference.

Read more comments on GitHub >

github_iconTop Results From Across the Web

net standard 1.6 WCF Client InvalidOperationException ...
net standard 1.6 WCF Client InvalidOperationException: System.Xml.Linq.XElement cannot be used as: 'xml text'.
Read more >
XElement.Explicit Operator (System.Xml.Linq)
The element is not null and does not contain a valid Int64 value. Examples. The following example creates an element with long integer...
Read more >
XElement.Load Method (System.Xml.Linq)
Creates a new XElement from a file specified by a URI, from an TextReader, or from an XmlReader.
Read more >
Returning an XML Encoded String in .NET - Rick Strahl
In most cases you'll want to use a proper XML processor whether it's an XML Document, XmlWriter or LINQ to XML to generate...
Read more >
Serializing Objects to XML in C# - Code Maze
In this post, we'll learn about serializing objects to XML in C#, i.e. transforming an object's contents into an XML document.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found