aws / aws-sdk-net

The official AWS SDK for .NET. For more information on the AWS SDK for .NET, see our web site:
http://aws.amazon.com/sdkfornet/
Apache License 2.0
2.06k stars 856 forks source link

AWS S3 SDK always tries to load log4net assembly even if logging is disabled or set to output to console #1839

Open madhub opened 3 years ago

madhub commented 3 years ago

Description

AWS S3 SDK always tries to load log4net assembly even if logging is disabled or set to output to console

We have application where we provide Assembly Resolver to resolve plugin assemblies, on every application launch our resolver is called to load log4net assembly even if logging is disabled or set to output to console.

Expectation : If logging is disabled or set to output to console , library should try load log4net assembly

Reproduction Steps

public class AWSSample
    {
        private const string DllExtension = ".dll";

        static void Main(string[] args)
        {
            // Assembly Resolver to load Plugin assemblies
            AssemblyLoadContext.Default.Resolving += Default_Resolving;
            string accessKey = "minioadmin";
            string secretKey = "minioadmin"; // do not store secret key hardcoded in your production source code!

            // Setting LoggingOptions.None also tries to load log4net
            AWSConfigs.Logging = LoggingOptions.Console;

            var config = new AmazonS3Config
            {
                RegionEndpoint = RegionEndpoint.USEast1, 
                ServiceURL = "http://localhost:9000", 
                ForcePathStyle = true,

                // disabling logging
                DisableLogging = true,

                Timeout = TimeSpan.FromSeconds(4)

            };
            var amazonS3Client = new AmazonS3Client(accessKey, secretKey, config);
            TransferUtility transferUtility = new TransferUtility(amazonS3Client);
            try
            {
                transferUtility.UploadDirectory(@"C:\Data\docs", "demo");
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.ToString());
            }

        }

        /// <summary>
        /// Assembly Resolver to load Plugin assemblies
        /// </summary>
        /// <param name="context"></param>
        /// <param name="arg2"></param>
        /// <returns></returns>
        private static System.Reflection.Assembly Default_Resolving(AssemblyLoadContext context, System.Reflection.AssemblyName arg2)
        {
            var path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, arg2.Name + DllExtension);
            try
            {
                if (File.Exists(path))
                {
                    return context.LoadFromAssemblyPath(path);
                }

                Console.WriteLine($"Unable to locate {arg2.Name} at {path}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"Unable to locate {arg2.Name} at {path}", e);
            }

            return null;
        }
    }

Logs

Environment

Resolution


This is a :bug: bug-report

github-actions[bot] commented 2 years ago

We have noticed this issue has not received attention in 1 year. We will close this issue for now. If you think this is in error, please feel free to comment and reopen the issue.

madhub commented 2 years ago

Any update on this issue, This needs to be fixed.