question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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'.

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
KSemenenkocommented, Mar 1, 2018

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

0reactions
afbasecommented, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found