== Troubleshooting == 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: {{{ #!cobra 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: {{{ #!cobra @number float64 }}} Or passing it at the command line: {{{ #!cobra 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): {{{ #!cobra 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: {{{ #!cobra @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 === When you compile, you get the error: {{{ error: Metadata file "System.Xml.Linq.dll" could not be found }}} This can be a mismatch between .NET versions, such as the version Cobra is running on vs. the version the DLL in question was written against. The current solution is to explicitly point to the appropriate back-end C# compiler. Suppose you are accessing a .NET 3.5 DLL, the solution might then be one of these: {{{ cobra -c -d -native-compiler:C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe foo.cobra cobra -c -d -native-compiler:C:\Windows\Microsoft.NET\Framework64\v3.5\csc.exe foo.cobra }}} === 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 }}} === 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. === 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 }}} === !HowTo/390-GTK.cobra === 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/ {{{ Regards, Bill Drissel Grand Prairie, TX }}} === Other Problems === See UserSupport. See also: DebuggingTopics, LanguageTopics