.NET - Visual Studio 2008 (C#)

The engine.
Post Reply
jeffs
Posts: 7
Joined: Tue Mar 10, 2009 3:22 pm

.NET - Visual Studio 2008 (C#)

Post by jeffs »

When trying to create a .NET (C#) application, I ran into trouble from the first line of code.
It makes me ask whether anyone has tried this with VisualStudio 2008 and the .NET 3.5 SP1 framework.

A very simple app - I added a button to mainform.
Inside the event handler:

Network = new Smile.Network();

The application terminates immediately with this error:

BadImageFormatException was unhandled
is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)


The output window shows:

'BayesSmile.vshost.exe' (Managed): Loaded 'C:\Development\Playground\C#\BayesSmile\BayesSmile\bin\Debug\BayesSmile.exe', Symbols loaded.
A first chance exception of type 'System.BadImageFormatException' occurred in System.Windows.Forms.dll
'BayesSmile.vshost.exe' (Managed): Loaded 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.

Has anyone used the .NET wrapper for Smile with C#?
If so, what about with VS 2008 and .NET Framework 3.5 SP1?
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Re: .NET - Visual Studio 2008 (C#)

Post by shooltz[BayesFusion] »

Has anyone used the .NET wrapper for Smile with C#?
Yes, we test SmileNet with C#.
If so, what about with VS 2008 and .NET Framework 3.5 SP1?
I've just made simple Winforms app with VS 2008 and .NET 3.5 (no SP1, however), it works just fine. Note that your exception occurs in System.Windows.Forms.dll - maybe some of your binaries are corrupt.

Code: Select all

A first chance exception of type 'System.BadImageFormatException' occurred in System.Windows.Forms.dll
You may try to remove the call to SmileNet to check if problem persists.
jeffs
Posts: 7
Joined: Tue Mar 10, 2009 3:22 pm

Post by jeffs »

If I comment out the single line that creates a Smile.Network object, then the app runs just fine (there's almost nothing in it).

So I'm thinking that the .dll file is corrupt. The dll was contained inside a zip file downloaded 2 days ago from the Genie website., which I downloaded inside a zip file.

What version of the .NET framework and VisualStudio did you try this with? I am building on Vista64, VS2008 SP1. and .NET 3.5. I did try with .NET 2.0 and .NET 3.0 with similar results.

Thanks for any help you can provide.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

jeffs wrote:What version of the .NET framework and VisualStudio did you try this with? I am building on Vista64, VS2008 SP1. and .NET 3.5.
I've tested with VS2008 SP1 with .NET 2.0 and 3.5 on Vista 32-bit, using the Smile.NET binaries available at our website. Smilenet.dll file size should be 1,265,664 bytes.
jeffs
Posts: 7
Joined: Tue Mar 10, 2009 3:22 pm

Post by jeffs »

I have the same .dll size.

And the object browser and intellisense all work to show the various classes and methods within the Smile.NET assembly.

I'm at a loss as to what might be causing the crash.
Last edited by jeffs on Wed Mar 11, 2009 10:12 pm, edited 1 time in total.
shooltz[BayesFusion]
Site Admin
Posts: 1417
Joined: Mon Nov 26, 2007 5:51 pm

Post by shooltz[BayesFusion] »

jeffs wrote:I'm at a loss as to what might be causing the crash.
I'm also running out of ideas. Can you search for all occurences of smilenet.dll on your harddrive, delete them and re-download the file?
jeffs
Posts: 7
Joined: Tue Mar 10, 2009 3:22 pm

Post by jeffs »

This should have been obvious to me earlier.

I'm building a .NET app on Vist 64, which I think will build a true 64 bit application (regardless of the .NET language).

The smilenet.dll is a 32 bit compiled DLL, and the application dies when it tries to load the library.

I tried the same C# application build on XP 32 just now and it works fine.

So, do you have a 64 bit .dll available for SmileNET? I tried to build the project from source but got extensive warnings about unmanaged directives no longer supported and a few errors.

With Windows7 on the way I think you'll be seeing a lot more 64 bit usage with .NET.
jeffs
Posts: 7
Joined: Tue Mar 10, 2009 3:22 pm

Post by jeffs »

This is now resolved. Here is what I learned:

For Vista/64 bit platforms:

If you want to build a .NET application (for example in C#) you must explicitly configure the build for the x86 platform. If you choose "Any CPU" on a 64 bit platform, then you get a 64 bit application trying to load a 32 bit .dll, the Smile.NET assembly.

(These instructions are relevant to Visual Studio 2008)

To configure you build, from the menu:

Build->Configuration Manager.

Click on the dropdown labeled "Active Solution Platform"
Click <New..>
Specify the x86 platform.

Of course, you also need to add reference to the smilenet.dll file in your project:

Project->Add Reference...
Click the "Browse" tab
Find your .dll file and click OK.
Post Reply