DynamoDS / Dynamo

Open Source Graphical Programming for Design
https://dynamobim.org
Other
1.74k stars 634 forks source link

Using DynamoCore.dll in a Stand-Alone C# Program #4907

Closed ColinDayOrg closed 9 years ago

ColinDayOrg commented 9 years ago

I am trying to make a simple C# program using DynamoCore that loads a graph from an XML file. However, I am running into an issue where VisualStudio says it can't load DynamoCore because it can't find the dll or one of its dependencies. (I have added a reference to the DynamoCore.dll file in my project).

Does anyone either know what I need to add for references or can point me to any examples of how to do this?

jnealb commented 9 years ago

Are you using the latest daily build from Dynamobim.org?

mjkkirschner commented 9 years ago

Hey Colin, I'm not sure of the exact dependencies, but a few things to try.

Are you sure it's not just a visual studio hiccup? (clean / close all tabs / restart etc?) What .net version are you targeting in your new project?

pboyer commented 9 years ago

@ColinDayOrg,

Is this a runtime error or a compile time error? Can you supply the specific error message you are seeing?

My guess is you are missing a reference for ProtoInterface.dll, DynamoUtilities.dll, or DynamoShapeManager.dll.

ColinDayOrg commented 9 years ago

Thanks all for the replies.

I am using version 0.8.0.1233 of Dynamo Studio.

Restarting Visual Studio did not appear to make any difference. I am targeting .Net Framework 4.5.

The issue I am seeing is a runtime error stating that DynamoCore or one of its dependencies could not be loaded. I am assuming that the issue is just that I need to add additional dll references. I added references to ProtoInterface.dll, DynamoUtilities.dll, and DynamoShapeManager.dll but it did not change the issue.

pboyer commented 9 years ago

@ColinDayOrg, I apologize for the difficulties!

I don't think it would make a difference, but Dynamo currently targets .NET 4.0 for compatibility reasons (Revit 2014).

Of course, it's not just that you make the appropriate compile time references, but that Dynamo's DLL's (and their dependencies) are discoverable at runtime.

The default lookup path for an assembly (i.e. a dll) is in the directory where the exe is located. IOW, DynamoCore needs to be in the same directory as your executable.

If this still doesn't work, you can use the AppDomain.AssemblyResolve event in order to see when the CLR fails to find a DLL.

You'd do something like this in your code before the runtime error:

AppDomain.CurrentDomain.AssemblyResolve += (e, a) => { 
    Console.WriteLine( a.Name ); 
    return null; 
}

This would print all of the dll's as the CLR attempts to load them. There are more details about the AssemblyResolve event here:

https://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve(v=vs.110).aspx

ColinDayOrg commented 9 years ago

Thanks, setting copy local resolved the issue.