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

Xamarin Support #10

Open
NVentimiglia opened this issue Aug 28, 2015 · 40 comments
Open

Xamarin Support #10

NVentimiglia opened this issue Aug 28, 2015 · 40 comments
Assignees

Comments

@NVentimiglia
Copy link

Does Cloudinary support Xamarin mobile clients ? Xamarin uses the mono subset (4.5), not the full .net runtime.

@NVentimiglia
Copy link
Author

Update, it is not supported.

After looking at the code it looks like some of the practices are pretty dated (HttpRequest being used instead of an HttpClient). Any plans to update this to a PCL project ?

@eanagel
Copy link

eanagel commented Jan 18, 2017

+1. This has been open for 16 months, can we get an update?

@roeeba
Copy link
Contributor

roeeba commented Feb 1, 2017

It is in our plans to have better support for all popular framework, including a Xamarin SDK. As it is currently not in our immediate plans, we have no ETA to share.

@jamesmontemagno
Copy link

Seems like you could just move this over to a .NET Standard library so you could support Xamarin, WPF, .NET, .NET Core, ASP.NET, and tons of other ones too. Might be worth investigating making this investment for all developers.

@jamesmontemagno
Copy link

It actually looks like you have a .NET Standard Library already targeting 1.6. Although it has a weird name of "NetCoreShared" it isn't related to .NET Core at all. This actually is consumable in Xamarin.iOS and Android projects as Xamarin Support the 1.6 .NET Standard Library spec.

@NVentimiglia
Copy link
Author

The standard library simply does not work. The UploadAsync method never completes. The logs have this.

System.OperationCanceledException: The operation was canceled.

@YomesInc
Copy link
Contributor

Hey guys, replying by the order:

@NVentimiglia

Does Cloudinary support Xamarin mobile clients ? Xamarin uses the mono subset (4.5), not the full .net runtime.

Update, it is not supported.
After looking at the code it looks like some of the practices are pretty dated (HttpRequest being used instead of an HttpClient). Any plans to update this to a PCL project ?

