OPCFoundation / UA-ModelCompiler

ModelCompiler converts XML files into C# and ANSI C
MIT License
150 stars 93 forks source link

[Bug] NodeSet2 XML namespaces are wrongly escaped #145

Closed koepalex closed 8 months ago

koepalex commented 8 months ago

Repo Steps

Observation

Generated source code for the namespace properties is invalid and therefor all references to it:

    #region Namespace Declarations
    /// <remarks />
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Opc.Ua.ModelCompiler", "1.0.0.0")]
    public static partial class Namespaces
    {
        /// <summary>
        /// The URI for the alexander-koepke de opcua compressor namespace (.NET code namespace is 'CompressorSimulationOpcUaServer').
        /// </summary>
        public const string alexander-koepke de opcua compressor = "http://alexander-koepke.de/opcua/compressor";

        /// <summary>
        /// The URI for the OpcUa namespace (.NET code namespace is 'Opc.Ua').
        /// </summary>
        public const string OpcUa = "http://opcfoundation.org/UA/";
    }
    #endregion

Expectation

Characters that are valid in URIs but not in C# code should be escaped, like:

    #region Namespace Declarations
    /// <remarks />
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Opc.Ua.ModelCompiler", "1.0.0.0")]
    public static partial class Namespaces
    {
        /// <summary>
        /// The URI for the alexander-koepke de opcua compressor namespace (.NET code namespace is 'CompressorSimulationOpcUaServer').
        /// </summary>
        public const string alexander_koepke_de_opcua_compressor = "http://alexander-koepke.de/opcua/compressor";

        /// <summary>
        /// The URI for the OpcUa namespace (.NET code namespace is 'Opc.Ua').
        /// </summary>
        public const string OpcUa = "http://opcfoundation.org/UA/";
    }
    #endregion

Workaround

Manually editing the generated source code, to update the name of the namespace properties and all references to it.

opcfoundation-org commented 8 months ago

Pushed fix.

koepalex commented 8 months ago

Retested, is not working fully, - isn't escaped

    #region Namespace Declarations
    /// <remarks />
    [System.CodeDom.Compiler.GeneratedCodeAttribute("Opc.Ua.ModelCompiler", "1.0.0.0")]
    public static partial class Namespaces
    {
        /// <summary>
        /// The URI for the alexander-koepkedeopcuacompressor namespace (.NET code namespace is 'CompressorSimulationOpcUaServer').
        /// </summary>
        public const string alexander-koepkedeopcuacompressor = "http://alexander-koepke.de/opcua/compressor";

        /// <summary>
        /// The URI for the OpcUa namespace (.NET code namespace is 'Opc.Ua').
        /// </summary>
        public const string OpcUa = "http://opcfoundation.org/UA/";
    }
    #endregion
nikolastilinovic commented 2 months ago

There is also an issue with quotes in NodeId attribute when it uses string id, they are not escaped and the generator doesn't create a valid code. image