mono / Embeddinator-4000

Tools to turn .NET libraries into native libraries that can be consumed on Android, iOS, Mac, Linux and other platforms.
MIT License
758 stars 95 forks source link

Failed to Convert XMLReader to Mono Code #782

Closed ppun51 closed 3 years ago

ppun51 commented 3 years ago

Steps to Reproduce

  1. Create sample project
  2. reference the System.XML
  3. Add Deserialization method using XMLReader
  4. use Embeddinator to convert the project to the library.

    Expected Behavior

    Generate library without error.

    Actual Behavior

    error is occurred "Failed to convert XMLReader to MonoCode

    Environment

public void Deserialize(XmlReader reader) { // get the values this.A = float.Parse(reader.GetAttribute(RGB_A)); this.R = float.Parse(reader.GetAttribute(RGB_R)); this.G = float.Parse(reader.GetAttribute(RGB_G)); this.B = float.Parse(reader.GetAttribute(RGB_B));

        // read the element
        reader.Read();
        reader.ReadEndElement();
    }

Build Logs

Example Project (If Possible)

rolfbjarne commented 3 years ago

Thank you for your feedback!

For us to investigate this further, could you please provide the full build log, a test project to reproduce and all your version information.

The easiest way to get exact version information:

Then copy/paste the version information (you can use the "Copy Information" button).

We look forward to hearing from you!

ppun51 commented 3 years ago

Thank you, Here is information about the VS on MAC.

Visual Studio Community 2019 for Mac Version 8.7.7 (build 10) Installation UUID: 202a0c59-63a2-437f-a962-a78fdbf652c0 GTK+ 2.24.23 (Raleigh theme) Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

Package version: 612000093

Mono Framework MDK Runtime: Mono 6.12.0.93 (2020-02/620cf538206) (64-bit) Package version: 612000093

Roslyn (Language Service) 3.7.0-6.20427.1+18ede13943b0bfae1b44ef078b2f3923159bcd32

NuGet Version: 5.7.0.6702

.NET Core SDK SDK: /usr/local/share/dotnet/sdk/3.1.402/Sdks SDK Versions: 3.1.402 3.1.401 3.1.302 3.1.301 3.1.300 3.1.202 3.1.200 3.1.102 3.0.101 3.0.100 2.1.701 MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/6.12.0/lib/mono/msbuild/Current/bin/Sdks

.NET Core Runtime Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 3.1.8 3.1.7 3.1.6 3.1.5 3.1.4 3.1.2 3.0.1 3.0.0 2.1.22 2.1.21 2.1.20 2.1.19 2.1.18 2.1.17 2.1.16 2.1.15 2.1.14 2.1.13 2.1.12

Xamarin.Profiler Version: 1.6.12.26 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Updater Version: 11

Xamarin.Android Version: 11.0.2.0 (Visual Studio Community) Commit: xamarin-android/d16-7/025fde9 Android SDK: /Users/sungyun/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 7.1 (API level 25) 8.1 (API level 27)

SDK Tools Version: 26.1.1 SDK Platform Tools Version: 30.0.4 SDK Build Tools Version: 29.0.2

Build Information: Mono: 83105ba Java.Interop: xamarin/java.interop/d16-7@1f3388a ProGuard: Guardsquare/proguard/proguard6.2.2@ebe9000 SQLite: xamarin/sqlite/3.32.1@1a3276b Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-7@017078f

Microsoft OpenJDK for Mobile Java SDK: /Users/sungyun/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25 1.8.0-25 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL

Android SDK Manager Version: 16.7.0.13 Hash: 8380518 Branch: remotes/origin/d16-7~2 Build date: 2020-08-19 22:18:28 UTC

Android Device Manager Version: 16.7.0.24 Hash: bb090a3 Branch: remotes/origin/d16-7 Build date: 2020-08-19 22:18:52 UTC

Apple Developer Tools Xcode 11.7 (16142) Build 12A7209

Xamarin.Mac Version: 6.20.2.2 (Visual Studio Community) Hash: 817b6f72a Branch: d16-7 Build date: 2020-07-18 18:44:59-0400

Xamarin.iOS Version: 13.20.2.2 (Visual Studio Community) Hash: 817b6f72a Branch: d16-7 Build date: 2020-07-18 18:45:00-0400

Xamarin Designer Version: 16.7.0.495 Hash: 03d50a221 Branch: remotes/origin/d16-7-vsmac Build date: 2020-08-28 13:12:52 UTC

Build Information Release ID: 807070010 Git revision: e58142243407a357198d18ee1a37b1e67a702eff Build date: 2020-09-10 11:48:02-04 Build branch: release-8.7 Xamarin extensions: e58142243407a357198d18ee1a37b1e67a702eff

Operating System Mac OS X 10.15.6 Darwin 19.6.0 Darwin Kernel Version 19.6.0 Thu Jun 18 20:49:00 PDT 2020 root:xnu-6153.141.1~1/RELEASE_X86_64 x86_64

rolfbjarne commented 3 years ago

Could you please provide us with a test project we can use to reproduce this issue as well?

ppun51 commented 3 years ago

The project is too big to attached, it is 4MB. The class is included below.

using System; using System.Xml; using DYMO.LabelAPI.CrossPlatform.Interfaces;

namespace DYMO.LabelAPI { // a cross platform color holder public class DYMOColor : IDYMOCloneable {

region Constants

    private const string COLOR = "Color";
    private const string RGB_A = "A";
    private const string RGB_R = "R";
    private const string RGB_G = "G";
    private const string RGB_B = "B";

    #endregion

    #region Pre-defined Colors

    // pre-defined colors
    public static DYMOColor Black { get { return new DYMOColor(0, 0, 0); } }
    // this is the black color for continuous tapes
    public static DYMOColor LabelBlack { get { return new DYMOColor(TruncateFloat((35f / 255f)), TruncateFloat((31f / 255f)), TruncateFloat((32f / 255f))); } }

    public static DYMOColor White { get { return new DYMOColor(1, 1, 1); } }

    public static DYMOColor Red { get { return new DYMOColor(1, 0, 0); } }

    //public static DYMOColor Green { get { return new DYMOColor(0, 1, 0); } }
    //public static DYMOColor TranslucentGreen { get { return new DYMOColor(.5f, 0, 1, 0); } }
    //public static DYMOColor Blue { get { return new DYMOColor(0, 0, 1); } }

    public static DYMOColor LightBlue { get { return new DYMOColor(.68f, .85f, .90f); } }
    public static DYMOColor LightGray { get { return new DYMOColor(.83f, .83f, .83f); } }

    //public static DYMOColor TranslucentLightGray { get { return new DYMOColor(.5f, .83f, .83f, .83f); } }
    public static DYMOColor Transparent { get { return new DYMOColor(0, 1, 1, 1); } }

    #endregion

    #region Properties

    private float _a;
    public float A
    {
        get { return _a; }
        set
        {
            if (float.IsNaN(value))
                value = 0.0f;
            this.CheckValue(value);
            _a = value;
        }
    }

    private float _r;
    public float R
    {
        get { return _r; }
        set
        {
            this.CheckValue(value);
            _r = value;
        }
    }

    private float _g;
    public float G
    {
        get { return _g; }
        set
        {
            this.CheckValue(value);
            _g = value;
        }
    }

    private float _b;
    public float B
    {
        get { return _b; }
        set
        {
            this.CheckValue(value);
            _b = value;
        }
    }

    #endregion

    #region Constructors

    public DYMOColor()
        : this(1, 1, 1)
    { }

    public DYMOColor(float r, float g, float b)
        : this(1, r, g, b)
    { }

    public DYMOColor(float a, float r, float g, float b)
    {
        A = a;
        R = r;
        G = g;
        B = b;
    }

    #endregion

    #region Public Methods

    ///// <summary>
    ///// Returns the DYMOColor represent by the specified hex string
    ///// </summary>
    //public static DYMOColor FromHex(string hex)
    //{
    //    // string must either be 7 or 9 digits long and start with #
    //    if (string.IsNullOrEmpty(hex) || !hex.StartsWith("#") || (hex.Length != 7 && hex.Length != 9))
    //    {
    //        throw new ArgumentException(string.Format("Hex string {0} is not in the correct format", hex));
    //    }

    //    byte byte0 = byte.Parse(hex.Substring(1, 2), NumberStyles.HexNumber);
    //    byte byte1 = byte.Parse(hex.Substring(3, 2), NumberStyles.HexNumber);
    //    byte byte2 = byte.Parse(hex.Substring(5, 2), NumberStyles.HexNumber);
    //    byte byte3 = hex.Length == 9 ? byte.Parse(hex.Substring(7, 2), NumberStyles.HexNumber) : (byte)255;

    //    float f0 = byte0 / 255.0f;
    //    float f1 = byte1 / 255.0f;
    //    float f2 = byte2 / 255.0f;
    //    float f3 = byte3 / 255.0f;

    //    if (hex.Length == 7)
    //        return new DYMOColor(f3, f0, f1, f2);
    //    else
    //        return new DYMOColor(f0, f1, f2, f3);
    //}

    public string AsHex()
    {
        byte byte0 = (byte)(this.A * 255);
        byte byte1 = (byte)(this.R * 255);
        byte byte2 = (byte)(this.G * 255);
        byte byte3 = (byte)(this.B * 255);
        return string.Format("#{0}{1}{2}{3}", byte0.ToString("X2"), byte1.ToString("X2"), byte2.ToString("X2"), byte3.ToString("X2"));
    }
    public string GetHex
    {
        get { return AsHex(); }
    }

    ///// <summary>
    ///// Returns a transparent version of this color
    ///// </summary>
    ///// <returns></returns>
    //public DYMOColor GetTransparent()
    //{
    //    return DYMOColor.FromHex("#00" + this.GetHex.Substring(3));
    //}

    public DYMOColor ToGrayscale()
    {
        // to convert to grayscale, we use a weighted average
        // http://www.had2know.com/technology/rgb-to-gray-scale-converter.html
        float avg = (.299f * this.R) + (.587f * this.G) + (.114f * this.B);
        return new DYMOColor(this.A, avg, avg, avg);
    }

    #endregion

    #region Private Methods

    // Checks the color value is in between 0 and 1
    // throws an exception if not
    private void CheckValue(float v)
    {
        if (v < 0 || v > 1)
            throw new ArgumentException("Invalid value. Valid values for color channels from from 0 to 1.0");
    }

    /// <summary>
    /// Color values are different while colculating hue
    /// </summary>
    /// <param name="v">color value</param>
    /// <returns>float that is truncated</returns>
    private static float TruncateFloat(float v)
    {
        float returnValue = (float)Math.Truncate(v * 10000000) / 10000000;
        return returnValue;
    }

    #endregion

    #region Overrides

    public override bool Equals(object obj)
    {
        DYMOColor other = obj as DYMOColor;
        if (other == null)
            return false;
        else if ((other.A.Equals(A)) && (other.B.Equals(B)) && (other.G.Equals(G)) && (other.R.Equals(R)))
        {
            return true;
        }
        else
            return false;

    }

    public override int GetHashCode()
    {
        return base.GetHashCode();
    }

    public object Clone()
    {
        return new DYMOColor(A, R, G, B);
    }

    #endregion

    #region Serialization

    public void Serialize(XmlWriter writer)
    {
        writer.WriteStartElement(COLOR);

        writer.WriteAttributeString(RGB_A, this.A.ToString());
        writer.WriteAttributeString(RGB_R, this.R.ToString());
        writer.WriteAttributeString(RGB_G, this.G.ToString());
        writer.WriteAttributeString(RGB_B, this.B.ToString());

        writer.WriteFullEndElement();
    }

    public void Deserialize(XmlReader reader)
    {
        // get the values
        this.A = float.Parse(reader.GetAttribute(RGB_A));
        this.R = float.Parse(reader.GetAttribute(RGB_R));
        this.G = float.Parse(reader.GetAttribute(RGB_G));
        this.B = float.Parse(reader.GetAttribute(RGB_B));

        // read the element
        reader.Read();
        reader.ReadEndElement();
    }

    #endregion
}

}


From: Sung Yun ppun51@hotmail.com Sent: Monday, September 28, 2020 1:48 PM To: mono/Embeddinator-4000 Embeddinator-4000@noreply.github.com; mono/Embeddinator-4000 reply@reply.github.com Cc: Author author@noreply.github.com Subject: Re: [mono/Embeddinator-4000] Failed to Convert XMLReader to Mono Code (#782)

Attached the sample code that I tested with Embeddinator. Thanks, Sung.


From: Rolf Bjarne Kvinge notifications@github.com Sent: Monday, September 28, 2020 8:33 AM To: mono/Embeddinator-4000 Embeddinator-4000@noreply.github.com Cc: ppun51 ppun51@hotmail.com; Author author@noreply.github.com Subject: Re: [mono/Embeddinator-4000] Failed to Convert XMLReader to Mono Code (#782)

Could you please provide us with a test project we can use to reproduce this issue as well?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/mono/Embeddinator-4000/issues/782#issuecomment-699977414, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEIGOFU236VL5HFBRQGHCQTSIB7A7ANCNFSM4RRVELNA.

rolfbjarne commented 3 years ago

The project is too big to attached, it is 4MB.

You can use a file-sharing service like Dropbox to share the project, and just paste the link here.

chamons commented 3 years ago

We have not received the requested information.

If you are still experiencing this issue please provide all the requested information then click the Reopen Issue button.

Thanks!