I have the following code:
namespace FVProductions.Base
{
public struct Color
{
public byte B, G, R, A;
public Color(float r, float g, float b, float a)
{
R = (byte)(Math.Min(1.0f, Math.Max(0.0f, r)) * 255);
G = (byte)(Math.Min(1.0f, Math.Max(0.0f, g)) * 255);
B = (byte)(Math.Min(1.0f, Math.Max(0.0f, b)) * 255);
A = (byte)(Math.Min(1.0f, Math.Max(0.0f, a)) * 255);
}
public Color(Vector3 rgb)
:this(rgb.X,rgb.Y,rgb.Z,1)
{
}
}
}
namespace FVProductions.Base.Graphics
{
public class ShaderParameter<T>
{
private T Value;
public T GetValue() { return Value; }
}
}
namespace FVProductions.NewGame
{
public class TerrainShader : Shader, IFullTextured, IStandardLit
{
private ShaderParameter<Vector3> epAmbient;
public FVProductions.Base.Color AmbientColor
{
get { return new FVProductions.Base.Color(epAmbient.GetValue()); }
set { epAmbient.SetValue(value.ToVector3()); }
}
}
}
The type, FVProductions.Base.Color is in a referenced library. epAmbient.GetValue returns a Vector3 and FVProductions.Base.Color has a constructor with a single Vector3 parameter. The project does not reference System.Drawing. However, the compiler is generating the following error:
error CS0012: The type ‘System.Drawing.Color’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.
That’s on the TerrainShader.AmbientColor get{} line, at the return keyword. Why would the compiler ever assume an explicitly declared type is another?
Found it. FVProductions.Base.Color is a base class in a base library and has a constructor that accepts a System.Drawing.Color. The project that has the problem code does not reference System.Drawing. When using the Color class, it was having trouble linking the System.Drawing.Color constructor even though it wasn’t used. So, I discovered two solutions:
Have the upper library reference the System.Drawing library even though it won’t be used.
Remove the System.Drawing.Color constructor from FVProductions.Base.Color.
Either will allow the project to compile.