I am able to run the AppInfo sample project, but not able to run the CodeRun example in the Navisworks 2013 API. What I did is open the Examples.sln solution with all the examples in VS2012. I have put the CodeRun.ADSK.dll and CodeRunLib.dll in the correct folder. I am able to open the CodeRun addin in Navisworks and get the code template, but when I click the "Run", it output the following error message:
System.NullReferenceException: Object reference not set to an instance of an object.
Stack Trace: at CodeRunLib.BaseGenerator.Generate(CodeDomProvider codeProvider, String sourceCode, String classToCreate, String callFunction, String& errors, String& consoleOutput)
at CodeRunLib.CodeRunCSharp.Generate(String code, String fullClassName, String mainFunction, String& errors, String& consoleOutput)
at CodeRun.Control.CodeRunControl.Generate(CodeRun codeRunner, String code, String fullClassName, String mainFunction, String& errors, String& consoleOutput)
If I tested on a machine with VS2010 installed only and built the sample in VS2010. It can work well. So it looks there is an issue with VS2012.
VS2012 uses .NET 4.5. It appears that there’s a problem fixed around System.Reflection.Assembly.Location, in that querying this property for a dynamically generated assembly should throw a NotSupportedException (either that or something changed that no longer silently absorbs this exception). This then gets translated to a NullReferenceException subsequently by later code.
The fix is to update line 60 of BaseGenerator.cs in the CodeRunLib example from:
if (!parameters.ReferencedAssemblies.Contains(asm.Location) && asm.Location != null && asm.Location != string.Empty)
if (!asm.IsDynamic && !parameters.ReferencedAssemblies.Contains(asm.Location) && asm.Location != null && asm.Location != string.Empty)i.e. Dynamically generated assemblies have no location & can’t be added to the compiler’s reference list.