Directly, no – it`s not supported. But –

@jamesmontemagno

Seems like you could just move this over to a .NET Standard library so you could support Xamarin, WPF, .NET, .NET Core, ASP.NET, and tons of other ones too. Might be worth investigating making this investment for all developers.

Yes, this might work across new .net core implementation. No one checked this on our end though.

@jamesmontemagno

It actually looks like you have a .NET Standard Library already targeting 1.6. Although it has a weird name of "NetCoreShared" it isn't related to .NET Core at all. This actually is consumable in Xamarin.iOS and Android projects as Xamarin Support the 1.6 .NET Standard Library spec.

Not exactly. NetCoreShared is a library that targets .net core and this is how it should be used in .net core based projects.

The standard library simply does not work. The UploadAsync method never completes. The logs have this.
System.OperationCanceledException: The operation was canceled.

Not sure what you mean by “standard library”. When we (RTL team) started supporting .net core, we reworked project's structure only and did not touch the code. What you are describing can be a bug that was not included in our scope and lived there for a long time. We'll consult with Cloudinary on this.

@YomesInc
Copy link
Contributor

@NVentimiglia and knowing the version about your last question about standard library could also help.

@jamesmontemagno
Copy link

So pulling down the project I saw that it is actually a .NET Standard Library, not a .NET Core Library, which is actually good because .NET Standard Libraries are .NET Libraries that can be consumed by any .NET Application that adhears to the profile selected, in this case 1.6: https://docs.microsoft.com/en-us/dotnet/standard/library

I was able to pull in the library into a Xamarin.Android Project by adding a few other NuGets to it and it compiled just fine, however I didn't actually test out the APIs though, but from what it sounds like it isn't finished yet.

There always seems to be a lot of confusion around .NET Core vs .NET Standard Libraries and how they mesh together..

.NET Core is a .NET Runtime that runs on Windows/Mac/Linux, just like .NET Framework has a .NET Runtime that runs on Windows, and Xamarin has a .NET Runtime that runs on Mac/iOS/Android/Windows/Linux/EverythingElse. Each of them you can create a Class Library for a single platform such as .NET Core or WPF for instance and take advantage of the .NET and Libraries of the platform.

However, since each platform has .NET you ideally want to just write some .NET code and have it be able to be consumed by any of these platforms. That is what a .NET Standard Library does and comes into play. It lays down a contract of what APIs each platform must implement to partake in each version... 1.0, 1.1, ... 1.6, 2.0 for instance. Each version contains more and more APIs, but may lose some platforms such as older windows phone/store devices.

So, if you target .NET Standard 1.6 you get: .NET Core, Xamarin, Mono, and .NET Framework 4.6.1 that can consume your library. Additionally, when the next version of UWP comes out that support .NET Standard 2.0 it can also consume a 1.6 library. These platforms are documented on the GitHub link I sent. Hope that helps.

@YomesInc
Copy link
Contributor

Exactly, @jamesmontemagno We targeted .NET Standard 1.6 to be able to work in .net core and other related projects.

@NVentimiglia Please let me know the version so we'd start working on it.

@NVentimiglia
Copy link
Author

@RTLcoil I pulled from master.

Testing on a Xamarin.Forms 2.3.4.247 Android, IOS, and PCL project

@YomesInc
Copy link
Contributor

@NVentimiglia Thank you. Could you also clarify if what was the DLL version used? NetCoreShared or cloudinaryDotNet. Seems it was NetCoreShared, but just want to make sure.

@NVentimiglia
Copy link
Author

Yes, NetCoreShared.

@Emixam23
Copy link

Emixam23 commented Sep 13, 2017

Hi,

So I have a question, how can you change the .NET Standard Platform from 1.5 to 1.6 since it's not in the list?

Is it because I'm generating the Xamarin PCL solution from a Mac?

Thank,

Max

@YomesInc
Copy link
Contributor

@Emixam23 not sure I understand your question and the list you are referring to, but we do support 1.6.

Could you clarify what you mean?

@Emixam23
Copy link

I cannot change the target as the others explained, I can only chose the framework 1.5, I don't have the the 1.6 as target Framework

@YomesInc
Copy link
Contributor

@Emixam23 “I can only chose the framework 1.5”
Could you clarify where can you only chose 1.5? Also, what environment do you use?

@Emixam23
Copy link

Yes sorry !

I'm on MacBook Pro OS X (Sierra). I'm using Visual Studio (7.1.3). My project has the following project.json file:

{
  "dependencies": {
    "Xamarin.Forms": "2.3.4.270"
  },
  "frameworks": {
    ".NETPortable,Version=v4.5,Profile=Profile111": {}
  }
}

When I go to PROJECT -> Options -> General, the checkbox [.NET Portable PCL 4.5 - Profile 111] is checked.

However, if I follow the link above, I can't, if I check the [.NET Standrad Platform netstandard1.5], I can't change to 1.6 or 2.0, I can only change in the range of 1.0 to 1.5

@YomesInc
Copy link
Contributor

Thanks, @Emixam23 a few questions:

  1. Could you clarify how exactly do you add Cloudinary into your xmarin project?
  2. If you don't add Cloudinary, can you change the target in the project to 1.6?

@Emixam23
Copy link

Emixam23 commented Sep 15, 2017

Well, I can't add it...

Over the PCL part, it throws :

*Running non-parallel restore.
Reading project file /Users/emixam23/Workspace/dev/PROJECT/PROJECT/PROJECT.csproj.
Restoring packages for /Users/emixam23/Workspace/dev/PROJECT/PROJECT/project.json...
Restoring packages for .NETPortable,Version=v4.5,Profile=Profile111...
Resolving conflicts for .NETPortable,Version=v4.5,Profile=Profile111...
Checking compatibility of packages on .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for PROJECT 1.0.0 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Microsoft.Bcl 1.1.10 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Microsoft.Bcl.Build 1.0.21 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Microsoft.Net.Http 2.2.29 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Newtonsoft.Json 10.0.3 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for PCLCrypto 2.0.147 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for PCLStorage 1.0.2 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Plugin.Permissions 2.0.1 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Xam.Plugin.Connectivity 3.0.2 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Xam.Plugin.Geolocator 4.0.1 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Xam.Plugin.Media 3.0.1 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Xam.Plugin.PushNotification 1.2.4 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Xamarin.Auth 1.5.0.3 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Xamarin.Forms 2.3.4.270 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for Xamarin.Forms.Maps 2.3.4.270 with .NETPortable,Version=v4.5,Profile=Profile111.
Checking compatibility for CloudinaryDotNet 1.0.30 with .NETPortable,Version=v4.5,Profile=Profile111.
Package CloudinaryDotNet 1.0.30 is not compatible with portable45-net45+win8+wpa81 (.NETPortable,Version=v4.5,Profile=Profile111). Package CloudinaryDotNet 1.0.30 supports:

  • net35 (.NETFramework,Version=v3.5)
  • net40 (.NETFramework,Version=v4.0)
    Checking compatibility for Validation 2.2.8 with .NETPortable,Version=v4.5,Profile=Profile111.
    Checking compatibility for PInvoke.NCrypt 0.3.2 with .NETPortable,Version=v4.5,Profile=Profile111.
    Checking compatibility for PInvoke.Windows.Core 0.3.2 with .NETPortable,Version=v4.5,Profile=Profile111.
    Checking compatibility for PInvoke.BCrypt 0.3.2 with .NETPortable,Version=v4.5,Profile=Profile111.
    Checking compatibility for PInvoke.Kernel32 0.3.2 with .NETPortable,Version=v4.5,Profile=Profile111.
    One or more packages are incompatible with .NETPortable,Version=v4.5,Profile=Profile111.
    Incompatible packages: 1
    Package restore failed. Rolling back package changes for 'PROJECT'.*

On android:

Attempting to gather dependency information for package 'CloudinaryDotNet.1.0.30' with respect to project 'PROJECT.Droid', targeting 'MonoAndroid,Version=v7.1'
GET https://api.nuget.org/v3/registration3-gz-semver2/cloudinarydotnet/index.json
OK https://api.nuget.org/v3/registration3-gz-semver2/cloudinarydotnet/index.json 166ms
Total number of results gathered : 92
Gathering dependency information took 175.25 ms
Summary of time taken to gather dependencies per source :
https://api.nuget.org/v3/index.json - 174.39 ms
Attempting to resolve dependencies for package 'CloudinaryDotNet.1.0.30' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'CloudinaryDotNet.1.0.30'
Resolved actions to install package 'CloudinaryDotNet.1.0.30'
Retrieving package 'CloudinaryDotNet 1.0.30' from 'nuget.org'.
For adding package 'CloudinaryDotNet.1.0.30' to project 'PROJECT.Droid' that targets 'monoandroid71'.
Install failed. Rolling back...
Package 'CloudinaryDotNet.1.0.30' does not exist in project 'PROJECT.Droid'
Package 'CloudinaryDotNet.1.0.30' does not exist in folder '/Users/emixam23/Workspace/dev/PROJECT/packages'
Executing nuget actions took 51.5 ms
Could not install package 'CloudinaryDotNet 1.0.30'. You are trying to install this package into a project that targets 'MonoAndroid,Version=v7.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.

@YomesInc
Copy link
Contributor

Thanks @Emixam23, let me check this with the team next week.

@YomesInc
Copy link
Contributor

@Emixam23 So I checked it and the package that you are using does not support netstandard. We have a package which does support it internally and it should be published soon.

@Emixam23
Copy link

Emixam23 commented Dec 6, 2017

Thanks to @jamesmontemagno for his video for sharing a .NET Core 2.0 project instead of a PCL. However, even if I can add the CloudinaryDotNet into both .NET Core 2.0 Project and Android side, I have compilation errors such as :

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(2,2): Error: Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'System.Text.Encodings.Web, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. Perhaps it doesn't exist in the Mono for Android profile?
File name: 'System.Text.Encodings.Web.dll'
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference, Mono.Cecil.ReaderParameters parameters) [0x00099] in /Users/builder/data/lanes/5749/9cfa7836/source/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:229
at Java.Interop.Tools.Cecil.DirectoryAssemblyResolver.Resolve (Mono.Cecil.AssemblyNameReference reference) [0x00000] in /Users/builder/data/lanes/5749/9cfa7836/source/xamarin-android/external/Java.Interop/src/Java.Interop.Tools.Cecil/Java.Interop.Tools.Cecil/DirectoryAssemblyResolver.cs:179
at Xamarin.Android.Tasks.ResolveAssemblies.AddAssemblyReferences (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver, System.Collections.Generic.ICollection`1[T] assemblies, Mono.Cecil.AssemblyDefinition assembly, System.Boolean topLevel) [0x0015c] in <998d78d5ee6d46b491b77aff8eeaf856>:0
at Xamarin.Android.Tasks.ResolveAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver resolver) [0x001c7] in <998d78d5ee6d46b491b77aff8eeaf856>:0 (NightLine.Droid)

Any idea @RTLcoil?

@YomesInc
Copy link
Contributor

YomesInc commented Dec 9, 2017

@Emixam23 can you provide a step by step description of how you get this error? We would like to reproduce it on our end, so we also need to know your Android environment, pack version, etc.

@Emixam23
Copy link

Hi,

I am sorry but it was a mistake from my side. I tried with the bad package I guess.
Cloudinary.Core works fine :)

Thanks

@Emixam23
Copy link

It works with Xamarin :) I have a Xamarin solution (.NET Core 1.6, Android 7.1, iOS, UWP Build 16299)

There is an example of how you can use it:

public class CloudinarySDK
{
    private Cloudinary cloudinary { get; set; }

    public CloudinarySDK()
    {

    }

    public void Init()
    {
        Account account = new Account(
                "my_cloud_name",
                "my_api_key",
                "my_api_secret");

        cloudinary = new Cloudinary(account);
    }

    /// <summary>
    /// Upload a file by its path.
    /// </summary>
    /// <returns>The upload end path.</returns>
    /// <param name="path">Path.</param>
    public async Task<string> Upload(string path)
    {
        ImageUploadParams uploadParams = new ImageUploadParams()
        {
            File = new FileDescription(path),
            PublicId = String.Format("{0}.{1}.jpg", User.GetUserInstance().ID, DateTime.Now.ToString("yyyy-MM-dd-HH:mm:ss"))
        };
        ImageUploadResult uploadResult = await cloudinary.UploadAsync(uploadParams);

        return uploadResult.Uri.ToString();
    }

    /// <summary>
    /// Delete the specified url.
    /// </summary>
    /// <returns>The delete.</returns>
    /// <param name="url">URL.</param>
    public void Delete(string url)
    {
        DeletionParams deletionParams = new DeletionParams(url);
        cloudinary.DestroyAsync(deletionParams);
    }
}

Hope it helps !

@YomesInc
Copy link
Contributor

Hey @Emixam23, seems like there's another pack you should download to make it work, take a look at this and let me know if this clarifies https://www.dropbox.com/s/zd4ikxxuaixkagl/nOoFF.png?dl=0
One is official the other one is not. While we appreciate contributions by our community, we can only rely on packs which went through our review. We checked your case with our pack and it did work. Make sure you install the additional required packages and change settings with xamarin. If you need help with that - let me know.

@Emixam23
Copy link

Hey !

I just tried to give working solution :) Right now I am busy but in like 2 weeks, I will work again with cloudinary, that will be the moment to try your situation :)

best,

@YomesInc
Copy link
Contributor

Sounds good!

@ediewoelfle
Copy link

I am having the same errors as @Emixam23. Has the netstandard version been released, @RTLcoil ?

@Emixam23
Copy link

If you're having the same problem it means you don't have the right package.. you need CloudinaryDotNet and not CloudinaryCore

