Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

The type initializer for 'CsGL.OSLib' ...

2009-09-27
2013-07-21
  • Hi.

    I'm really new to OpenGL. I was programming on a x86 computer and my applications run fine, but recently i moved to a x64 machine, and it throws the following exception: "The type initializer for 'CsGL.OSLib' threw an exception." Has anyone any idea what is the cause of that exception?

    Here is the part of code where the exception is thrown:

        protected override void OnSizeChanged(EventArgs e)
            {
                base.OnSizeChanged(e);
                Size s = Size;

                GL.glMatrixMode(GL.GL_PROJECTION);
                GL.glLoadIdentity();
                GL.gluPerspective(45.0f, (double)s.Width / (double)s.Height, 0.1f, 100.0f);
                GL.glMatrixMode(GL.GL_MODELVIEW);
                GL.glLoadIdentity();
            }

    It is thown on the first line: base.OnSizeChanged…

     
  • I also encounter his error. please help us deal with it.thks

     
  • Jason Foley
    Jason Foley
    2010-03-17

    I'm getting this too.  I'm running C# 2008 Express and tried a 32-bit build with no effect.  The OS I'm stuck with is Vista Home Premium 64bit.  This is probably an OS-specific or platform issue.  The CsGL .Net assembly can't find the native .dll file.  I can't reference the native .dll since it's not an assembly.  Is there another way to link from the IDE?  Usually it looks in the current directory.  Copying didn't work either.

    One example is NeHe lesson08.  The C# program compiles fine and runs with the unhandled exception on the OnSizeChanged event (initial window setup).  At least this is a starting point.

    Message:
    "Unable to load DLL 'csgl.native.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)"

    Stack trace:
       at CsGL.OSLib.csgl_sys_initAssert(ASSERT a, ASSERT_THROW at)
       at CsGL.OSLib..cctor()

    The failed assert is line 46 of OSLib.cs in the latest version of the CsGL source.
    It's also referenced in csgl_sys.h on line 39.

    Are there any special hoops to jump through for this to work on a Vista x64 machine?
    I've compiled and run every example on a XP 32-bit before.

     
  • dw
    dw
    2011-10-04

    I also got this problem.  If found that the problem is in how the author of the tutorial setup his folder structure.  The reference to csgl.dll is in the "debug" folder.

    I'm running XP using VS 2005 (old I know, but I'm limited to older versions because of company resources)
    I solve the problem, by going to this thread http://edndoc.esri.com/arcobjects/9.2/NET/0b0cb380-490e-4c8e-829d-d8083967387b.htm
    1) Download the csgl files.
    2) Run the script in the "libinstall" folder (the script copies the two libraries to the System32 folder)
    3) Then go to the VS Solution Explorer, expand the "References" folder, right click on the "csgl" reference and remove it.
    4) Right click on the "References" folder, go to "Add Reference…" and navigate to the "csgl.dll" file located in the "System32" folder.

    If you're using Vista, or WIndows 7 or a 64-bit machine, use folder equivalent to "System 32" for an XP machine.

    Hope that helps

     
  • samuel
    samuel
    2011-12-15

    I got the run-time error "The type initializer for 'CsGL.OSLib' threw an exception" when doing a build/run from MS Visual Studio 2010 and also from MS Visual Studio C# Express. I am using 64 bit Windows 7. Visual Studio seems to be 32 bit (both C# express and the full version).
    I tried the proceedure suggested by DWHD but this did not seem to make any difference. I could not see the csgl.dll file from within the 'Add reference' screen within Visual Studio. The files are visible in Windows Explorer, and were installed with the provided install script in the "libinstall" folder as above (this .bat runs the command: gacutil.exe /if csgl.dll).

    However changing the target build from 64bit to X86 (in other words, setting the target build to 32 bit instead of the default 64 bit) solved the problem and the application displayed a rotating textured object and did not give a run-time error.

    You can change the target build in MS Visual Studio 2010 (full version) using the 'Build' tab of the C# project properties. Use the pull-down menu on 'Platform target' and choose 'X86'.

    In order to alter the build target on MS Visual Studio C'# express, follow the instructions in the following post:
    http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvcs/thread/af44fa1e-a0e2-4f9f-90c4-0dd90fa3fb9e/

    I do not understand why 'csgl.dll' does not appear in the MS Visual Studio 'References' window - other DLL's do appear but other DLL's that appear in a windows explorer list are also missing.

     
  • Ehsan Samadian
    Ehsan Samadian
    2012-04-30

    if display error "The type initializer for 'CsGL.OSLib' threw an exception"   !!!!!!!!!!!?????
    Do not worry.
    Help From site 

    s1390.mihanblog.com

     
  • Anand
    Anand
    2013-07-21

    "I do not understand why 'csgl.dll' does not appear in the MS Visual Studio 'References' window - other DLL's do appear but other DLL's that appear in a windows explorer list are also missing.".......

    its because of the 64 bit os...copy the dll's to C:\Windows\SysWOW64 then reference it to the new address..