-
Notifications
You must be signed in to change notification settings - Fork 129
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
Trying to implement the REFPRP64.DLL in C# API #637
Comments
You need to make sure that all string buffers are at minimum the lengths specified in https://refprop-docs.readthedocs.io/en/latest/DLL/high_level.html#f/_/REFPROPdll |
Thank you for your quick response, Ian. I am not entirely sure of your meaning. Could you please provide a brief example? |
Yes, all string buffers must be at minimum the length indicated in the docs |
For instance this string is way too short:
|
Thank you again Ian.
Based on the specifications in the documentation as pasted above, I've made some changes to the above code and have the following:
Still crashing and getting: Exception thrown: 'System.AccessViolationException' in CIPHRAPI.dll What am I missing here? |
Lengths are still wrong. See the docs: hFld_length [int ] :: length of variable hFld (default: 10000) There are user-contributed wrappers for C# you should use: https://github.com/usnistgov/REFPROP-wrappers/tree/master/wrappers/Csharp |
Hello Ian, Thanks again for your quick response. I have modified my initial code to reflect the information you have given me and it is still crashing with the System.AccessViolationException. I do have the C# example in the wrappers documentation and tried to implement it in my code. However, I did notice that the example uses the legacy dll which requires calling SETUPdll. As far as I understand, these legacy methods are deprecated and should not be used. So, I have a few questions:
My modified code is below. Please point out what I am missing so I may correct it. Thank you!
|
You are also not passing the right string length variables. Please see the examples in the Python wrapper: https://github.com/usnistgov/REFPROP-wrappers/blob/master/wrappers/python/ctypes/ctREFPROP/ctREFPROP.py |
Hello Ian, Are you specifically speaking about hFld_length, hIn_length, hOut_length and hUnits_length? Also, could you please address my three questions above? I believe that question number 2 might be related somewhat to those 4 fields. I apologize for my many inquiries. It is difficult for me to decipher single sentence answers and Python code. The documentation, though extensive, is not very clear in terms of what is a required parameter and which is not. I am not asking you to write my code for me, I am asking specific questions whose answers will allow me to understand the documentation better and write my own code for the high-level API methods which do not have wrapper and implementation examples. Thank you, Michael Villegas |
Hi, I am afraid I have zero knowledge of C#, but if you have not done so already, please take a look at the C# wrapper that another user has kindly posted here https://github.com/usnistgov/REFPROP-wrappers/tree/master/wrappers/Csharp If you continue to have problems perhaps contact the author of the wrapper. |
Hello Marcia, The author of the wrapper is not available to contact from GIT hub. Is there anyone you can point me to who has knowledge of the high-level API dell (REFPRP64.DLL) and its implementation requirements to consume it through a C# API? We purchased the license for this DLL and are unable to find anyone who can provide proper support. Thank you very much, Michael Villegas |
Michael,
The author did leave an email contact on the page, perhaps try Warren Newhauser ***@***.******@***.***>)
The most knowledgeable person about C# interfacing probably is Ian.
If you are unable to use the product due to interfacing difficulties, please send an email to ***@***.******@***.***> explaining your problem and ask for a refund.
I am sorry if we are unable to help you.
Marcia
From: mikevill1968 ***@***.***>
Sent: Monday, January 13, 2025 2:25 PM
To: usnistgov/REFPROP-wrappers ***@***.***>
Cc: Huber, Marcia L. Dr. (Fed) ***@***.***>; Comment ***@***.***>
Subject: Re: [usnistgov/REFPROP-wrappers] Trying to implement the REFPRP64.DLL in C# API (Issue #637)
Hello Marcia,
The author of the wrapper is not available to contact from GIT hub.
Is there anyone you can point me to who has knowledge of the high-level API dell (REFPRP64.DLL) and its implementation requirements to consume it through a C# API?
We purchased the license for this DLL and are unable to find anyone who can provide proper support.
Thank you very much,
Michael Villegas
-
Reply to this email directly, view it on GitHub<#637 (comment)>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AJUJT2NFQTZ7NJL6YYPQNCL2KQVKVAVCNFSM6AAAAABU4WH4UKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDKOBYGI2DQMJQGY>.
You are receiving this because you commented.Message ID: ***@***.******@***.***>>
|
To answer your three questions, a little bit of explanation of how REFPROP works may be helpful. REFPROP is written in a language called FORTRAN 77. This low-level language does not allow for dynamic memory allocation, meaning that all inputs in and out of the program must be completely defined, and with fully fixed lengths, as new and recent language features like overloading do not exist. Furthermore, because you're working with low level DLL interactions that leaves the safe C# memory managed bubble, your routines need to call the exact hooks that exist on the DLL, and this mean they need the precise number of arguments as well as array sizes. So to answer your questions:
Feel free to direct your further questions towards me. Sorry for the personal Github account. |
Thank you so much for your reply Tyler. this makes things much clearer. In my latest code to call the REPROPdll method I have the following call:
The input parameter values along with explanations of each are the following hfld = "NITROGEN|METHANE|CO2|ETHANE|PROPANE|ISOBUTAN|BUTANE|IPENTANE|PENTANE|HEXANE" (with blank spaces at the end that add up to 10000 characters) hIn = "TP" (with blank spaces at the end that add up to 255 characters) hOut = "D" (with blank spaces at the ed that add up to 255 characters) iUnits = 3 (SI with Celcius) iMass = 0 (Molecular) iFlag = 0 (since I am not looking for saturation and don't require SATSPLN to be called) a = 26.9 (temperature in Celcius) b = 6.89476 (pressure in kPa) z = an array of type double and size 20 whose values for the first components in the order of hFld add up to 1) hfldLen = 10000 hInLen = 255 hOutLen = 255 hUnits_length = 255 herrLen = 255 As far as I can surmise, this should run, based on what I see in the documentation for the method but it still crashes and returns the System.AccessViolationException Is something missing or off in those input values? |
Hi Michael, I'm recreating your code and conducting a few experiments, expect to hear back from me later today. |
Hello again Tyler, The good news is that it is no longer crashing when calling REFPROPdll. The bad news is that it returning an error "Length cannot be less than zero.\r\nParameter name: length". which appears to happen in VBByValStrMarshaller.cs (which I can see in decompiled code) [SecurityCritical] I am adding my recent code below in full so you can see my explanations better: I know I am VERY CLOSE to getting this to work. :-)
|
Hello again Tyler. I figured it out!!! My issue was not with my controller call. It was with my wrapper. Your information on Fortran made me go back to 1989 in college and realize that I am dealing with unmanaged type arrays. I was already marshalling the string arrays but not the double type arrays. Adding the InteropServices.MarshalAs method to those arrays and passing them by value instead of by reference fixed the problem and now the REFPROPdll method is returning values without crashing or erroring out. Thank you SO very much for your help!!! My wrapper code below:
|
Happy to be of assistance. I normally don't interact with NIST's customers (hence the personal github, getting that fixed), but you can also direct any further REFPROP and C# questions to me. |
I'm going to leave this issue open while I update our C# wrapper example to use the new API. |
Thank you again Tyler |
Hello,
REFPROP version: REFPRP64.dll (no version appears in the properties but it has a timestamp of 06/04/2018 22:24:01)
Operating System: Microsoft Windows 11 Enterprise, Version: 10.0.22631 Build 22631
Access Method: C# wrapper built in-house (code provided below)
I am building a C# .NET API to create endpoints that will access the REFPRP64 high-methods and make then consumable by web applications throughout the company. I have build a C# wrapper and referenced the wrapper in my API. The code for the wrapper is as follows:
The text was updated successfully, but these errors were encountered: