- Home /
Unable to debug dynamically loaded assembly DLL that was loaded via Assembly.load() in Unity 5.5.1f1(64 bit)
I am loading an assembly as follows:
var bytes = File.ReadAllBytes("E:/Code/Projects/MyUtilities/bin/Debug/MyUtilities.dll");
Assembly loadedAssembly = Assembly.Load(bytes);
The assembly is loaded fine and I can call functions with invoke: System.Type type = loadedAssembly.GetType("DLLTest.MyUtilities");
FieldInfo field = type.GetField("c");
Debug.Log(field.GetValue(null));
// get the method
MethodInfo method = type.GetMethod("test", BindingFlags.Public | BindingFlags.Static);
object[] args = new object[1];
args[0] = 2;
var result = method.Invoke(null, args).ToString(); // assuming it doesn't take parameters
When I add the DLL project into the UNity solution and set a break point in the DLL project its not hit. The PDB is right beside the DLL. I have tried to keep it beside Library\ScriptAssemblies\Assembly-CSharp.dll as well. Still the breakpoint is not hit in the DLL code.
Tried all solution mentioned here: http://stackoverflow.com/questions/1295807/debug-dynamically-loaded-assembly-in-visual-studio-net?noredirect=1&lq=1
Does it have to be a mdb file rather than a PDB file?
I am using .Net version 3.5 for the DLL. After the project is built as a dll and pdb, I tried pdb2mdb.exe but it gives the following error:
Unhandled Exception: System.BadImageFormatException: Invalid PE file File name: 'E:\Code\Projects\$$anonymous$$yUtilities\bin\Debug\$$anonymous$$yUtilities.pdb' ---> $$anonymous$$ono.Cecil.Binary.ImageFormatException: Invalid PE File Signature at $$anonymous$$ono.Cecil.Binary.ImageReader.VisitDOSHeader(DOSHeader header) at $$anonymous$$ono.Cecil.Binary.Image.Accept(IBinaryVisitor visitor) at $$anonymous$$ono.Cecil.Binary.ImageReader.Read(String file) at $$anonymous$$ono.Cecil.Binary.ImageReader.Read(String file) at $$anonymous$$ono.Cecil.AssemblyFactory.GetAssembly(String file) at Pdb2$$anonymous$$db.Driver.$$anonymous$$ain(String[] args)
Ok, so what did work is placing the DLL and PDB in the Assets/plugins folder of the Unity project. But why do I need to do this. The PDB is also present where the DLL is compiled at E:/Code/Projects/$$anonymous$$yUtilities/bin/Debug/$$anonymous$$yUtilities.dll
Is it necessary to have a post build copy of the DLL and PDB into the Assets/plugins folder?
Can't I simply tell Unity to search for DLL assets at E:/Code/Projects/$$anonymous$$yUtilities/bin/Debug/ as well?
Your answer
Follow this Question
Related Questions
Windows Phone 8.1 Assembly 0 Answers
Using a DLL assembly on Mac 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers