1
votes

I'm currently trying to consume a FORTRAN DLL that I have been given by a third party. Now, it has been consumed before by other vendors (unsure whether they used C# or not to consume it), but I'm getting some reference errors when I'm trying to consume it.

I'm basically trying to get it to work within a small test app.

Here's the C# code I'm using to import (basic COM really):

[DllImport("foo.dll")]
public static extern void foo(ref int IS, ref double[] BETA, ref int K, out double TH, out double SETH, out int IER);

static void Main(string[] args)
{
    double[] betas = new double[3];
    betas[0] = 25.6;
    betas[1] = 30.8;
    betas[2] = 35.8;

    int score = 5;
    int numberOfItems = 3;
    double latentVariable;
    double standardErrorOfEstimate;
    int errorCode;

    foo(ref score, ref betas, ref numberOfItems, out latentVariable, out standardErrorOfEstimate, out errorCode);

        Console.ReadLine();
}

Note: The DLL method signature matches that what I have.

When trying to run the application, I get the following Exception:

Unable to load DLL 'foo.dll': The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail. (Exception from HRESULT: 0x800736B1)

Looking in the event log, the following details is shown on the error:

Activation context generation failed for "C:\dllpath\foo.dll". Dependent Assembly Microsoft.VC90.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" could not be found. Please use sxstrace.exe for detailed diagnosis.

Also, running sxstrace, the same information and error is shown:

ERROR: Cannot resolve reference Microsoft.VC90.DebugCRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8". ERROR: Activation Context generation failed. End Activation Context Generation.

Now, after doing some googling and looking round on here, some people recommend installing the Redistributable packages for C++. I've done that for both 2008 and 2010 on both x86 and x64 platforms and still no joy.

Anyone got any ideas? I'm using Visual Studio 2010 and Windows 7 (if that helps?).

1
A small correction DllImport is pinvoke and not Com interop. msdn.microsoft.com/en-us/library/ms173185.aspxAmit Mittal
@AmitMittal updated tags & title, thank you :)mattytommo
Do not add the ref keyword for arrays. They already are references. Only add the ref keyword to primitive values.John Alexiou
Can you post the FORTRAN function declaration with arguments and types please.John Alexiou

1 Answers

1
votes

The problem is DebugCRT. You've got the debug build of that DLL and it has a dependency on the debug build of the CRT. Which requires an appropriate version of Visual Studio, the only way to get the debug build of the CRT on your machine. Which is Visual Studio 2008, indicated by the 9.0 version number. You have no use for the debug build if you don't also have the source code for this DLL. Nor can you get this DLL deployed and working on your customer's machine.

Get ahead by contacting the owner and asking for the release build so that the redistributable packages can work.