Max :)

@ediewoelfle
Copy link

ediewoelfle commented Apr 26, 2018

My apologies, I didn't clarify. I am using CloudinaryDotNet. I have decided to rollback to 1.6 and drop my RestSharp NuGet (only works with 2.0). :(

@idobarnoam
Copy link

@ediewoelfle Could you maybe elaborate on what are you experiencing?

also if you could share the details of your environment it would also help us in understanding.

@c-lamont
Copy link

c-lamont commented Aug 24, 2018

@idobarnoam I have added the CloudinaryDotNet package to my projects but the Xamarin Android project does not compile and complains of Could not load assembly 'CloudinaryDotNet, Version=1.3.1.0, Culture=neutral, PublicKeyToken=c8234dc617ae7841'. Perhaps it doesn't exist in the Mono for Android profile?

I tried the .NET Core SDK as described here. This compiles but does not upload an image using the following code. I have tried uploading the path and the stream.

Account account = new Account(
    "xxx",
    "xxx",
    "xxx");

_cloudinary = new Cloudinary(account);


using (var photoStream = mediaFile.GetStream())
{
    ImageUploadParams uploadParams1 = new ImageUploadParams()
    {
        File = new FileDescription(mediaFile.Path, photoStream),
        PublicId = String.Format(mediaFile.Path)
    };
    ImageUploadResult uploadResult1 = await _cloudinary.UploadAsync(uploadParams1);

    var test = uploadResult1.Uri?.ToString();
}


ImageUploadParams uploadParams2 = new ImageUploadParams()
{
    File = new FileDescription(mediaFile.Path),
    PublicId = String.Format(mediaFile.Path)
};
ImageUploadResult uploadResult2 = await _cloudinary.UploadAsync(uploadParams2);
var test2 = uploadResult2.Uri?.ToString();

However both upload results return an object with all properties set to null, and there is nothing in the Cloudinary dashboard.

Edit

Turns out the file size was too big, I got this message from the Json "File size too large. Got 10790535. Maximum is 10485760."

To confirm, this is using the .Net Core package.

@roeeba
Copy link
Contributor

roeeba commented Aug 26, 2018

Hi @c-lamont. I couldn't manage to reproduce the issue you have with Xamarin Android. Could you please try removing the Cloudinary NuGet package and re-add it? let me know if that helps?

@c-lamont
Copy link

c-lamont commented Aug 27, 2018

@roeeba I tried multiple times. Removed all output paths and packages and restored them.

Also in the CloudinaryDotNet I noticed there is no UploadAsync method, only the Upload method.

@roeeba
Copy link
Contributor

roeeba commented Aug 27, 2018

Hi @c-lamont. Please try the following solution:
https://forums.xamarin.com/discussion/68974/system-io-filenotfoundexception-could-not-load-assembly-system-drawing
Specifically:
-> Close the solution
-> Delete all contents of the Packages folder (all the DLL’s referenced through Nuget)
-> Restart the solution
-> Build (this will cause Nuget to get all DLL’s again based on the packages.config)

Regarding the UploadAsync method. Currently, this method is not supported for Core. We might support it going forward.

@ah3eyy
Copy link

ah3eyy commented Jan 31, 2020

Severity Code Description Project File Line Suppression State
Error Can not resolve reference: System.Text.Encodings.Web, referenced by CloudinaryDotNet. Please add a NuGet package or assembly reference for System.Text.Encodings.Web, or remove the reference to CloudinaryDotNet..Getting this error and i really dont get y

@roeeba
Copy link
Contributor

roeeba commented Feb 2, 2020

@ah3eyy Can you please share the full error stacktrace and a minimal code project so we can try and replicate this error?

@roeeba roeeba self-assigned this Feb 2, 2020
@ah3eyy
Copy link

ah3eyy commented Feb 2, 2020 via email

@roeeba roeeba assigned const-cloudinary and unassigned roeeba Feb 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests