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

plaid cholbr1 at lsu.edu
Thu Jan 12 21:51:10 UTC 2012


I have posted this in Mono - WinForms as well under

http://mono.1490590.n4.nabble.com/Porting-Windows-NET-4-WinForm-Application-To-NIX-With-Mono-Unexpected-binary-element-0-tp4289685p4289685.html

as per Stifu's suggestion (forgive me, I'm new to this forum) but I didn't
want to try to move it as I wasn't sure where it fit best.

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

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.
--
View this message in context: http://mono.1490590.n4.nabble.com/Porting-Windows-NET-4-WinForm-Application-To-NIX-With-Mono-Unexpected-binary-element-0-tp4290598p4290598.html
Sent from the Mono - Dev mailing list archive at Nabble.com.


More information about the Mono-devel-list mailing list