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

'ToFile' is not a member of Task(Of TinifyAPI.Source) #24

Open
trevski opened this issue Aug 25, 2022 · 6 comments
Open

'ToFile' is not a member of Task(Of TinifyAPI.Source) #24

trevski opened this issue Aug 25, 2022 · 6 comments

Comments

@trevski
Copy link

trevski commented Aug 25, 2022

I am implementing in VB.net

I need a version of this DLL with a strong name key, our solution gets installed in the GAC on the server and requires it.

I Forked to create a version and deployed it and I am getting the above error.

Any ideas ?

@ddmicu
Copy link

ddmicu commented Aug 26, 2022

Unfortunately, we don't have much experience in vb.net but here is a minimal working project to start with:

Imports TinifyAPI

Module Program
Sub Main(args As String())
Tinify.Key = "API_KEY"
Dim task = New Task(AddressOf Compress)
task.Start()
task.Wait()
Console.ReadLine()
End Sub

Async Sub Compress()
    Dim imageSrc = Tinify.FromUrl("https://tinypng.com/images/panda-happy.png")
    Await imageSrc.ToFile("test.png")
End Sub

End Module

Hope this is a good starting example that you can expand.

@jshergal
Copy link
Contributor

I might be able to help. I recently was updating the library to deal with the Json.Net issue as well as updating it to .net standard 2.0, etc. I am primarily a C# developer, but I may be able to help you with your VB code if you can show the context of your code where you are getting this error. I am assuming you are trying to write the result to a file via the ToFile call, so if you can show a few lines of code of where you are seeing this issue, I will try to help.

@trevski
Copy link
Author

trevski commented Aug 31, 2022

Async Sub Compress(ByVal filepathFrom As String, ByVal filepathTo As String)

    Dim tinifyImg As Task(Of TinifyAPI.Source) = TinifyAPI.Tinify.FromFile(filepathFrom)
    Await tinifyImg.ToFile(filepathTo)

End Sub

I am getting an underline on tinifyImg.ToFile

And a message

'ToFile' is not a member of Task(Of TinifyAPI.Source)

All I did was re-complie the code with a strong name key

@jshergal
Copy link
Contributor

jshergal commented Aug 31, 2022

The ToFile method is an extension method on the Task(Of Source) and so if you have not imported the namespace you won't have access to it. Since you are adding the TinifyAPI.Tinify full name in your code, I am assuming you have not added this line:

Imports TinifyAPI

That should take care of your issue.

Note: This is what is included in the sample that was provided by @ddmicu

Imports TinifyAPI

Module Program

Sub Main(args As String())
    Tinify.Key = "API_KEY"
    Dim task = New Task(AddressOf Compress)
    task.Start()
    task.Wait()
    Console.ReadLine()
End Sub

Async Sub Compress()
    Dim imageSrc = Tinify.FromUrl("https://tinypng.com/images/panda-happy.png")
    Await imageSrc.ToFile("test.png")
End Sub

@trevski
Copy link
Author

trevski commented Aug 31, 2022

OK in VB.Net I needed to format the code like this...

        Dim tinifyImg As Task(Of TinifyAPI.Source) = TinifyAPI.Tinify.FromFile(filepathFrom)

        Dim newImage As TinifyAPI.Source = Await tinifyImg

        Await newImage.ToFile(filepathTo)

It then worked OK.

@jshergal
Copy link
Contributor

jshergal commented Aug 31, 2022

I'm glad that worked, but if you add the import line to the top of your source file, you would be able to just write this code:

Dim tinifyImg = Tinify.FromFile(filepathFrom)
Await tinifyImg.ToFile(filepathTo)

The ToFile method in my sample is using an extension method on the Task(Of Source). In your code you are awaiting the Task(Of Source) which is giving you back then an object of type Sourceand then you are calling theToFile` on that object. I guess it is more a matter of preference than anything, but you could shorten your code by a line by adding the Import statement.

Either way I am glad you got it working. Feel free to close the issue, if you feel it has been resolved.

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