Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#pragma warning disable CS1591 only works for the first namespace #9394

Open
Cotspheer opened this issue Mar 18, 2025 · 1 comment
Open

#pragma warning disable CS1591 only works for the first namespace #9394

Cotspheer opened this issue Mar 18, 2025 · 1 comment

Comments

@Cotspheer
Copy link

Cotspheer commented Mar 18, 2025

Description

I'm trying to reduce the number of warnings in a project I'm working on. Most of them are CS1591 "Missing XML comment [...]". I've searched the issues and found the following PR #8940 where the issue should have been solved.

Now here is the thing, I've got static classes which do wrap DTOs used by my grains. The result is that the source generator creates two different namespaces:

  • OrleansCodeGen.OrleansPlaygroundApp.AccountContracts
  • OrleansCodeGen.OrleansPlaygroundApp.AccountRelationshipContracts

and the #pragma warning disable CS1591 only wraps the first namespace. The result is that I get warnings for all remaining classes inside different namespaces for the given output file OrleansPlaygroundApp.orleans.g.cs.

While writing the issue I also recognize that this happens when there are multiple classes in different namespaces - not nested - that do use [GenerateSerializer], so my issue isn't only related to the static class with its nested DTOs but occurs as soon as you have different namespaces.

If I remove the DTOs from the static class and make them standalone the directive gets properly added to the end of the file #pragma warning restore CS1591. But currently it gets added right above namespace OrleansCodeGen.OrleansPlaygroundApp.AccountRelationshipContracts

Expected behavior:

Directive #pragma warning restore CS1591 gets added to the very end of the generated source code or maybe leave it out completely as far as I can see restoring is not necessary. The latter would be the same solution that seems to be implemented by the logger source generator from the Microsoft.Extensions.Telemetry.Abstractions package.

Versions

  • .NET 9.0
  • Microsoft.Extensions.Logging.Abstractions: 9.0.3
  • Microsoft.Extensions.Telemetry.Abstractions: 9.3.0
  • Microsoft.Orleans.Core: 9.1.2
  • Microsoft.Orleans.Core.Abstractions: 9.1.2

How to reproduce:

  1. Create the most simple project
  2. Include the packages mentioned above
  3. Set following properties in the csproj
    1. <GenerateDocumentationFile>True</GenerateDocumentationFile>
    2. <EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
    3. <CompilerGeneratedFilesOutputPath>Generated</CompilerGeneratedFilesOutputPath>
  4. Create two DTO classes in two different namespaces and add the Attribute [GenerateSerializer] to them (or use the examples provided below)
  5. Hit compile
  6. Inspect the generated source file

Static AccountContracts

using Orleans;

namespace OrleansPlaygroundApp;

/*
    Does not work as it ends up in a different namespace than AccountRelationshipContracts
    Comment the following code to see the error.
 */

/// <summary>
///     Contains the contracts for the accounts
/// </summary>
public static class AccountContracts
{
    /// <summary>
    ///     Initialize a new account.
    /// </summary>
    [GenerateSerializer]
    [Immutable]
    public sealed class StoreAccountDataTransferObject
    {
        /// <summary>
        ///    The account that should be stored.
        /// </summary>
        [Id(0)]
        public string? AccountId { get; set; }
    }

    /// <summary>
    ///     Marks an account as deleted.
    /// </summary>
    [GenerateSerializer]
    [Immutable]
    public sealed class DeactivateAccountDataTransferObject
    {
        /// <summary>
        ///     The account that should be marked as deleted.
        /// </summary>
        [Id(0)]
        public string? AccountId { get; set; }
    }
}

/*
    Does work as every class is going into the same namespace.
    Uncomment the following code to see the error.
 */

///// <summary>
/////     Initialize a new account.
///// </summary>
//[GenerateSerializer]
//[Immutable]
//public sealed class StoreAccountDataTransferObject
//{
//    /// <summary>
//    ///    The account that should be stored.
//    /// </summary>
//    [Id(0)]
//    public string? AccountId { get; set; }
//}

///// <summary>
/////     Marks an account as deleted.
///// </summary>
//[GenerateSerializer]
//[Immutable]
//public sealed class DeactivateAccountDataTransferObject
//{
//    /// <summary>
//    ///     The account that should be marked as deleted.
//    /// </summary>
//    [Id(0)]
//    public string? AccountId { get; set; }
//}

Static AccountRelationshipContracts

using Orleans;

namespace OrleansPlaygroundApp;

/*
    Does not work as it ends up in a different namespace than AccountRelationshipContracts
    Comment the following code to see the error.
 */

