Wiki
Version 5 (modified by Chuck, 15 years ago)

--

Troubleshooting

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:

obj.foo(1.0, 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):

obj.foo(1.0_f32, 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 in 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

System.Security.SecurityException

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=2.0.0.0, 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.

Other Problems

See UserSupport.

See also: DebuggingTopics, LanguageTopics