Question-and-Answer Resource for the Building Energy Modeling Community
Get s tarted with the Help page
Ask Your Question
2

How to set up Visual Studio to use C# bindings

asked 2015-11-11 11:23:52 -0500

pflaumingo gravatar image

updated 2015-11-11 11:54:53 -0500

I'm using Visual Studio 2015 and OpenStudio 1.9.0, but can't seem to get any of the example c# files or my own to run. I've followed this answer setting my path correctly and build configuration for a 64-bit machine, but I keep getting a System.TypeInitializationException occuring in OpenStudio.dll. The exception is thrown at OpenStudio.OpenStudioUtilitiesCorePINVOKE and the inner exception states that it's unable to load openstudio_OpenStudioUtilitiesCore_csharp.dll. Any thoughts?

edit retag flag offensive close merge delete

Comments

@MarkAdams, I just saw this post here, is using Visual Studio 2015 an issue on OpenStudio 1.9.0 or 1.9.3?

pflaumingo gravatar image pflaumingo  ( 2015-11-11 11:25:30 -0500 )edit

@pflaumingo Visual Studio 2015 should be okay when using the C# bindings, but it does not work when compiling OpenStudio itself. I just tested with OpenStudio 1.9.0, Visual Studio 2015 Enterprise, and the code (and instructions) from here, and it all works. I don't know what to say other than follow my instructions in that other post and if that still fails to maybe post example code.

MarkAdams gravatar image MarkAdams  ( 2015-11-11 14:15:28 -0500 )edit

Hmm, very odd as I've just copied your sample code (and changed the path). I'll figure it out.

pflaumingo gravatar image pflaumingo  ( 2015-11-11 14:28:33 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-11-11 14:11:14 -0500

I believe you have to either copy all the dlls from your OpenStudio install into your build directory or add the path to the OpenStudio dlls to your path. The path to copy dlls from is:

C:\Program Files\OpenStudio 1.9.0\CSharp\openstudio

Depending on what features you try to use from OpenStudio you may also need to copy some Qt plugins or other file resources.

edit flag offensive delete link more

Comments

Yeh, I've added the path to my environment variables listed in the link I posted, but still no luck. Typing 'path' in the command prompt also shows it's in the path. I could probably add it to the build directory, but I was hoping to avoid this.

pflaumingo gravatar image pflaumingo  ( 2015-11-11 14:16:59 -0500 )edit

Did you include both C:\Program Files\OpenStudio 1.9.0\bin; and C:\Program Files\OpenStudio 1.9.0\CSharp\openstudio; in your path?

MarkAdams gravatar image MarkAdams  ( 2015-11-11 14:22:52 -0500 )edit

Check that you are building a 64 bit C# application if you are using the 64 bit OpenStudio dlls. After that, I have found Dependency Walker to be useful here, see this tutorial.

macumber gravatar image macumber  ( 2015-11-11 14:26:41 -0500 )edit

@MarkAdams, yup, I've checked a few times and I've got them both. @macumber, I've tried both 32-bit and 64-bit builds, but neither worked. Also, I used dumpbin on OpenStudio.dll and it looks like it is 32-bit even though my OpenStudio download is 64-bit. If my path is set up correctly as @MarkAdams shows I should just be able to type 'OpenStudio' in a command prompt and it should launch, right?

pflaumingo gravatar image pflaumingo  ( 2015-11-11 14:48:37 -0500 )edit

I ended up uninstalling and reinstalling and everything works fine now.

pflaumingo gravatar image pflaumingo  ( 2015-11-11 15:37:15 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

 

Question Tools

1 follower

Stats

Asked: 2015-11-11 11:23:52 -0500

Seen: 154 times

Last updated: Nov 11 '15