[MonoDevelop] Opening a c# file gives InvalidCastException

Jonathan Wheelhouse wheelhouse@exemail.com.au
Mon, 28 Mar 2005 11:14:03 +1000


Hi

I have the latest mono, mcs, gtksourceview-sharp, MonoDevelop from svn
compiled and installed.

When I attempt to open a c# file using MonoDevelop I get the following
message on the console:

Error while loading System.InvalidCastException: Cannot cast from source type to destination type.
in <0x00058> GtkSourceView.SourceLanguagesManager:GetLanguageFromMimeType (System.String mime_type)

(I've included the full error message below the dashed line.)

MonoDevelop doesn't crash but the file doesn't display; there is just a
blank window.

I know the mime type of the file is as it should be since I added a Console.WriteLine
statement.  When I run monodevelop on a c# file I get the following:
jdw SourceEditorDisplayBinding.Load file :/usr/local/src/mono/tomboy/Tomboy/Tomboy.cs: mimetype :text/x-csharp:

GtkSourceView.SourceLanguagesManager shows the following:

	[DllImport("gtksourceview-1.0")]
		static extern IntPtr gtk_source_languages_manager_get_language_from_mime_type(IntPtr raw, string mime_type);

		public GtkSourceView.SourceLanguage GetLanguageFromMimeType(string mime_type) {
			IntPtr raw_ret = gtk_source_languages_manager_get_language_from_mime_type(Handle, mime_type);
			GtkSourceView.SourceLanguage ret;
			if (raw_ret == IntPtr.Zero)
				ret = null;
			else
				ret = (GtkSourceView.SourceLanguage) GLib.Object.GetObject(raw_ret);
			return ret;
		}

I assume the object returned is not a SourceLanguage; that's why there is an invalid cast. 


Text files (mimetype text/plain) open up OK.

I'm running Debian unstable; have also got libgnome-cil and its
dependencies installed so I can compile and run tomboy.

Version of Debian libgtksourceview is 1.2.0-1 .

Any ideas?

------------------------------------------------------------------------
/usr/local/src/mono/MonoDevelop$ make run
cd build/bin && LD_LIBRARY_PATH=`echo "/usr/local/lib:" | sed 's/^://g'`
/usr/local/bin/mono --debug MonoDevelop.exe
Entering VB.NET parser
Reading
/home/jonathan/.config/MonoDevelop//CodeCompletionData/mscorlib_1.0.5000.0_b77a5c561934e089.pidb
Creating DefaultWorkbench
Socket already in use

jdw SourceEditorDisplayBinding.Load file :/usr/local/src/mono/tomboy/Tomboy/Tomboy.cs: mimetype :text/x-csharp:

Error while loading System.InvalidCastException: Cannot cast from source
type to destination type.
in <0x00058>
GtkSourceView.SourceLanguagesManager:GetLanguageFromMimeType
(System.String mime_type)
in <0x00016> MonoDevelop.SourceEditor.Gui.SourceEditorBuffer:LoadText
(System.String text, System.String mime)
in <0x00036> MonoDevelop.SourceEditor.Gui.SourceEditorBuffer:LoadFile
(System.String file, System.String mime)
in <0x00066>
MonoDevelop.SourceEditor.Gui.SourceEditorDisplayBindingWrapper:Load
(System.String fileName)
in <0x0002e>
MonoDevelop.SourceEditor.Gui.SourceEditorDisplayBinding:CreateContentForFile
(System.String fileName)
in <0x00023>
MonoDevelop.Services.DefaultFileService+LoadFileWrapper:Invoke
(System.String fileName)
in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void_string
(string)
in <0x00014>
MonoDevelop.Core.Services.FileUtilityService+LoadWrapper:Invoke ()
in (wrapper delegate-invoke) System.MulticastDelegate:invoke_void ()
in <0x00018> MonoDevelop.Core.Services.FileUtilityService:ObservedLoad
(MonoDevelop.Core.Services.FileOperationDelegate saveFile, System.String
fileName, System.String message, FileErrorPolicy policy)