/// <summary>
///     Contains the contracts for the account relationship.
/// </summary>
public static class AccountRelationshipContracts
{
    /// <summary>
    ///     Creates a relationship between two accounts.
    /// </summary>
    [GenerateSerializer]
    [Immutable]
    public sealed class EstablishAccountRelationshipDataTransferObject
    {
        /// <summary>
        ///     The account that is the head of the relationship.
        /// </summary>
        [Id(0)]
        public string? HeadAccountId { get; set; }

        /// <summary>
        ///     The account that is the tail of the relationship.
        /// </summary>
        [Id(1)]
        public string? TailAccountId { get; set; }

    }
}

/*
    Does work as every class is going into the same namespace.
    Uncomment the following code to see the error.
 */

///// <summary>
/////     Creates a relationship between two accounts.
///// </summary>
//[GenerateSerializer]
//[Immutable]
//public sealed class EstablishAccountRelationshipDataTransferObject
//{
//    /// <summary>
//    ///     The account that is the head of the relationship.
//    /// </summary>
//    [Id(0)]
//    public string? HeadAccountId { get; set; }

//    /// <summary>
//    ///     The account that is the tail of the relationship.
//    /// </summary>
//    [Id(1)]
//    public string? TailAccountId { get; set; }

//}

Generated Output

#pragma warning disable CS1591
[assembly: global::Orleans.ApplicationPartAttribute("OrleansPlaygroundApp")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")]
[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")]
[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.OrleansPlaygroundApp.Metadata_OrleansPlaygroundApp))]
namespace OrleansCodeGen.OrleansPlaygroundApp.AccountContracts
{
    using global::Orleans.Serialization.Codecs;
    using global::Orleans.Serialization.GeneratedCodeHelpers;

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
    public sealed class Codec_StoreAccountDataTransferObject : global::Orleans.Serialization.Codecs.IFieldCodec<global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject>
    {
        private readonly global::System.Type _codecFieldType = typeof(global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject);
        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void Serialize<TBufferWriter>(ref global::Orleans.Serialization.Buffers.Writer<TBufferWriter> writer, global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject instance)
            where TBufferWriter : global::System.Buffers.IBufferWriter<byte>
        {
            global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.AccountId);
        }

        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void Deserialize<TReaderInput>(ref global::Orleans.Serialization.Buffers.Reader<TReaderInput> reader, global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject instance)
        {
            uint id = 0U;
            global::Orleans.Serialization.WireProtocol.Field header = default;
            while (true)
            {
                reader.ReadFieldHeader(ref header);
                if (header.IsEndBaseOrEndObject)
                    break;
                id += header.FieldIdDelta;
                if (id == 0U)
                {
                    instance.AccountId = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header);
                    reader.ReadFieldHeader(ref header);
                }

                reader.ConsumeEndBaseOrEndObject(ref header);
                break;
            }
        }

        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void WriteField<TBufferWriter>(ref global::Orleans.Serialization.Buffers.Writer<TBufferWriter> writer, uint fieldIdDelta, global::System.Type expectedType, global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject @value)
            where TBufferWriter : global::System.Buffers.IBufferWriter<byte>
        {
            if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value))
                return;
            writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType);
            Serialize(ref writer, @value);
            writer.WriteEndObject();
        }

        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject ReadValue<TReaderInput>(ref global::Orleans.Serialization.Buffers.Reader<TReaderInput> reader, global::Orleans.Serialization.WireProtocol.Field field)
        {
            if (field.IsReference)
                return ReferenceCodec.ReadReference<global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject, TReaderInput>(ref reader, field);
            field.EnsureWireTypeTagDelimited();
            var result = new global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject();
            ReferenceCodec.RecordObject(reader.Session, result);
            Deserialize(ref reader, result);
            return result;
        }
    }

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
    internal sealed class Activator_StoreAccountDataTransferObject : global::Orleans.Serialization.Activators.IActivator<global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject>
    {
        public global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject Create() => new global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject();
    }

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
    public sealed class Codec_DeactivateAccountDataTransferObject : global::Orleans.Serialization.Codecs.IFieldCodec<global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject>
    {
        private readonly global::System.Type _codecFieldType = typeof(global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject);
        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void Serialize<TBufferWriter>(ref global::Orleans.Serialization.Buffers.Writer<TBufferWriter> writer, global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject instance)
            where TBufferWriter : global::System.Buffers.IBufferWriter<byte>
        {
            global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.AccountId);
        }

        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void Deserialize<TReaderInput>(ref global::Orleans.Serialization.Buffers.Reader<TReaderInput> reader, global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject instance)
        {
            uint id = 0U;
            global::Orleans.Serialization.WireProtocol.Field header = default;
            while (true)
            {
                reader.ReadFieldHeader(ref header);
                if (header.IsEndBaseOrEndObject)
                    break;
                id += header.FieldIdDelta;
                if (id == 0U)
                {
                    instance.AccountId = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header);
                    reader.ReadFieldHeader(ref header);
                }

                reader.ConsumeEndBaseOrEndObject(ref header);
                break;
            }
        }

        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void WriteField<TBufferWriter>(ref global::Orleans.Serialization.Buffers.Writer<TBufferWriter> writer, uint fieldIdDelta, global::System.Type expectedType, global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject @value)
            where TBufferWriter : global::System.Buffers.IBufferWriter<byte>
        {
            if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value))
                return;
            writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType);
            Serialize(ref writer, @value);
            writer.WriteEndObject();
        }

        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject ReadValue<TReaderInput>(ref global::Orleans.Serialization.Buffers.Reader<TReaderInput> reader, global::Orleans.Serialization.WireProtocol.Field field)
        {
            if (field.IsReference)
                return ReferenceCodec.ReadReference<global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject, TReaderInput>(ref reader, field);
            field.EnsureWireTypeTagDelimited();
            var result = new global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject();
            ReferenceCodec.RecordObject(reader.Session, result);
            Deserialize(ref reader, result);
            return result;
        }
    }

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
    internal sealed class Activator_DeactivateAccountDataTransferObject : global::Orleans.Serialization.Activators.IActivator<global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject>
    {
        public global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject Create() => new global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject();
    }
}
#pragma warning restore CS1591

namespace OrleansCodeGen.OrleansPlaygroundApp.AccountRelationshipContracts
{
    using global::Orleans.Serialization.Codecs;
    using global::Orleans.Serialization.GeneratedCodeHelpers;

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
    public sealed class Codec_EstablishAccountRelationshipDataTransferObject : global::Orleans.Serialization.Codecs.IFieldCodec<global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject>
    {
        private readonly global::System.Type _codecFieldType = typeof(global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject);
        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void Serialize<TBufferWriter>(ref global::Orleans.Serialization.Buffers.Writer<TBufferWriter> writer, global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject instance)
            where TBufferWriter : global::System.Buffers.IBufferWriter<byte>
        {
            global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.HeadAccountId);
            global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, instance.TailAccountId);
        }

        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void Deserialize<TReaderInput>(ref global::Orleans.Serialization.Buffers.Reader<TReaderInput> reader, global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject instance)
        {
            uint id = 0U;
            global::Orleans.Serialization.WireProtocol.Field header = default;
            while (true)
            {
                reader.ReadFieldHeader(ref header);
                if (header.IsEndBaseOrEndObject)
                    break;
                id += header.FieldIdDelta;
                if (id == 0U)
                {
                    instance.HeadAccountId = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header);
                    reader.ReadFieldHeader(ref header);
                    if (header.IsEndBaseOrEndObject)
                        break;
                    id += header.FieldIdDelta;
                }

                if (id == 1U)
                {
                    instance.TailAccountId = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header);
                    reader.ReadFieldHeader(ref header);
                }

                reader.ConsumeEndBaseOrEndObject(ref header);
                break;
            }
        }

        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public void WriteField<TBufferWriter>(ref global::Orleans.Serialization.Buffers.Writer<TBufferWriter> writer, uint fieldIdDelta, global::System.Type expectedType, global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject @value)
            where TBufferWriter : global::System.Buffers.IBufferWriter<byte>
        {
            if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value))
                return;
            writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType);
            Serialize(ref writer, @value);
            writer.WriteEndObject();
        }

        [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
        public global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject ReadValue<TReaderInput>(ref global::Orleans.Serialization.Buffers.Reader<TReaderInput> reader, global::Orleans.Serialization.WireProtocol.Field field)
        {
            if (field.IsReference)
                return ReferenceCodec.ReadReference<global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject, TReaderInput>(ref reader, field);
            field.EnsureWireTypeTagDelimited();
            var result = new global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject();
            ReferenceCodec.RecordObject(reader.Session, result);
            Deserialize(ref reader, result);
            return result;
        }
    }

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
    internal sealed class Activator_EstablishAccountRelationshipDataTransferObject : global::Orleans.Serialization.Activators.IActivator<global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject>
    {
        public global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject Create() => new global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject();
    }
}

