Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29304 Discussions

Additional information: Could not load type 'FortMod' from assembly 'FortMod, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because the method 'PROGRESS' has no implementation (no RVA).

mch7918
Beginner
2,470 Views
hi,

I have two function calls from my C# code to Fortran (DoSomething() and PROGRESS()). I can call the function DoSomething() with no issues, but when i tried to add another function call (i.e PROGRESS()), i get the following error message.

An unhandled exception of type 'System.TypeLoadException' occurred in Microsoft.VisualStudio.HostingProcess.Utilities.dll

Additional information: Could not load type 'FortMod' from assembly 'FortMod, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' because the method 'PROGRESS' has no implementation (no RVA).


c# code to call the methods

public static extern void DoSomething();

public static extern void PROGRESS(ref int PERCENT_COMPLETE, ref int CURRENT_STATUS);

private void ListenMainThread()
{
int PERCENT_COMPLETE = 0, CURRENT_STATUS = 0;
while (Cond)
{
PROGRESS(ref PERCENT_COMPLETE, ref CURRENT_STATUS);

}
}

Fortran Code:

SUBROUTINE PROGRESS(PERCENT_COMPLETE,CURRENT_STATUS)

!MS$ATTRIBUTES DLLEXPORT, ALIAS:'PROGRESS' :: PROGRESS

USE PROGRESS_DECLARATIONS

IMPLICIT NONE

INTEGER :: CURRENT_STATUS
INTEGER :: PERCENT_COMPLETE

CURRENT_STATUS=FLOAT(IPROGRESS(1))
PERCENT_COMPLETE=FLOAT(IPROGRESS(2))

RETURN
END

Please let me know if i am missing anything while adding another function call to my C# code.

Thank you!

-Chouhan

0 Kudos
9 Replies
bmchenry
New Contributor II
2,470 Views
You declare current_status and percent_complete as INTEGER
You then set them with the FLOAT() command
0 Kudos
mch7918
Beginner
2,470 Views
This problem pops up whenhever i add a new Routine in Fortran project and try to call from my c# code.

This is the new Fortran Subroutine i added ..

SUBROUTINE RoutineTest(var1)
!MS$ATTRIBUTES DLLEXPORT,ALIAS:'RoutineTest' :: RoutineTest

IMPLICIT NONE
INTEGER :: var1
var1=var1+1
RETURN
END

Whenhever i try to declare this function my c# code(as shown below), the problem popsup..

public static extern void RoutineTest(ref int var1);



0 Kudos
Steven_L_Intel1
Employee
2,470 Views
I thought you had to use DllImport and "MarshallAs" to call unmanaged code from C#.
0 Kudos
mch7918
Beginner
2,470 Views
Hi Steve,

I already have dllimport in my code and i am able to access a Fortran Routine method from my code. But when i tried to call another routine which is part of the same Fortran solution the problem occurs.

[DllImport(Fort.dll", CallingConvention = CallingConvention.Cdecl)]

i dont know about MarshallAs.

-Chouhan

0 Kudos
Steven_L_Intel1
Employee
2,470 Views
I believe you need the "MarshallAs" to get the arguments passed correctly. I have attached a sample I have.
0 Kudos
mch7918
Beginner
2,470 Views
I tried to run your solution. I get following error at the function call.

An unhandled exception of type 'System.BadImageFormatException' occurred in CsharpCallsFortran.exe

Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)


I can see that the subroutine accepts 6 arguments, where as we are trying to pass 8 argument.

In my case i have character array in the call, which unmanagedType shuould i use to MarshallAs.
MarshalAs(UnmanagedType.?) for char array..

thank u!
0 Kudos
Steven_L_Intel1
Employee
2,470 Views
If youy are on a 64-bit system you must build the DLL as 64-bits (and I think specify x64 as the target architecture for the C# project. I haven't looked at this project in a while but I had to do that with the VB.NET samples.
0 Kudos
mch7918
Beginner
2,470 Views
I have bulid the solution as 64-bit. It runs perfectly now.

Now i tried to implement MarshallAs in my solution. It gives me following error.

An unhandled exception of type 'System.AccessViolationException' occurred in FortranTest1.exe

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.


Even i tried to create a new solution (a simple fortran application) it gives me the same error.

pls help.
0 Kudos
mch7918
Beginner
2,470 Views
Tha Answer to the root problem is,

We should have dllimport statement for each method that we are trying to import from Fortran DLL.

ie.) [DllImport("Dll")
public static extern void SubRout1();

[DllImport("Dll")
public static extern void SubRout2();
0 Kudos
Reply