Link to home
Start Free TrialLog in
Avatar of charlieb01

asked on framework versions

I have a DLL and VB.NET source code from NIST called REFPROP that work under .NET Framework 3.5. At the same time, I have an application I need to build that uses third party controls from National Instruments that only work under .NET Framework 4.0.
The main application (framework 4.0) contains all of the UI and other functions I need with the exception of calls to the NIST REFPROP to get refrigerant properties.
I am trying to find a way to use the main program (using framework 4.0) to call a second program (the NIST REFPROP using framework 3.5) to get the answers I need.
Typically, you pass a temperature and pressure and refrigerant type to the RefProp routine with a function call for the answer you want and the function result provides the answer.

I am at a loss as to what to do here. Any suggestions?

Avatar of Miguel Oz
Miguel Oz
Flag of Australia image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of charlieb01


I set the program to Framework 4 and when it reaches this line:

Call SETUPdll(nc2, hfld, hfmix, hrf, ierr, herr, 10000, 255, 3, 255)

I get an error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

However, if I change the program to Framework 3.5, re-launch it and run it again, not only do I not get any errors, it gives me the correct answer.

Any ideas?

Could you send the method declaration of SETUPdll? I need to see what kind of classes/primitive types or heaven forbids COM/Unmanaged code.
It seems that you are dealing with COM/Unmanaged code. A typical .NET assembly will not raise such an error. also you need to check whether your build is 32 bits (x86) or 64 bits.
You may have some differences especially if you are dealing with unmanaged code. One quick fix could be to create a facade class that is contained in a .NET 3.5  assembly. This class will encapsulate any interaction and calls to any .NET 3.5 code so that your program only interacts with this class only, not your third party DLL.
I don't have access to the source code of the third party DLL.
If I understand what you are suggesting, I should take the vb.NET module that works under NET 3.5 and create a DLL from that. Then my NET 4 4 program would call the new DLL I make and that in turn calls the functions in the third part DLL.

Do I understand this correctly?
Perfect. Just make sure you have the same build properties as per .NET 3.5 project
I have not done this in a long time (and not that many times at that) can you assist me with creating the new DLL from the module?
I think I need to launch a new instance of and "New Project" and select "Class Library". (being sure that it is Framework 3.5)

Then, in the code window I would copy the entire contents of the existing module (with the exception of "Module General" and "End Module" and then save the new Class project in its own folder.

I would then start a new program (windows Form) and to that I would need to add the Class Library reference by browsing for it.

Do I have this right so far?
Yes, that is correct just make sure that the "class" declaration has no unmanaged code dependencies.
For example declaring pointers as parameters in a method.
Also check if there is any start-up and closing methods that setups your library usage and surface them as shared methods(static in C#) in case the third party library requires a special initialization and resource clean-up respectively.
Other than that it should work as advertised.
Can you create the 3.5 app As a DLL file, and just reference it inside the 4.0 Program or vica versa?
That is what I am going to attempt to do. So I will have a 4.0 program that makes calls to a 3.5 DLL that makes calls to a DLL probably created by some Fortran code. (I have no idea what NIST is using today) It would be a lot easier if I had the source code for the DLL from NIST
Whats this for, NASA?

Maybe this example will help you make calls to the dll

Best mode of action is just add the dll to your resources, and send calls to it.
The problem is, the NIST REFPROP dll will not work wih a Net 4.0 Framework program
then make a 3.5 dll with it, call all functions,  return the returns,  then add that dll to your 4.0