Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using SharpFluids in a .Net 4.6.1 Class Library, getting 'Coolprop.dll not found' error after rebuilds #36

Open
Sean-Hasse opened this issue May 19, 2022 · 5 comments

Comments

@Sean-Hasse
Copy link

I've been getting an inconsistent issue with SharpFluids since changing a project to a library to add to another, larger project. The first time my project tries to create a fluid with 'Fluid f = new Fluid(FluidList.Water);' I get an exception. It appears that the code is not finding the CoolProp.dll when it tries to convert the FluidList object to a Fluid object. I've confirmed that the CoolProp.dll is present in the Debug folder, and that I'm properly calling 'using SharpFluids;' at the start and all.

Mystifyingly, the workaround I've found so far is to comment out that first 'Fluid f =' line, let my code run, and after it crashes because Fluid f is a null reference object, I un-comment out that code and it runs perfectly fine.

I suspect it's either an issue with the loading order for my project, or maybe it's an issue with the .Net framework I'm using. Any insights at all would be appreciated.

Additional Information:
SharpFluids being used is version 3.0.270 but has been observed on multiple versions
The full error is this: System.TypeInitializationException: The type initializer for 'CoolPropPINVOKE' threw an exception. ---> System.TypeInitializationException: The type initializer for 'SWIGExceptionHelper' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'CoolProp': The specified module could not be found. (Exception from HRESULT: 0x8007007E)

@MadsKirkFoged
Copy link
Owner

I somethings get the error myself when starting up a new project. I believe it is because the Nuget have to copy over the "Coolprop.dll" and sometimes it just doesn't do it. I can just press "Rebuild" and it then copies the dll correctly.

What you are talking about it using SharpFluids inside a library that you then use elsewhere.
I have done exactly that and as I remember I got the same issue.
The issue is that the nuget package can't copy the dlls when you get down another level.
So the issue is to with copying files in nesting nugets packages and not really SharpFluids

Fix:
I have put CoolProp.dll and CoolProp64.dll directly into the library and marked them Copy if newer

@Sean-Hasse
Copy link
Author

Thank you very much for this help! One question: I did manage to find and set the packages properties to 'Copy if newer', but I'm not sure what level in the files you'd move CoolProp.dll and CoolProp64.dll to.

I copied and pasted both .dll files to my library's Project folder (so, on the same level as the other .cs files), and set both to Copy if newer, but upon Cleaning and Building, I'm running into the same error.

@Sean-Hasse
Copy link
Author

Unfortunately, despite looking online for answers regarding this bug, I haven't found anything yet. What you described seems very likely the source of this glitch, rather than something to do with SharpFluids in particular, but I haven't been able to implement the solution that you suggested.

@MadsKirkFoged
Copy link
Owner

MadsKirkFoged commented May 25, 2022

  1. Can you try to update to maybe net47 or newer? Just to rule that out
  2. After you have build your program can you find the dll files in the folder ..bin\Debug\

@Sean-Hasse
Copy link
Author

  1. Switching to .Net 4.7+ might be possible, but it would require enough restructuring of the code that I am hesitant to try that unless it is necessary.

  2. I can confirm that both CoolProp.dll and CoolProp64.dll are in the ..bin\Debug\ folder after building the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants