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

BucketExistsAsync throwing NullReferenceException when Bucket doesn't exist #847

Closed
renatokenji opened this issue Aug 23, 2023 · 4 comments

Comments

@renatokenji
Copy link

Hi,

I'm having the exact same issue described in #714 but my client is instantiated correctly calling the .Build() at the end. I've already tested other operations and everything is running fine, I can upload/download and list objects but I decided to implement the bucket verification just in case and i'm getting this error.

Code for the client

private const string Bucket = "BucketTestName";
private const string ContentType = "application/pdf";
private readonly MinioClient _client = new MinioClient().WithEndpoint(Url)
            .WithCredentials(AccessKey, SecretKey)
            .WithSSL().Build();

Code for putting an object in the bucket

        public async Task Add(ArquivoMinio arquivo)
        {
            try
            {
                var argss = new BucketExistsArgs().WithBucket(Bucket);
                var bucketExists = await _client.BucketExistsAsync(argss); //this line throws the exception
                if (!bucketExists)
                {
                    await CreateBucket();
                }

                using var dados = new MemoryStream(arquivo.Base64);
                var args = new PutObjectArgs().WithBucket(Bucket).WithObject($"{arquivo.Caminho}")
                    .WithStreamData(dados).WithObjectSize(arquivo.Base64.Length)
                    .WithContentType(ContentType);
                await _client.PutObjectAsync(args);
            }
            catch (MinioException e)
            {
                //ommited for brevity
            }
        }

Everything is running and working. Its just that BucketExistsAsync verification that throws the same error from the issue mentioned

System.NullReferenceException: Object reference not set to an instance of an object.
   at Minio.MinioClient.ParseErrorFromContent(ResponseResult response) in /_/Minio/MinioClient.cs:line 608
   at Minio.MinioClient.ParseError(ResponseResult response) in /_/Minio/MinioClient.cs:line 477
   at Minio.MinioClient.<>c.<.ctor>b__94_0(ResponseResult response) in /_/Minio/MinioClient.cs:line 47
   at Minio.MinioClient.HandleIfErrorResponse(ResponseResult response, IEnumerable`1 handlers, DateTime startTime) in /_/Minio/MinioClient.cs:line 670
   at Minio.MinioClient.ExecuteTaskCoreAsync(IEnumerable`1 errorHandlers, HttpRequestMessageBuilder requestMessageBuilder, Boolean isSts, CancellationToken cancellationToken) in /_/Minio/MinioClient.cs:line 451
   at Minio.BucketRegionCache.Update(MinioClient client, String bucketName) in /_/Minio/BucketRegionCache.cs:line 99
   at Minio.MinioClient.GetRegion(String bucketName) in /_/Minio/MinioClient.cs:line 202
   at Minio.MinioClient.CreateRequest(HttpMethod method, String bucketName, String objectName, IDictionary`2 headerMap, String contentType, ReadOnlyMemory`1 body, String resourcePath, Boolean isBucketCreationRequest) in /_/Minio/MinioClient.cs:line 291
   at Minio.MinioClient.CreateRequest[T](BucketArgs`1 args) in /_/Minio/MinioClient.cs:line 232
   at Minio.MinioClient.BucketExistsAsync(BucketExistsArgs args, CancellationToken cancellationToken) in /_/Minio/ApiEndpoints/BucketOperations.cs:line 67

This happens only when the Bucket doesn't exist. I tried running the code with the name of a existing bucket and it also runs fine and proceeds to put the object successfully.

I'm using MinIO version 5.0.0 and the server version is 2023-06-29T05:12:28Z

@renatokenji renatokenji changed the title BucketExistsAsync throwing NullReferenceException when Bucket doesn't exists BucketExistsAsync throwing NullReferenceException when Bucket doesn't exist Aug 24, 2023
@criedsky
Copy link

I have the same issue when trying to create a new bucket.
Working fine for put/get file from an exist bucket.

@xiangxiren
Copy link

Minio server version is low.

@ebozduman
Copy link
Collaborator

@renatokenji , @criedsky

I believe this issue is fixed in PR #844

Could you please test it and close this issue if it passes your test?

@renatokenji
Copy link
Author

@ebozduman fixed. Updated to 6.0.0 with same server version. Thank you, closing this issue.

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

4 participants