namespace OrleansCodeGen.OrleansPlaygroundApp
{
    using global::Orleans.Serialization.Codecs;
    using global::Orleans.Serialization.GeneratedCodeHelpers;

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never)]
    internal sealed class Metadata_OrleansPlaygroundApp : global::Orleans.Serialization.Configuration.TypeManifestProviderBase
    {
        protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config)
        {
            config.Serializers.Add(typeof(OrleansCodeGen.OrleansPlaygroundApp.AccountContracts.Codec_StoreAccountDataTransferObject));
            config.Serializers.Add(typeof(OrleansCodeGen.OrleansPlaygroundApp.AccountContracts.Codec_DeactivateAccountDataTransferObject));
            config.Serializers.Add(typeof(OrleansCodeGen.OrleansPlaygroundApp.AccountRelationshipContracts.Codec_EstablishAccountRelationshipDataTransferObject));
            config.Copiers.Add(typeof(global::Orleans.Serialization.Cloning.ShallowCopier<global::OrleansPlaygroundApp.AccountContracts.StoreAccountDataTransferObject>));
            config.Copiers.Add(typeof(global::Orleans.Serialization.Cloning.ShallowCopier<global::OrleansPlaygroundApp.AccountContracts.DeactivateAccountDataTransferObject>));
            config.Copiers.Add(typeof(global::Orleans.Serialization.Cloning.ShallowCopier<global::OrleansPlaygroundApp.AccountRelationshipContracts.EstablishAccountRelationshipDataTransferObject>));
            config.Activators.Add(typeof(OrleansCodeGen.OrleansPlaygroundApp.AccountContracts.Activator_StoreAccountDataTransferObject));
            config.Activators.Add(typeof(OrleansCodeGen.OrleansPlaygroundApp.AccountContracts.Activator_DeactivateAccountDataTransferObject));
            config.Activators.Add(typeof(OrleansCodeGen.OrleansPlaygroundApp.AccountRelationshipContracts.Activator_EstablishAccountRelationshipDataTransferObject));
        }
    }
}

Logging.g.cs from Microsoft.Extensions.Telemetry.Abstractions

// <auto-generated/>
#nullable enable
#pragma warning disable CS1591 // Compensate for https://github.com/dotnet/roslyn/issues/54103

namespace OrleansPlaygroundApp.LoggingTestA
{
    partial class Log
    {
        /// <summary>
        /// Logs "Hello {message}" at "Debug" level.
        /// </summary>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Gen.Logging", "9.3.0.0")]
        static partial void LogSomeMessageInternal(this global::Microsoft.Extensions.Logging.ILogger logger, string message)
        {
            if (!logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                return;
            }

            var state = global::Microsoft.Extensions.Logging.LoggerMessageHelper.ThreadLocalState;

            _ = state.ReserveTagSpace(2);
            state.TagArray[1] = new("message", message);
            state.TagArray[0] = new("{OriginalFormat}", "Hello {message}");

            logger.Log(
                global::Microsoft.Extensions.Logging.LogLevel.Debug,
                new(1065463220, nameof(LogSomeMessageInternal)),
                state,
                null,
                [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Gen.Logging", "9.3.0.0")] static string (s, _) =>
                {
                    var message = s.TagArray[1].Value ?? "(null)";
                    #if NET
                    return string.Create(global::System.Globalization.CultureInfo.InvariantCulture, $"Hello {message}");
                    #else
                    return global::System.FormattableString.Invariant($"Hello {message}");
                    #endif
                });

            state.Clear();
        }
    }
}

namespace OrleansPlaygroundApp.LoggingTestB
{
    partial class Log
    {
        /// <summary>
        /// Logs "Hello {message}" at "Debug" level.
        /// </summary>
        [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Gen.Logging", "9.3.0.0")]
        static partial void LogSomeMessageInternal(this global::Microsoft.Extensions.Logging.ILogger logger, string message)
        {
            if (!logger.IsEnabled(global::Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                return;
            }

            var state = global::Microsoft.Extensions.Logging.LoggerMessageHelper.ThreadLocalState;

            _ = state.ReserveTagSpace(2);
            state.TagArray[1] = new("message", message);
            state.TagArray[0] = new("{OriginalFormat}", "Hello {message}");

            logger.Log(
                global::Microsoft.Extensions.Logging.LogLevel.Debug,
                new(1065463220, nameof(LogSomeMessageInternal)),
                state,
                null,
                [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.Gen.Logging", "9.3.0.0")] static string (s, _) =>
                {
                    var message = s.TagArray[1].Value ?? "(null)";
                    #if NET
                    return string.Create(global::System.Globalization.CultureInfo.InvariantCulture, $"Hello {message}");
                    #else
                    return global::System.FormattableString.Invariant($"Hello {message}");
                    #endif
                });

            state.Clear();
        }
    }
}
@Cotspheer Cotspheer changed the title #pragma warning disable CS1591 only works for the first namespace when classes are nested #pragma warning disable CS1591 only works for the first namespace Mar 18, 2025
@Cotspheer
Copy link
Author

Cotspheer commented Mar 18, 2025

I just investigated the change made and I came up with two possible solutions:

  1. Remove the code from line 381 to line 403
  2. Change line 383 to the following namespaces[namespaces.Count - 1] = namespaces[namespaces.Count - 1]

With the latter solution the restore would be appended to the end of the very last namespace. But it would have the same effect as removing the whole block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant