Version 7 (modified by Chuck, 9 years ago)



Here are some problems people run into when getting started with Cobra and their solution.

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.

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

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.Lang ...

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


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.

Other Problems

See UserSupport.

See also: DebuggingTopics, LanguageTopics