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

# Csharp for OpenStudio

I tried to start a project in visual studio to create different OpenStudio Models based on a database. Therefore I insert the .dlls from the Csharp Folder in the OpenStudio/bin. But this doesn´t work with OpenStudio 1.8.0/1.8.5/1.9.0. I always get an error Message, when I try to create a model or create a runmanager.

When I try to use OpenStudio 1.3.0, I don´t have any error Messages and I can create surfaces etc.. But when I safe the model, it doesn´t exist without sending an error Message. I can´t see if it works.

What could be the mistake of the programm? How can I get the dll work on visualstudio? What can I do, to make the DLL work in Visual Studio?

Now I change the settings of my project and add a reference to the OpenStudio/Csharp/openstudio Folder and the error Message is not shown. BUT when I try to make a simple model with only one construction and building and save this, nothing happens. There is no error message, but the osm. file doesn´t exist. I used this:

OpenStudio.Model model = new OpenStudio.Model();
....
model.save(new OpenStudio.Path(path),true);

edit retag close merge delete

Sort by » oldest newest most voted

Does this answer address your question on how to get the C# DLLs to work in Visual Studio?

UPDATE:

I tested creating a new Model then saving it and it works for me. Make sure you follow the instructions in the linked answer completely. Also, make sure the path variable in model.save(new OpenStudio.Path(path),true); is a valid path. I used "C:\\Users\\UserName\\Desktop\\test.osm" as the string I passed into OpenStudio.Path(). Note that I escaped the path separators and used a file name with osm extension.

more

Make sure you are not mixing architectures (32 bit vs 64 bit). If the version of Open Studio you got the DLL's from was 64 bit, then your C# program has to be 64 bit and vice versa. Don't use the Any CPU option.

I ran into a problem like this when moving to a new version of Open Studio since I inadvertently switched from 32 to 64 bit.

more

So this is the way I tried:

1. Install OpenStudio 64x
2. Create in the system path variablen: OpenStudio = "C:\Program Files\OpenStudio 1.9.0\bin" and OpenStudioCshapr = "C:\Program Files\OpenStudio 1.9.0\CSharp\openstudio"
3. Open the Csharp Example from Path = "C:\Program Files\OpenStudio 1.9.0\CSharp\examples\RunManagerExample"
4. Delete the Reference from OpenStudio
5. Add new Reference OpenStudio from path = "C:\Program Files\OpenStudio 1.9.0\CSharp\openstudio"
6. To be sure I copied all dll from "C:\Program Files\OpenStudio 1.9.0\CSharp\openstudio" to the project\bin
7. start Program
( 2015-10-27 05:20:39 -0500 )edit

it is solved. I had to install Qt and renew the .dll from the programm/bin path with the dll from Qt/plugins/platform

( 2015-10-27 06:56:52 -0500 )edit

Yeah, I try to get the c# DLL work in Visual Studio. There is an explanation in your answer, but it didn´t help. I get the following error Message:

It appears that there was an error accessing the C# SWIG Bindings for OpenStudio. Note that the libraries installed in <installdir>/CSharp/openstudio need to be accessible to this application at runtime, either through the path or in the same directory as the exe. Nothing else will work properly have this point. Error Text: It was tried to import a file in a wrong format. (Except HRESULT: 0x8007000B)

I also tried to copy all of the dll to the project/bin and renew the reference. But the same error occured. What can I do, to make the DLL work in Visual Studio?

more

1

( 2015-10-15 07:04:43 -0500 )edit