This is the code used to create the .dll:
string[] data = new string[] {"Carrier"};
string enumName = "AgentCode";
AppDomain currentDomain = AppDomain.CurrentDomain;
AssemblyName name = new AssemblyName("DatabaseEnums");
AssemblyBuilder assemblyBuilder = currentDomain.DefineDynamicAssembly(
name,
AssemblyBuilderAccess.RunAndSave,
"/Assets");
ModuleBuilder moduleBuilder = assemblyBuilder.DefineDynamicModule(name.Name,
name.Name + ".dll");
EnumBuilder myEnum = moduleBuilder.DefineEnum(
"Lockstep.Data." + enumName,
TypeAttributes.Public,
typeof(byte));
for (int i = 0; i < data.Length; i++) {
TData item = data[i];
myEnum.DefineLiteral (data[i]);
}
myEnum.CreateType();
assemblyBuilder.Save(name.Name + ".dll");
For some reason, this error pops up when I try to use the enum in the .dll:
This line causes the compiler error:
Lockstep.Data.AgentCode ac = Lockstep.Data.AgentCode.Carrier;
This is the full log of the error (for some reason compiler warnings showed up in the same log as the error):
Assets/Lockstep/Core/Simulation/Physics/Core/CollisionPair.cs(254,33): warning CS0162: Unreachable code detected
Assets/Lockstep/Core/Simulation/Physics/Core/CollisionPair.cs(269,33): warning CS0162: Unreachable code detected
Assets/Lockstep/Core/Simulation/Physics/Core/CollisionPair.cs(285,33): warning CS0162: Unreachable code detected
Assets/Lockstep/Core/Simulation/Physics/Core/CollisionPair.cs(301,33): warning CS0162: Unreachable code detected
Assets/Lockstep/Core/Simulation/Physics/Core/LSBody.cs(168,33): warning CS1717: Assignment made to same variable; did you mean to assign something else?
Assets/Lockstep/Core/Utility/Array2D.cs(17,38): warning CS0219: The variable test' is assigned but its value is never used Assets/Lockstep/Core/Utility/Serialization/Compressor.cs(19,38): warning CS0219: The variable outStream’ is assigned but its value is never used
error CS0656: The compiler required member `Lockstep.Data.AgentCode.value__’ could not be found or is inaccessible
Unhandled Exception: System.InvalidCastException: Cannot cast from source type to destination type.
at Mono.CSharp.Constant.CreateConstant (System.Type t, System.Object v, Location loc) [0x00000] in :0
at Mono.CSharp.Constant.CreateConstant (System.Type t, System.Object v, Location loc) [0x00000] in :0
at Mono.CSharp.ExternalConstant.CreateConstantReference (Location loc) [0x00000] in :0
at Mono.CSharp.ConstantExpr.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.MemberAccess.DoResolve (Mono.CSharp.ResolveContext ec, Mono.CSharp.Expression right_side) [0x00000] in :0
at Mono.CSharp.MemberAccess.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in :0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.Assign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.SimpleAssign.DoResolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec, ResolveFlags flags) [0x00000] in :0
at Mono.CSharp.Expression.Resolve (Mono.CSharp.ResolveContext ec) [0x00000] in :0
at Mono.CSharp.ExpressionStatement.ResolveStatement (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.StatementExpression.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.Block.Resolve (Mono.CSharp.BlockContext ec) [0x00000] in :0
at Mono.CSharp.ToplevelBlock.Resolve (Mono.CSharp.FlowBranching parent, Mono.CSharp.BlockContext rc, Mono.CSharp.ParametersCompiled ip, IMethodData md) [0x00000] in :0
Why is this happening and how do I fix it?