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

Error CS0012: The type 'QuantizedColor' is defined in an assembly that is not referenced. You must add a reference to assembly 'ColorThief.Forms, Version=1.1.0.1, Culture=neutral, PublicKeyToken=null'. #9

Open
afbase opened this issue Feb 21, 2018 · 7 comments

Comments

@afbase
Copy link

afbase commented Feb 21, 2018

Hi @KSemenenko

I'm trying to follow your suggestion in the prior issue:

create proxy for ColorThief platform specific implementation using Xamarin Forms DependencyService.

In my PCL Xamarin project I have an interface and added reference to ksesmenenko.ColorThief.Forms v1.0.0.4:

using ColorThiefDotNet;
...
public interface IColorThiefHelper
{
    List<QuantizedColor> GetPalette(string sourceImage, int colorCount);
    QuantizedColor GetColor(string sourceImage);
}

and then also in my PCL Xamarin project call it using dependency service:

var colorTask = DependencyService.Get<IColorThiefHelper>().GetPalette(Logo, 8);
var backgroundColor = Color.FromHex(colorTask.FirstOrDefault().Color.ToHexString());
var foregroundColor = Color.FromHex(colorTask.LastOrDefault().Color.ToHexString());
BackgroundColor = backgroundColor;
TextInverseColor = foregroundColor;

Finally in my iOS project I have added reference to ksesmenenko.ColorThief.Forms v1.0.0.4 again and then made the dependency service implementation like so:

[assembly: Dependency(typeof(ColorThiefHelper))]
namespace IOSNameSpace
{
    public class ColorThiefHelper : IColorThiefHelper  {
        private ColorThief Thief { get; set; }
        public ColorThiefHelper()
        {
            Thief = new ColorThief();
        }    

        static UIImage FromUrl(string uri)
        {
            using (var url = new NSUrl(uri))
            using (var data = NSData.FromUrl(url))
                return UIImage.LoadFromData(data);
        }    

        public List<QuantizedColor> GetPalette(string sourceImage, int colorCount)
        {
            UIImage image = FromUrl(sourceImage);
            return Thief.GetPalette(image,colorCount,10,true);
        }
        public QuantizedColor GetColor(string sourceImage)
        {
            UIImage image = FromUrl(sourceImage);
            return Thief.GetColor(image, 10, true); 
        }
}

And here I get the error on the ColorThiefHelper class :

Error CS0012: The type 'QuantizedColor' is defined in an assembly that is not referenced. You must add a reference to assembly 'ColorThief.Forms, Version=1.1.0.1, Culture=neutral, PublicKeyToken=null'. (CS0012)

The bug is strange as there is no Version=1.1.0.1 of ColorThief.Forms in nuget.

Do you know what might be the problem?

@KSemenenko
Copy link
Owner

Hello @afbase, thanks for your detailed description.
most likely I did not correctly make a nuget for PCL.
I will fix it)
You are already using .net standard?

@afbase
Copy link
Author

afbase commented Feb 21, 2018

@KSemenenko
I am using .NET Portable PCL 4.5 - Profile111, not .net standard.

@KSemenenko
Copy link
Owner

KSemenenko commented Feb 21, 2018

@afbase, why do you need DI?
For Xamarin.Forms you need only

await CrossColorThief.Current.GetPalette(sourceImage);

or you want to use new method like FromUrl?

@afbase
Copy link
Author

afbase commented Feb 23, 2018

@KSemenenko

For Xamarin.Forms you need only

await CrossColorThief.Current.GetPalette(sourceImage);

If I write this line of code in my PCL project, I get a System.NotImplementedException error. The error message for me is not clear. If I write this line of code in my PCL project, do I need to add a colorthief package to my iOS project and android projects as well?

or you want to use new method like FromUrl?

I'd rather try to write all of this in a PCL project but I'm beginning to think this is not possible.

@afbase
Copy link
Author

afbase commented Feb 23, 2018

I think where this issue is coming up is ColorThief reference/object confusion between PCL and platform projects.

I think what we want in the PCL project is using ColorThiefDotNet.Forms;:

using ColorThiefDotNet.Forms;
...
public interface IColorThiefHelper
{
    List<QuantizedColor> GetPalette(string sourceImage, int colorCount);
    QuantizedColor GetColor(string sourceImage);
}

instead of what I originally had here:

using ColorThiefDotNet;
...
public interface IColorThiefHelper
{
    List<QuantizedColor> GetPalette(string sourceImage, int colorCount);
    QuantizedColor GetColor(string sourceImage);
}

If I try using ColorThiefDotNet.Forms;, I get an error stating that QuantizedColor could not be found. I think this is where quantizedcolor should be instead of just the ColorThiefDotNet namespace. If that is the case I think that resolves the problem. I just forked over the repo, I may try to play with it a bit and see if it works this weekend.

@KSemenenko
Copy link
Owner

@afbase I think I found a problem, it's still in the structure of the project.
apparently I need to do the refactoring

@afbase
Copy link
Author

afbase commented Mar 5, 2018

@KSemenenko

I may follow up on this later in my development near the end of March as I have reprioritized my development as this became a bit of a blocker. I am working on other features but what I am now thinking is to refactor the Shared library's implementation to a dependency service onto interfaces implemented in the various platform libraries.

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

2 participants