beloveds 0 Newbie Poster

Hi, everybody

First of all, i should say i am new at OpenGL programming and thanks to those who may help to solve my problem :)

The thing is, i was developing an application which is named Articulated Robot Arm (some of you guys may familiar with this). Everything was going perfect, but last night i have upgraded my OS from WinXP to Vista Ultimate 64-bit. I have opened my project to keep going but, i got the following exception in my code.

System.TypeInitializationException was unhandled
  Message="The type initializer for 'CsGL.OSLib' threw an exception."
  Source="csgl"
  TypeName="CsGL.OSLib"
  StackTrace:
       at CsGL.OSLib..ctor()
       at CsGL.OpenGL.OpenGL..ctor()
       at CsGL.OpenGL.OpenGL_Extension..ctor()
       at CsGL.OpenGL.GLU..ctor()
       at CsGL.OpenGL.GLUT..ctor()
       at CsGL.OpenGL.GL..ctor()
       at CsGL.OpenGL.OpenGLContext..ctor()
       at CsGL.OpenGL.ControlGLContext..ctor(Control c)
       at CsGL.OpenGL.OpenGLControl.CreateContext()
       at CsGL.OpenGL.OpenGLControl.get_Context()
       at CsGL.OpenGL.OpenGLControl.OnSizeChanged(EventArgs e)
       at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height, Int32 clientWidth, Int32 clientHeight)
       at System.Windows.Forms.Control.UpdateBounds(Int32 x, Int32 y, Int32 width, Int32 height)
       at System.Windows.Forms.Control.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)
       at System.Windows.Forms.Control.System.Windows.Forms.Layout.IArrangedElement.SetBounds(Rectangle bounds, BoundsSpecified specified)
       at System.Windows.Forms.Layout.DefaultLayout.xLayoutDockedControl(IArrangedElement element, Rectangle newElementBounds, Boolean measureOnly, Size& preferredSize, Rectangle& remainingBounds)
       at System.Windows.Forms.Layout.DefaultLayout.LayoutDockedControls(IArrangedElement container, Boolean measureOnly)
       at System.Windows.Forms.Layout.DefaultLayout.xLayout(IArrangedElement container, Boolean measureOnly, Size& preferredSize)
       at System.Windows.Forms.Layout.DefaultLayout.LayoutCore(IArrangedElement container, LayoutEventArgs args)
       at System.Windows.Forms.Layout.LayoutEngine.Layout(Object container, LayoutEventArgs layoutEventArgs)
       at System.Windows.Forms.Control.OnLayout(LayoutEventArgs levent)
       at System.Windows.Forms.Control.PerformLayout(LayoutEventArgs args)
       at System.Windows.Forms.Control.PerformLayout()
       at System.Windows.Forms.Control.ResumeLayout(Boolean performLayout)
       at System.Windows.Forms.Layout.DefaultLayout.SetDock(IArrangedElement element, DockStyle value)
       at System.Windows.Forms.Control.set_Dock(DockStyle value)
       at ArticulatedRobotArm.Form1..ctor() in F:\asd\Desktop\ArticulatedRobotArm\ArticulatedRobotArm\ArticulatedRobotArm\Form1.cs:line 19
       at ArticulatedRobotArm.Program.Main() in F:\asd\Desktop\ArticulatedRobotArm\ArticulatedRobotArm\ArticulatedRobotArm\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.BadImageFormatException
       Message="An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)"
       Source="csgl"
       StackTrace:
            at CsGL.OSLib.csgl_sys_initAssert(ASSERT a, ASSERT_THROW at)
            at CsGL.OSLib..cctor()
       InnerException:

The exception is generated in this section of my code:

public partial class Form1 : Form
    {
        MyView viewRef;
        public Form1()
        {
            InitializeComponent();
            viewRef = new MyView();
            this.viewRef.Parent = OpenGLPanel;
            [B]this.viewRef.Dock = DockStyle.Fill;[/B] // <- Here
            
        }

I really have no idea what the problem is.

Dani AI

Generated

Quick diagnosis for : a TypeInitializationException with an inner BadImageFormatException almost always points to a CPU-architecture mismatch between the running process and a native or mixed‑mode library used by CsGL. Moving from 32‑bit XP to 64‑bit Vista commonly exposes this: an AnyCPU build will run as 64‑bit on Vista x64 but a CsGL native component is still 32‑bit, so the CLR fails while initializing the CsGL static/native layer.

Practical fixes (fastest first):

  • Force the app to run 32‑bit: set the Visual Studio project Build -> Platform target to x86 and rebuild. This is the simplest way to load 32‑bit native DLLs without changing libraries.
  • If a 64‑bit process is required, obtain or compile 64‑bit versions of the CsGL native/mixed assemblies and deploy those alongside the executable.

Verification and troubleshooting steps:

  • Confirm the bitness of the native DLLs (csgl or similar) with Dependency Walker (depends.exe) or dumpbin /headers and check the Machine field (x86 vs x64).
  • Use corflags on managed assemblies to inspect preference flags.
  • Ensure the native DLLs live in the application output folder; missing or wrong‑bit native binaries cause load-time failures.
  • Note that the OpenGL control creates its context during control creation/layout, so the crash will appear when the view is docked or the form lays out.

Additional notes: if matching architectures still fails, verify Vista x64 GPU drivers provide OpenGL support and consider switching to a maintained managed wrapper that provides explicit x64 binaries if CsGL lacks them.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.