HeavenWu / slimdx

Automatically exported from code.google.com/p/slimdx
MIT License
0 stars 0 forks source link

Variable AsVector().Set() compile time exception when System.Drawing is not referenced (.NET 4) #772

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
following code gives a compile time error on the last line:

                Vector4 color = light.LightColor.ToVector4();
                var variable = lightEffect.GetVariableByName("vColor");
                var vectorVariable = variable.AsVector();                    
                vectorVariable.Set(color);

The type 'System.Drawing.Color' is defined in an assembly that is not 
referenced. You must add a reference to assembly 'System.Drawing, 
Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

Original issue reported on code.google.com by stijn.ta...@gmail.com on 21 Jan 2011 at 3:51

GoogleCodeExporter commented 8 years ago
The problem is that the Color4 type in SlimDX has an implicit conversion from 
System.Drawing.Color, so the compiler is looking for it to make sure it gets 
the right overload of Set().

I don't see a way to fix that without breaking things for other users. Is there 
some reason you can't reference System.Drawing? It's not like adding a 
reference increases the size of your assembly. Also, assemblies are loaded 
on-demand, so if you never use the types from it, it won't even get loaded into 
your process at runtime.

Original comment by Mike.Popoloski on 22 Jan 2011 at 5:08

GoogleCodeExporter commented 8 years ago
why does it give that error for the code above? 
i'm trying to Set() a Vector4, not a Color4 as i already converted it a few 
lines above.
so either the compiler is stupid enough to look for an implicit overload even 
if an explicit one exists, or something else is wrong?

Original comment by stijn.ta...@gmail.com on 23 Jan 2011 at 6:47

GoogleCodeExporter commented 8 years ago
It has to build a candidate set of overloads to determine the best one to call. 
To do this, it needs to know the conversions to and from each type in each 
overload. Since the assembly isn't referenced it doesn't know anything about 
the Color type, so it gives an error.

Original comment by Mike.Popoloski on 23 Jan 2011 at 7:03

GoogleCodeExporter commented 8 years ago
great :'(

Original comment by stijn.ta...@gmail.com on 23 Jan 2011 at 9:13

GoogleCodeExporter commented 8 years ago
I don't see why this is a problem. Just add the reference. If you don't 
actually use any of the types, the assembly won't get loaded at runtime.

Original comment by Mike.Popoloski on 23 Jan 2011 at 9:28