[Mono-dev] NullReferenceException when trying to use socket with embedded mono2
Bill Holmes
billholmes54 at gmail.com
Wed Oct 8 14:13:58 EDT 2008
Hi,
We had the same problem. To work around this problem call
mono_jit_exec on a Main in an exe. Then proceed with calling your
methods as usual.
Specifically what we had to do was change the type of the assembly
being called to an executable and add a Main that does nothing. Then
we obtained and called the Main method (with mono_jit_exec) before
calling the real methods.
-bill
On Wed, Oct 8, 2008 at 3:09 AM, Mrak <konstantink at epsystems.lt> wrote:
>
> Hello,
>
> I'm using mono in embedded mode, and currently trying to upgrade runtime to
> version 2.0. However have a strange problem. When trying to use TCP sockets
> i'm getting the following exception:
>
> System.Configuration.ConfigurationErrorsException: Error Initializing the
> configuration system. ---> System.NullReferenceException: Object reference
> not set to an instance of an object
> at System.Configuration.ConfigurationManager.OpenExeConfigurationInternal
> (ConfigurationUserLevel userLevel, System.Reflection.Assembly
> calling_assembly, System.String exePath) [0x00000]
> at System.Configuration.ClientConfigurationSystem.get_Configuration ()
> [0x00000]
> --- End of inner exception stack trace ---
> at System.Configuration.ClientConfigurationSystem.get_Configuration ()
> [0x00000]
> at
> System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection
> (System.String configKey) [0x00000]
> at System.Configuration.ConfigurationManager.GetSection (System.String
> sectionName) [0x00000]
> at System.Net.Sockets.Socket.CheckProtocolSupport () [0x00000]
> at System.Net.Sockets.Socket..cctor () [0x00000]
>
> I've explored some source code and figured out that in this code
> (ConfigurationManager.cs starting from line 96):
>
> if (exePath == null || exePath.Length == 0) {
> if (!systemWebInUse && calling_assembly != null)
> exePath = calling_assembly.Location;
> else
> exePath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
> map.ExeConfigFilename = exePath.EndsWith (".config") ? exePath :
> exePath + ".config";
>
> Both calling_assembly and
> AppDomain.CurrentDomain.SetupInformation.ConfigurationFile are null so
> exePath.EndsWith(".config") fails with NullReferenceException
>
> I've checked, in embedded mode Assembly.GetEntryAssembly() returns null, so
> naturally calling_assembly here is null.
>
> Is it a bug or "feature" and how can I overcome it?
>
> Thank you very much in advance,
>
> --
> Konstantin Koryashev
> --
> View this message in context: http://www.nabble.com/NullReferenceException-when-trying-to-use-socket-with-embedded-mono2-tp19873451p19873451.html
> Sent from the Mono - Dev mailing list archive at Nabble.com.
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
More information about the Mono-devel-list
mailing list