Mono - .NET cross-platform personal experience (1)

zhaozj2021-02-16  69

In the afternoon, two class library projects that have been used in the past .NET project in the Redhat Linux 9 / Mono 1.0, the first simpler projects are successfully compiled, and compiled in the second XML library project. Abnormal, and this project has passed Microsoft's CSC compiler, the feedback information of the Mono-MCS compiler is as follows:

XMLUtility.cs (73) error CS1502: The best overloaded match for method 'System.Xml.XmlAttribute System.Xml.XmlAttributeCollection.Remove (System.Xml.XmlAttribute)' has some invalid arguments.XMLUtility.cs (73) error CS1503: Argument 0: Can not convert from 'System.Xml.XmlNode' to 'System.Xml.XmlAttribute'.XMLUtility.cs (73) error CS1501: No overload for method' Remove 'takes' 1' arguments.XMLUtility.cs (73) Error CS8006: COULD NOT FIND ANY Applicable Function Fer this Argument List.Compilation Failed: 4 Error (s), 0 Warnings.

Open the source code, locate the error prompt position, the context code is as follows: prompt: OwnerNode is the incoming parameter of the function, its type is system.xml.xmlNode, AttributeName is the incoming parameter of the function, which is String.

System.xml.xmlnode attribute = ownernode.attribute.getnameditem (attributename);

IF (attribute! = null) OwnerNode.Attributes.remove (attribute);

Change the last code to: OwnerNode.attributes.Remove ((System.xml.attribute) attribute); after compiling!

Why is the above code in vs.net, but can't compile it in MCS compilers in Mono? OK, let's take a look at the MCS's prompt information, great idea is to find the REMOVE of the REMOVE that matches it in XMlattributeCollection. Through VS.NET object browser, you can view Microsoft's System.xml.dll and Mono's System.xml.dll library file, which definition is both, as follows: public class xmlattribute: system.xml.xmlnodepublic class xmlattributeCollection: system.xml .Xmlnamednodemap

public virtual System.Xml.XmlAttributeCollection Attributes [get] public virtual System.Xml.XmlAttribute System.Xml.XmlAttributeCollection.Remove (System.Xml.XmlAttribute node) public virtual System.Xml.XmlNode System.Xml.XmlNamedNodeMap.GetNamedItem (string name ) There is only one unique REMOVE method in the XMlattributeCollection class, and there is no override overload. So the last line of code should be compiled, why can you pass in vs.net? And the above .GetNameDItem (AttributeName) is only the XMLNode type, so the compiler cannot make intelligence judgments, and convert it by default. Oh, how do you do it? :- (Finally, this class library size compiled with MCS in Linux is 43KB, and the class library compiled with VS.NET (CSC) (Debug / Release Version) in Win2000 is 56kb. :-(

转载请注明原文地址:https://www.9cbs.com/read-17556.html

New Post(0)