BadImageFormatException was unhandled

May 15, 2012 at 1:13 PM

I am using VS 2010 on x64; set path to both i86 and x64 bit dll's without luck.

Trying to run basic demos; could anyone suggest what could correct the situation?

May 21, 2012 at 6:27 PM

I'm having the exact same problem and nothing can fix it!

My project is x86 and the environment variable R_HOME points to "C:\Progs\R\R-2.15.0\bin\i386" (but i've tried other stuff too)

the Registry value InstallPath points to "C:\Progs\R\R-2.15.0"

and it will just not work!!!

I have Genuine Windows 7 x64 with R version 2.15.0 (my project is indeed x86 though, but i've tried it in x64 too, nothing happened)

so frustrating!

May 21, 2012 at 6:38 PM
Hello N1h1l1sT and daspranab,
I have a guess as to what your issue might be. By default, Visual Studio compiles all .NET projects with the target platform set to "Any CPU". This means that when you run on a X64 system, the 64-bit version of the libraries are used. (If on a 32-bit system, 32-bit versions used).
It is not possible to have both 64-bit and 32-bit DLL's in the same application. If this happens you will get a BadImageFormatException
I set my .NET app to compile to x86 and I only reference the i386 version of the R DLL.
The binary distributions of R.NET are targeted to a specific CPU type. Make sure your .NET project targets the same CPU.
Best Regards,

Rob
May 21, 2012 at 6:44 PM

i've already done this bro.. doesn't work :(

 

is r.net working for you? if so, PLEASE check your system and tell me EXACTLY what you see on those places (use the numbers i use so i can understand which corresponds to what):

 

1) The system Variable "R_HOME" (Control Panel -> System -> Advances System Settings -> Advanced -> (last option) Environment Variables)

Also, is it a user variable or a system variable

2) The Registry variable "InstallPath" on HKEY_LOCAL_MACHINE\Software\R-core\R\

3) Any other variable you think that might be connected with R.NET 

 

Thank you very much in advance. making this work will mean so much to me! 

May 21, 2012 at 6:58 PM
Hi,
I am still having some issues with R.NET, but the example works.
I am using R version 2.15.0. Nothing special, just the default install.
I do not have any environment variables that I added or modified, but the set code below.
I use a slightly different startup sequence. Target CPU = x86. Target framework = 4.0
Are you set to use the 4.0 .NET Framework?
public partial class Form1 : Form
{
private static String R_Home = @"C:\Program Files\R\R-2.15.0";
private static String Rbin_Home = @"C:\Program Files\R\R-2.15.0\bin\i386";
private void Form1_Load(object sender, EventArgs e)
{
String pathEnv = System.Environment.GetEnvironmentVariable("PATH");
pathEnv = Rbin_Home + ";" + pathEnv;
System.Environment.SetEnvironmentVariable("PATH", pathEnv);
System.Environment.SetEnvironmentVariable("R_HOME", R_Home);
REngine.SetDllDirectory(Rbin_Home);
REngine.CreateInstance("RDotNet");
using (REngine currentEngine = REngine.GetInstanceFromID("RDotNet"))
{
...
May 21, 2012 at 7:08 PM

Yes, i use .NET Framework 4.0

i have R 2.15.0

 

the newest R.NET version says it needs an environment variable to point to R.

 

I am wondering, could i tell u my teamviewer ID and PASS so u can log in to my computer for just 5 minutes

just to check out with your own eyes if i've missed something.

May 21, 2012 at 7:18 PM
Hi,

Have you tried using the .NET utility FUSLOGVW? It may shed some light on what dll is causing the error.
I am not able to remote into your system; that violates my company's policy.

Another idea is to download the source for R.NET, include in your solution and max out the exception traps for debugging.


> From: N1h1l1sT
> Yes, i use .NET Framework 4.0
> i have R 2.15.0
>
> the newest R.NET version says it needs an environment variable to point to R.
>
> I am wondering, could i tell u my teamviewer ID and PASS so u can log in to my computer for just 5 minutes
> just to check out with your own eyes if i've missed something.
May 21, 2012 at 7:26 PM

I didnt even know something like that existed. i googled it and went here: http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.100).aspx

i run it, then run the program. the program told me the same thing but nothing appeared on the FUSLOGVW. so i cant push the "View Log" button.

 

Btw it's too bad u cant connect to my pc.

At this point, i'd do anything to make it work... i need to make a program for a paper i'll be writing and i'm sooo behind :(

May 21, 2012 at 7:40 PM

To run FUSLOGVW on win7 you need to "Run As Administrator". Then go to setting to start the capture. Run program until it errors, then return to FUSLOGVW.

From: N1h1l1sT [email removed]
Sent: Monday, May 21, 2012 11:26 AM
To: MCALLISTER,ROB (A-Spokane,ex1)
Subject: Re: BadImageFormatException was unhandled [rdotnet:355831]

From: N1h1l1sT

I didnt even know something like that existed. i googled it and went here: http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.100).aspx

i run it, then run the program. the program told me the same thing but nothing appeared on the FUSLOGVW. so i cant push the "View Log" button.

Btw it's too bad u cant connect to my pc.

At this point, i'd do anything to make it work... i need to make a program for a paper i'll be writing and i'm sooo behind :(