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 issueHi @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:
- Created 6 years ago
- Comments:7 (3 by maintainers)
@afbase I think I found a problem, it’s still in the structure of the project. apparently I need to do the refactoring
@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.