I am writing a Fortran function that needs to receive two vectors of reals, and as an output, returns a vector. The function could be for example the sum of the two vectors:

```
function sumtwovectors( n, v1, v2 )
implicit none
real(kind=8), dimension(100000) :: sumtwovectors
integer, intent(in) :: n
real(kind=8), dimension(100000), intent(in) :: v1, v2
integer :: i
if (n .gt. 100000) then
sumtwovectors(:) = -99
return
endif
do i = 1, n
sumtwovectors(i) = v1(i) + v2(i)
enddo
return
end function sumtwovectors
```

which is then compiled without error into a dll with

```
gfortran -c sumtwovectors.f90 -o sumtwovectors.o
gfortran -shared -mrtd -o test.dll sumtwovectors.o
```

This dll should be NET-compatible, so I load it into Mathematica ( `path`

contains the path where the dll is stored):

```
InstallNET();
sumtwovectors = DefineDLLFunction("sumtovectors_", path, "double()", {"short*", "double()", "double()"})
```

but when I run this, I have an error:

```
sumtwovectors(3, {1, 3, 2}, {3, 4, 5})
NET::netexcptn: A .NET exception occurred: System.Runtime.InteropServices.MarshalDirectiveException: Impossible de marshaler 'return value' : Combinaison de types managés/non managés non valide.
à Wolfram.NETLink.DynamicDLLNamespace.DLLWrapper1.sumtovectors_(Int16& , Double() , Double() ).
```

- How can I make this work in Mathematica? I tried enclosing the two list into MakeNETObject() but to no avail.
- Instead of having a maximum size (1000000), could it work with no defined maximum size?