Here are some problems people sometimes experience when getting started with Cobra.

Errors about "float"

Symptoms include error messages you weren't expecting about method calls and "float" arguments:, 1.0)   # error: Cannot convert...

Cobra supports fractional values with the types:

  • float32
  • float64
  • float (=float64)
  • decimal (the default)

One of these types has to be the default type for values such as "1.0" and "x/y". Cobra uses "decimal" because it is more accurate with respect to the base-10 numbers people normally work with (e.g., 10%, 1.6). However, some libraries--especially for graphics and games--expect binary floating point numbers. If your application is oriented towards such numbers you can change the default number type by placing this in your code:

@number float64

Or passing it at the command line:

cobra -number:float64 ...

You can also choose "float32".

If you only need the occasional float, you can use suffixes like "_f64" and "_f32" (or "_d" for decimal):, 1.0_f32)

64-bit vs. 32-bit Clash

Symptoms include a "BadImageFormatException". You might be running on a 64-bit operating system, but trying to use a DLL/library that is 32-bit native. In other words, you're using a C or C++ library built for 32-bit on a 64-bit system.

The solution is to build against the "x86" platform, instead of "x64" or "Any". Note that "Any" is the default, and will run in whatever is native to the machine such as 32-bit or 64-bit. You can target "x86" at the command line:

cobra -sharp-args:"/platform:x86" ...

or with a directive in a source file:

@args sharp-args:"/platform:x86"

Also note that you can "cd C:\Windows\Microsoft.NET\Framework64\v2.0.50727" and then enter "ldr64 setwow" to force .NET programs to run as 32-bit. You can enter "ldr64 set64" to switch back.

Metadata file "Foo.dll" could not be found

See LibraryCouldNotBeFound

System.IO.FileNotFoundException: Could not load file or assembly 'Cobra.Core …

When you run Cobra like so:

\PATH\TO\Cobra-VERSION\Source\Snapshot> cobra "\PATH\TO\my-first-program.cobra"

You get:

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Cobra.Core ...

You haven't installed Cobra. The "Snapshot" directory is only suitable for compiling the compiler and isn't otherwise directly used. Run "install-from-workspace" from the "Source" parent directory. After that, you can be in any directory, and typically will not be in the Cobra directories unless you are hacking on the compiler or in the "HowTo" or "Samples" (or maybe "Tests").

\PATH\TO\Cobra-VERSION\Source> install-from-workspace

The error is from the .Net runtime and is due the compiled program executing and not finding the Cobra runtime library (Cobra.Core.dll) to use.

The instruction above installs the cobra RTL in the GAC where it is globally available.

An alternative is to ensure that there is a copy of Cobra.Core.dll in the same directory as the executable program to be run.
This could be manually copied from the install (or cobra build directory tree) or alternatively
have the compiler do it for you using the cobra compiler -copy-core option when you compile your program.

564 .../wkspace1/Source> ./cobra -color ../Samples/BlindWatchMaker1.cobra

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Cobra.Core, Version=0.0.2955.1, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
File name: 'Cobra.Core, Version=0.0.2955.1, Culture=neutral, PublicKeyToken=null
   at BlindWatchMaker1..ctor()
   at MainWrapper.Main() in c:\Users\hops\src\cobra\wkspace1\Source\MainWrapper.cobra:line 3

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

565 xx:...wkspace1/Source> ./cobra -color -copy-core ../Samples/BlindWatchMaker1.cobra
Cumulative Selection:
Single step selection took 87 times longer than cumulative selection and *still* failed.
566 xx:...wkspace1/Source>


When you run a program created with Cobra you get "Unhandled Exception: System.Security.SecurityException".

This happens on Windows when the current directory is a network drive and the Cobra test runner is invoked. The key call within the test runner is to the instance method System.Reflection.Assembly.GetName(). The exception reads:

Unhandled Exception: System.Security.SecurityException: Request for the permissi
on of type 'System.Security.Permissions.FileIOPermission, mscorlib,
      Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.
   at System.Security.CodeAccessSecurityEngine.Check(Object demand,
      StackCrawlMark& stackMark, Boolean isPermSet)
   at System.Security.CodeAccessPermission.Demand()
   at System.Reflection.Assembly.VerifyCodeBaseDiscovery(String codeBase)
   at System.Reflection.Assembly.GetName(Boolean copiedName)
   at System.Reflection.Assembly.GetName()
   at Cobra.Lang_ert_5ff8.Test.TestRunner._collectTestsFor(Assembly ass,
      Boolean willFollowReferences, Set`1 found)

Workarounds include:

  1. Run the program on a non-network drive.
  2. Recompile with -include-tests:no option.

Internal Error About 'path'

Upon compiling you get this error:

error: COBRA INTERNAL ERROR / ArgumentException / Item has already been added.
       Key in dictionary: 'path' Key being added: 'path'

If you compile with -reveal-internal-exceptions you get this exception:

Unhandled Exception: 

System.ArgumentException: Item has already been added. Key in dictionary: 'path'  Key being added: 'path' 
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add) 
at System.Collections.Hashtable.Add(Object key, Object value) 
at System.Collections.Specialized.StringDictionary.Add(String key, String value) 
at System.CodeDom.Compiler.Executor.ExecWaitWithCaptureUnimpersonated(SafeUserTokenHandle userToken,
   String cmd, String currentDir, TempFileCollection tempFiles, String& outputName, String& errorName,
   String trueCmdLine) 

Cobra is your PATH twice such as seeing "C:\Cobra\bin" in your PATH more than one time. Fix the path.

Install Error: Unexpected debug information initialization error …

On Ubuntu (10.10), during installation, you get:

Compiling installation program...
error: Unexpected debug information initialization error "The assembly for default symbol writer cannot be loaded"
Compilation failed - 1 error, 0 warnings
Not running due to errors above.

The solution is to issue:

sudo apt-get build-dep monodevelop
sudo apt-get install mono-xbuild


Finally got .../HowTo/390-GTK.cobra to run under Windows XP, msys and MinGW:

  • built my own /usr/local/lib/pkgconfig/gtk-sharp-2.0.pc using Linux .pc as a model ... had to add several -r:./*.dll's to the Libs line
  • copy all *.dll to HowTo
  • copy gdk-pixbuf.loaders to .../HowTo/etc/gtk-2.0/
  Bill Drissel
  Grand Prairie, TX

Other Problems

See UserSupport.
See SomeCompilerMessages

See also: LibraryCouldNotBeFound, DebuggingTopics, LanguageTopics