Currently getting error whenever I try to invoke any members of my Caravan.Math
namespace, which include:
struct Vector2<>
struct Vector3<>
static class Math
like System.Math
but for my VectorsIn my entry point class, Caravan.Program
I get a TypeLoadException whenever I reference either Vector2 or Vector3.
There are no compile errors upon building, and when I remove references to the Vectors it will run just fine. Full class definitions will be at the bottom, any examples will show code that is in addition to the bottom.
The full error details are:
System.TypeLoadException
HResult=0x80131522
Message=Could not load type 'Caravan.Math.Vector2`1' from assembly 'Caravan, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
Source=<Cannot evaluate the exception source>
StackTrace:
<Cannot evaluate the exception stack trace>
NOTE: At every step of debugging so far, I have tried rebuilding, cleaning, deleting bin and obj folders, reinstalling dependent packages, I have only one project in the solution, all classes are in the same project, the only external DLLs are for thus far fully functional libraries downloaded form NuGet.
Currently, I am just looking for a "Whats next" with debugigng, because I can not seem to squeeze any further details out of VisualStudio or Google.
I first got the error, when attempting to define some testing statics inside Program
:
private static CharBrush charTest = new CharBrush {
new KeyValuePair<Vector2<int>, char>(new Vector2<int>(0, 0), 'a'),
new KeyValuePair<Vector2<int>, char>(new Vector2<int>(1, 0), 'b'),
new KeyValuePair<Vector2<int>, char>(new Vector2<int>(2, 0), 'c'),
new KeyValuePair<Vector2<int>, char>(new Vector2<int>(0, 1), 'd'),
new KeyValuePair<Vector2<int>, char>(new Vector2<int>(1, 1), 'e'),
new KeyValuePair<Vector2<int>, char>(new Vector2<int>(2, 1), 'f'),
};
private static ColorBrush colorTest = new ColorBrush {
new KeyValuePair<Vector2<int>, Vector3<int>>(new Vector2<int>(0, 0), new Vector3<int>(255, 255, 000)),
new KeyValuePair<Vector2<int>, Vector3<int>>(new Vector2<int>(1, 0), new Vector3<int>(255, 000, 255)),
new KeyValuePair<Vector2<int>, Vector3<int>>(new Vector2<int>(2, 0), new Vector3<int>(000, 255, 255)),
new KeyValuePair<Vector2<int>, Vector3<int>>(new Vector2<int>(0, 1), new Vector3<int>(255, 000, 000)),
new KeyValuePair<Vector2<int>, Vector3<int>>(new Vector2<int>(1, 1), new Vector3<int>(000, 255, 000)),
new KeyValuePair<Vector2<int>, Vector3<int>>(new Vector2<int>(2, 1), new Vector3<int>(000, 000, 255)),
};
public static void Main()
{
Draw(charTest, colorTest, Vector2<int>.One);
}
When this failed, I commented it all out, replacing it simply with:
public static void Main()
{
var test = new Vector2<int>(1, 1);
}
Which produced the identical error. Finally, I tried
public static void Main()
{
var test = new Vector3<int>(1, 1, 1);
}
Which oddly enough, gave me the exact same error, despite me not using a Vector2
at all, even after commenting out the Draw method.
Program The entry point of the Application
public class Program
{
public static void Main()
{
}
public static void Draw(CharBrush chars, ColorBrush color, Vector2<int> offset)
{
Vector2<int> target = Vector2<int>.Zero;
int r = 0;
int g = 0;
int b = 0;
Console.Clear();
foreach (KeyValuePair<Vector2<int>, Char> entry in chars)
{
target = Math.Math.Add(entry.Key, offset);
if (target.X >= 0 && target.Y >= 0)
{
color[entry.Key].AsReferences(ref r, ref g, ref b);
Console.SetCursorPosition(target.X, target.Y);
Console.Write(entry.Value, Color.FromArgb(r, g, b));
}
}
}
}
Vector2 A general container, keeping two of the same type, and supporting math operations through the class Caravan.Math.Math
class
public struct Vector2<T> : IEquatable<Vector2<T>>, IEquatable<Vector3<T>>
{
public Vector2(T x, T y) { this.x = x; this.y = y; }
T x;
T y;
static Vector2<int> zero = new Vector2<int>(0, 0);
static Vector2<int> one = new Vector2<int>(1, 1);
static Vector2<int> unitX = new Vector2<int>(1, 0);
static Vector2<int> unitY = new Vector2<int>(0, 1);
public T X { get => x; set => x = value; }
public T Y { get => y; set => y = value; }
public static Vector2<int> Zero { get => zero; }
public static Vector2<int> One { get => one; }
public static Vector2<int> UnitX { get => unitX; }
public static Vector2<int> UnitY { get => unitY; }
public bool Equals(Vector2<T> other)
{
return this.x.Equals(other.x) && this.y.Equals(other.y);
}
public bool Equals(Vector3<T> other)
{
return this.x.Equals(other.X) && this.y.Equals(other.Y);
}
}
Vector3 A general container, keeping three of the same type, and supporting math operations through the class Caravan.Math.Math
class
public struct Vector3<T> : IEquatable<Vector3<T>>, IEquatable<Vector2<T>>
{
public Vector3(T x, T y, T z) { this.x = x; this.y = y; this.z = z; }
T x;
T y;
T z;
public T X { get => x; set => x = value; }
public T Y { get => y; set => y = value; }
public T Z { get => z; set => z = value; }
public bool Equals(Vector3<T> other)
{
return this.x.Equals(other.x) && this.y.Equals(other.y) && this.z.Equals(other.z);
}
public bool Equals(Vector2<T> other)
{
return this.x.Equals(other.X) && this.y.Equals(other.Y);
}
public void AsReferences(ref T x, ref T y, ref T z)
{
x = this.x;
y = this.y;
z = this.z;
}
}
Math Supports math operations on Vector2
s and Vector3
s of type int and float.
public static partial class Math
{
public static Vector3<int> Add(Vector3<int> left, Vector3<int> right) => new Vector3<int>(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
public static Vector3<float> Add(Vector3<float> left, Vector3<float> right) => new Vector3<float>(left.X + right.X, left.Y + right.Y, left.Z + right.Z);
public static Vector3<int> Subtract(Vector3<int> left, Vector3<int> right) => new Vector3<int>(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
public static Vector3<float> Subtract(Vector3<float> left, Vector3<float> right) => new Vector3<float>(left.X - right.X, left.Y - right.Y, left.Z - right.Z);
public static Vector2<int> Add(Vector2<int> left, Vector2<int> right) => new Vector2<int>(left.X + right.X, left.Y + right.Y);
public static Vector2<float> Add(Vector2<float> left, Vector2<float> right) => new Vector2<float>(left.X + right.X, left.Y + right.Y);
public static Vector2<int> Subtract(Vector2<int> left, Vector2<int> right) => new Vector2<int>(left.X - right.X, left.Y - right.Y);
public static Vector2<float> Subtract(Vector2<float> left, Vector2<float> right) => new Vector2<float>(left.X - right.X, left.Y - right.Y);
}
Map is a wrapper for a dictionary that will eventually provide extra functionality for accessing adjacent members.
public class Map<T> : ICollection<KeyValuePair<Vector2<int>, T>>, IEnumerable<KeyValuePair<Vector2<int>, T>>
{
#region Inheritance
public int Count => ((ICollection<KeyValuePair<Vector2<int>, T>>)data).Count;
public bool IsReadOnly => ((ICollection<KeyValuePair<Vector2<int>, T>>)data).IsReadOnly;
public IEnumerator<KeyValuePair<Vector2<int>, T>> GetEnumerator() => data.GetEnumerator();
public void Add(KeyValuePair<Vector2<int>, T> item) => ((ICollection<KeyValuePair<Vector2<int>, T>>)data).Add(item);
public void Clear() => ((ICollection<KeyValuePair<Vector2<int>, T>>)data).Clear();
public bool Contains(KeyValuePair<Vector2<int>, T> item) => ((ICollection<KeyValuePair<Vector2<int>, T>>)data).Contains(item);
public void CopyTo(KeyValuePair<Vector2<int>, T>[] array, int arrayIndex) => ((ICollection<KeyValuePair<Vector2<int>, T>>)data).CopyTo(array, arrayIndex);
public bool Remove(KeyValuePair<Vector2<int>, T> item) => ((ICollection<KeyValuePair<Vector2<int>, T>>)data).Remove(item);
IEnumerator IEnumerable.GetEnumerator() => ((ICollection<KeyValuePair<Vector2<int>, T>>)data).GetEnumerator();
#endregion
Dictionary<Vector2<int>, T> data = new Dictionary<Vector2<int>, T>();
public T this[int x, int y]
{
get
{
return data[new Vector2<int>(x, y)];
}
set
{
Vector2<int> i = new Vector2<int>(x, y);
try
{
data[i] = value;
}
catch (KeyNotFoundException)
{
data.Add(i, value);
}
}
}
public T this[Vector2<int> i]
{
get
{
return data[i];
}
set
{
try
{
data[i] = value;
}
catch (KeyNotFoundException)
{
data.Add(i, value);
}
}
}
public class Member<U>
{
public Member(U data, Vector2<int> position)
{
this.data = data;
this.position = position;
}
public Member(U data, int x, int y)
{
this.data = data;
this.position = new Vector2<int>(x, y);
}
U data;
Vector2<int> position;
public U Data { get => data; set => data = value; }
public Vector2<int> Position { get => position; }
public static implicit operator U(Member<U> member) => member.data;
}
}
User contributions licensed under CC BY-SA 3.0