Avatar of charlieb01
 asked on

vb.net 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?

.NET ProgrammingVisual Basic.NET

Avatar of undefined
Last Comment
Ess Kay

8/22/2022 - Mon
Miguel Oz

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

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?

Miguel Oz

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?
Your help has saved me hundreds of hours of internet surfing.
Miguel Oz

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 VB.net 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?
Miguel Oz

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.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Ess Kay

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
Ess Kay

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.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

The problem is, the NIST REFPROP dll will not work wih a Net 4.0 Framework program
Ess Kay

then make a 3.5 dll with it, call all functions,  return the returns,  then add that dll to your 4.0