[MonoDevelop] Further problems with libraries and assemblies

Lluis Sanchez lluis at ximian.com
Tue Nov 20 13:54:44 EST 2007

El dt 20 de 11 del 2007 a les 12:36 -0500, en/na dsmithers at talktalk.net
va escriure:
> Hi,
> I am now using MonoDevelop 0.15 (0.17 is not stable with Ubuntu 7.04)

MD 0.17 works great in Ubuntu 7.04. We haven't got any bug report about
problems with that distro.

> I am still struggling with libraries, and have found a way that works
> most of the time.
> I have written and compiled a library using 
> gmcs -target:module -out:lib/mysock.dll src/mysock.cs
> I have populated an AssemblyInfo.cs file and compiled it with 
> gmsc -target:lib -out:lib/mysocklib.dll -addmodule:lib/mysock.dll
> src/AssemblyInfo.cs
> As well as a line to a key file and various other strings,
> AssemblyInfo.cs contained the line
> [assembly: AssemblyVersion("1.0.*.*")] 
> but I found this to be very erratic. I kept getting invalid assembly
> info compile errors after rebuilding the library.
> I changed it to read 
> [assembly: AssemblyVersion("")] 
> I also found that I needed to add a link to mysock.dll to the bin
> directory containing my application.
> Does this all look sensible? 

To create a library, just run 

gmcs -target:lib src/mysock.cs src/AssemblyInfo.cs

> How can I specify which versions of an assembly are compatible with my
> application?

It depends. If the library is installed in the GAC, your application
will load only the library that exactly matches the version with which
your application was compiled. If there isn't any library with the same
exact version, your app will crash (this behavior can be changed by
installing 'policies', which allow mapping one library version to

If the library is not installed in the GAC, your app will load any
version you may have in the application directory.

> I also _sometimes_ have problems finding the
> System.Net.Sockets.UdpClient::set_EnableBroadcast when I run the
> binary. There is no compilation error, but I get a
> System.MissingMethodException raised. I say sometimes as some builds
> run correctly and the next build might fail. Usually rebuilding the
> library is sufficient to sort this out.
> The error is as follows:
> Unhandled exception: System.MissingMethodException: Method not found
> 'System.Net.Sockets.UdpClient::set_EnableBroadcast'
>   at <0x00000> <unknown method>
>   at AGSocket.CSocket.create(Int32 port, System.Byte[] address,
> AGSocket.FCallback cb) [0x00000]
>   at Main..ctor() [0x00000]
>   at gtkclient.MainClass.Main (System.string[] args) [0x00000]
> I have a native C# application that uses this library that behaves
> correctly.

Be careful when mixing assemblies compiled with mcs (.NET 1.1) and gmcs
(.NET 2.0). UdpClient.EnableBroadcast was introduced in .NET 2.0. So for
example let's say you create a library which sets
UdpClient.EnableBroadcast and you compile it with gmcs. Then, you create
an application which uses your library, but you compile that application
with mcs. When you run your application using "mono yourapp.exe", mono
will detect that yourapp.exe was compiled with the 1.1 runtime, and will
load the 1.1 libraries. So it will load the 1.1 version of UdpClient,
which doesn't have the EnableBroadcast property, and you'll get the
MissingMethod exception.

> Is there some path variable that I need to set?
> What about MONO_PATH? the runtime errors sometimes mention this, but
> the main mono documentation deprecates its use.

It is not a path problem, just a conflict of runtime versions.


More information about the Monodevelop-list mailing list