sábado, 18 de septiembre de 2010

FreeBSD, Mono y FireBird .Net Provider

Al intentar correr un programa C# compilado en windows, el cual usa el .Net Provider para Firebird me arrojo el siguiente error:

When the FbConnection.Open() method was called, one exception was raised:

Unhandled Exception: System.TypeInitializationException: An exception was
thrown by the type initializer for FirebirdSql.Data.Common.Charset --->
System.ArgumentException: Encoding name 'shift_jis' not supported
Parameter name: name
at System.Text.Encoding.GetEncoding (System.String name) [0x00000]
at FirebirdSql.Data.Common.Charset.GetEncoding () [0x00000]
at FirebirdSql.Data.Common.Charset..ctor (Int32 id, System.String name,
Int32 bytesPerCharacter, System.String systemName) [0x00000]
at FirebirdSql.Data.Common.Charset.InitializeSupportedCharsets ()
[0x00000]



Esto se debe a que la dll del Provider de Firebird (FirebirdSql.Data.FirebirdClient.dll)
fue compilada con el Framework .Net de Windows y por lo tanto encapsula una serie de
CharSet que no existe en nuestro sistema operativo, no solo en FreeBSD, sino
tambien cualquier OS unix. Por suerte en la pagina oficial de FireBird estan dos
versiones de esta dll, una para .Net Windows, otra para Mono. Con esta desaparece el
error* pero me trae uno nuevo:

Unhandled Exception: System.ArgumentOutOfRangeException: Index is less than 0 or more than or equal to the list count.
Parameter name: index
0
at System.Collections.ArrayList.ThrowNewArgumentOutOfRangeException (System.String name, System.Object actual,
System.String message) [0x00000] in :0
at System.Collections.ArrayList.get_Item (Int32 index) [0x00000] in :0
at System.Diagnostics.ProcessModuleCollection.get_Item (Int32 index) [0x00000] in :0
at System.Diagnostics.Process.get_MainModule () [0x00000] in :0
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_MainModule ()
at FirebirdSql.Data.FirebirdClient.FbConnectionInternal.GetProcessName () [0x00000] in :0


En un sistema operativo basado en Linux nunca lo veremos este error, ya que las
funciones encapsuladas en el System.Diagnostics.Process hace un llamado a un
recurso propio del OS: "/PROC"

En FreeBSD no viene habilitado por defecto a diferencia de Linux, asi que lo debemos
de activar agregando la siguiente lineas en el /etc/fstab :
proc /proc procfs rw 0 0

Luego de reiniciar el sistema estara activado. Pero si no deseamos esperar a
reiniciar el sistema, pues montamos el proc directamente:

mount -t procfs proc /proc

Nuevamente probamos nuestro programa y funciona !

*Nota: para los que le sirva la informacion, en Ubuntu 10 no me funciono el .Net Provider de Firebird para Mono,
ya que me dio otro mensaje de error buscando otro CharSet diferente (EUC-JP),
en este caso la solucion es un poco mas trabajosa, intentar de activar/registrar este
charSet en Ubuntu o compilar los fuentes del .Net Provider en Ubuntu y utilizar la dll generada, esta ultima opcion fue la que yo tome para resolver el error.

No hay comentarios: