Quantcast

Porting Windows .NET 4 WinForm Application To *NIX With Mono - Unexpected binary element 0

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Porting Windows .NET 4 WinForm Application To *NIX With Mono - Unexpected binary element 0

plaid
This post has NOT been accepted by the mailing list yet.
I have a WinForms program ported from .NET 1.1 to .NET 4 (Full Profile) compiled as an x86 project within Visual Studio 2010 Ultimate on Windows 7 64-bit.

It has a combination of VB, C#, ASP.NET (Web Service ported to WCF) and as well connects to SQL.

--------------------------------------------------------------------------------------------------------

I've installed a VM of openSUSE 11.4 (both 32-bit and 64-bit) with the latest repository of Mono (2.10.6 and 2.10.2 respectively).

I've also installed the packages for
libgdiplus0
mono-basic (mono-data, mono-data-sqlite, mono-web, mono-winforms)
mono-wcf (mono-extras, mono-mvc)

and eventually found I also needed
mono-locale-extras

as well as the necessity to use
ln -s ~/.kde4 ~/.kde
and
export MONO_MWF_SCALING=disable

in order to get past my initial errors.

--------------------------------------------------------------------------------------------------------

Now, when I try to run my application it is failing out before loading the UI with the error:

System.Runtime.Serialization.Serialization Exception: Unexpected binary element: 0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject
...
at System.Resources.ResourceManager.GetObject(System.String name)
at MyNameSpace.MyForm.InitializeComponent()
...

After some debugging I realized it was from it not being able to load the resources for neither a PictureBox I have on the opening form nor the Icon I have set on the Form.

--------------------------------------------------------------------------------------------------------

in InitializeComponent() the code dealing with this error should be

Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(MyForm))
...
Me.pict.Image = CType(resources.GetObject("pict.Image"), System.Drawing.Image)
...
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)

--------------------------------------------------------------------------------------------------------

In the .resx file, they are listed as

  <data name="pict.Image" type="System.Drawing.Bitmap, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" mimetype="application/x-microsoft.net.object.bytearray.base64">
....

  <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" mimetype="application/x-microsoft.net.object.bytearray.base64">
...

--------------------------------------------------------------------------------------------------------

Am I missing something here?

Just as a curiousity I replaced the pict.Image line with a Shared Function I use in other places to swap in and out embedded resources of images which looks something like

    Public Shared Function GetBMPImage(ByVal name As String) As Bitmap
        GetBMPImage = Nothing
        Dim stream As IO.Stream
        Try
            Dim execAssembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly
            stream = execAssembly.GetManifestResourceStream(String.Concat(GetType(MyForm).Namespace, ".", name, ".bmp"))
            GetBMPImage = New Bitmap(stream)
        Catch err As Exception
            'TODO: Err Handling
        Finally
        End Try
    End Function

and commented out the Me.Icon line

...The form loaded with the Image I used and I was able to use that form properly until it tried to open another Form which has the same problem...

I must have missed something simple here cause I can't imagine this is a default issue with Mono, right?

Any responses would be appreciated.

Ars Longa, Vita Brevis.

Ars Longa, Vita Brevis.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Porting Windows .NET 4 WinForm Application To *NIX With Mono - Unexpected binary element 0

Stifu
This post has NOT been accepted by the mailing list yet.
It sounds like a Mono ResourceManager bug to me.
I reported a bug that sounds similar a little while ago: http://bugzilla.xamarin.com/show_bug.cgi?id=749

In my case, I found out a workaround: adding the file to the project, and setting it as embedded resource, rather than using an resx file.

plaid wrote
I have a WinForms program ported from .NET 1.1 to .NET 4 (Full Profile) compiled as an x86 project within Visual Studio 2010 Ultimate on Windows 7 64-bit.

It has a combination of VB, C#, ASP.NET (Web Service ported to WCF) and as well connects to SQL.

--------------------------------------------------------------------------------------------------------

I've installed a VM of openSUSE 11.4 (both 32-bit and 64-bit) with the latest repository of Mono (2.10.6 and 2.10.2 respectively).

I've also installed the packages for
libgdiplus0
mono-basic (mono-data, mono-data-sqlite, mono-web, mono-winforms)
mono-wcf (mono-extras, mono-mvc)

and eventually found I also needed
mono-locale-extras

as well as the necessity to use
ln -s ~/.kde4 ~/.kde
and
export MONO_MWF_SCALING=disable

in order to get past my initial errors.

--------------------------------------------------------------------------------------------------------

Now, when I try to run my application it is failing out before loading the UI with the error:

System.Runtime.Serialization.Serialization Exception: Unexpected binary element: 0
at System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject
...
at System.Resources.ResourceManager.GetObject(System.String name)
at MyNameSpace.MyForm.InitializeComponent()
...

After some debugging I realized it was from it not being able to load the resources for neither a PictureBox I have on the opening form nor the Icon I have set on the Form.

--------------------------------------------------------------------------------------------------------

in InitializeComponent() the code dealing with this error should be

Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(MyForm))
...
Me.pict.Image = CType(resources.GetObject("pict.Image"), System.Drawing.Image)
...
Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)

--------------------------------------------------------------------------------------------------------

In the .resx file, they are listed as

  <data name="pict.Image" type="System.Drawing.Bitmap, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" mimetype="application/x-microsoft.net.object.bytearray.base64">
....

  <data name="$this.Icon" type="System.Drawing.Icon, System.Drawing, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" mimetype="application/x-microsoft.net.object.bytearray.base64">
...

--------------------------------------------------------------------------------------------------------

Am I missing something here?

Just as a curiousity I replaced the pict.Image line with a Shared Function I use in other places to swap in and out embedded resources of images which looks something like

    Public Shared Function GetBMPImage(ByVal name As String) As Bitmap
        GetBMPImage = Nothing
        Dim stream As IO.Stream
        Try
            Dim execAssembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly
            stream = execAssembly.GetManifestResourceStream(String.Concat(GetType(MyForm).Namespace, ".", name, ".bmp"))
            GetBMPImage = New Bitmap(stream)
        Catch err As Exception
            'TODO: Err Handling
        Finally
        End Try
    End Function

and commented out the Me.Icon line

...The form loaded with the Image I used and I was able to use that form properly until it tried to open another Form which has the same problem...

I must have missed something simple here cause I can't imagine this is a default issue with Mono, right?

Any responses would be appreciated.

Ars Longa, Vita Brevis.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Porting Windows .NET 4 WinForm Application To *NIX With Mono - Unexpected binary element 0

plaid
This post has NOT been accepted by the mailing list yet.
This post was updated on .
Sounds like your case is pretty much exactly the same case.  In my case I find that it fails with Images as well as Icons (where the Cursor is effectively the same as an Icon).

What is the resx entry for the Cursor you tried in your example?
**EDIT**
Looked at the posted files from your bug listing, it is the same mimetype

<data name="hand" type="System.Windows.Forms.Cursor, System.Windows.Forms" mimetype="application/x-microsoft.net.object.bytearray.base64">

as I expected.  I wonder if it is trying to read it as

application/x-microsoft.net.object.binary.base64

and that's why it's failing.  That's a complete guess though.
**EDIT**

What I did with that GetBMPImage Function is essentially the same as your workaround, however, in my case, I have waaaay too many forms with images and icons in this manner to try to replace them all with this sort of process (especially considering it shouldn't be necessary to "workaround").

I get the feeling the issue is in how it's handling/converting

application/x-microsoft.net.object.bytearray.base64

types when it tries to digest the resources.

Any ideas of where I might be able to post this to verify such a premise and/or elevate it as a bug?  It seems like it would be a fairly common problem for ANY Windows Forms application generated from Windows to *NIX and/or Mac.
Ars Longa, Vita Brevis.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Porting Windows .NET 4 WinForm Application To *NIX With Mono - Unexpected binary element 0

Stifu
This post has NOT been accepted by the mailing list yet.
"What is the resx entry for the Cursor you tried in your example?"
What do you mean? You should have everything you need in the solution attached to the bug report.

"Any ideas of where I might be able to post this to verify such a premise and/or elevate it as a bug?"
Well, I already reported the bug, so if it's the same one, there's no need to report anything else. But you may post extra info on the bug report. It may also help to bring up this issue on more popular mailing lists, such as Mono - Dev. And you might want to  check out the ResourceManager class  (https://github.com/mono/mono/blob/master/mcs/class/corlib/System.Resources/ResourceManager.cs), or related classes...

I don't think I'll be able to help much, but feel free to ask for more info if needed.

plaid wrote
Sounds like your case is pretty much exactly the same case.  In my case I find that it fails with Images as well as Icons (where the Cursor is effectively the same as an Icon).

What is the resx entry for the Cursor you tried in your example?

What I did with that GetBMPImage Function is essentially the same as your workaround, however, in my case, I have waaaay too many forms with images and icons in this manner to try to replace them all with this sort of process (especially considering it shouldn't be necessary to "workaround").

I get the feeling the issue is in how it's handling/converting

application/x-microsoft.net.object.bytearray.base64

types when it tries to digest the resources.

Any ideas of where I might be able to post this to verify such a premise and/or elevate it as a bug?  It seems like it would be a fairly common problem for ANY Windows Forms application generated from Windows to *NIX and/or Mac.
Loading...