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

System.NullReferenceException: 'Object reference not set to an instance of an object.' #14

Open
jluzardo1971 opened this issue Nov 6, 2021 · 3 comments

Comments

@jluzardo1971
Copy link

Hi,

In the latest version of the code I'm getting:

System.NullReferenceException: 'Object reference not set to an instance of an object.'

in

private async Task Authenticate(string username, string password, string endpoint)

in the

public partial class Client : ISwiftClient, IDisposable

image

This is not being called:

image

I'm using this code to call the SwiftClient and the code works with version 1.2.2 of the nuGet package

@jluzardo1971
Copy link
Author

I'm using this code:

public class OpenStackSwift : IDisposable, IFileServer
{

    SwiftClient.Client client;
    string containerId;


    // Flag: Has Dispose already been called?
    bool disposed = false;

    public OpenStackSwift(string username, string password, List<string> endPoints, string containerId)
    {
        this.containerId = containerId;
        client = new SwiftClient.Client()
        .WithCredentials(new SwiftCredentials
        {
            Username = username,
            Password = password,
            Endpoints = endPoints
        })
        .SetRetryCount(6)
        .SetRetryPerEndpointCount(2)
        ;
    }

    public void UploadFile(System.IO.Stream stream, string fileName)
    {
        stream.Position = 0;
        using (MemoryStream ms = new MemoryStream())
        {
            stream.CopyTo(ms);
            Task<SwiftResponse> task = Task.Run(() => client.PutObject(this.containerId, fileName, ms.ToArray()));
            SwiftResponse response = task.Result;
        }
    }

@yunusrf
Copy link

yunusrf commented Mar 22, 2022

Hello @jluzardo1971

I am also getting the same error. Do you have any comments to resolve this ?. Your input will help a lot.
Thanks in advance.

alejandro1585 pushed a commit to alejandro1585/SwiftClient that referenced this issue Oct 18, 2022
…o1971 System.NullReferenceException: 'Object reference not set to an instance of an object.'
@alejandro1585
Copy link

alejandro1585 commented Oct 18, 2022

_client not init

I've created Pull request address this issue. As @jluzardo1971 mentioned, the SetHttpClient() method is not being called and as a result the _client variable does not get initialized. I just initialized it by default until I can spend some more time and understand where exactly SetHttpClient should be called. For now this minor fix has gotten me up and running for my project which has a very tight deadline. Thank you guys for putting this together. Aside for the minor obstacles, it saved us lots of time.

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

3 participants