Home Forums Support System.TypeInitializationException happens on iOS device, not in simulator

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #4219

    I’m trying to make a chat app in Xamarin using NetworkComms. When testing on an iOS device rather than the simulator, I get the following exception:

    System.TypeInitializationException: An exception was thrown by the type initializer for NetworkCommsDotNet.NetworkComms ---> System.Exception: Object reference not set to an instance of an object
      at NetworkCommsDotNet.DPSBase.DPSManager.CreateObjectWithParameterlessCtor (System.String typeName) [0x00034] in <filename unknown>:0
      at NetworkCommsDotNet.DPSBase.DPSManager.GetDataSerializer[ExplicitSerializer] () [0x00032] in <filename unknown>:0
      at NetworkCommsDotNet.NetworkComms..cctor () [0x00170] in <filename unknown>:0
      --- End of inner exception stack trace ---
      at Program.iOS.ViewController.InitializeServer () [0x0002c] in /…/Program/iOS/ViewController.cs:116
      at Program.iOS.ViewController.startServer_TouchUpInside (UIKit.UIButton sender) [0x00002] in /…/Program/iOS/ViewController.cs:68
      at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
      at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/2320/bae2cdbe/source/maccore/src/UIKit/UIApplication.cs:77
      at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0001c] in /Users/builder/data/lanes/2320/bae2cdbe/source/maccore/src/UIKit/UIApplication.cs:60
      at Program.iOS.Application.Main (System.String[] args) [0x00008] in /…/Program/iOS/Main.cs:17

    My program works as it should on Android devices, Android simulators and iOS simulators, but not on my iPhone for some reason. Does anyone have any ideas?


    Heya Henry,

    How are you initialising or attempting to retrieve a DPS manager? Have you compared your approach to the one used in the iOS chat example?

    Kind regards,


    Hi Marc,
    I’m not sure that I’m doing that, but would that explain why it only doesn’t work on a physical iOS device?

    This is the server code I’ve got:

    private void StartServer()
    NetworkComms.AppendGlobalIncomingPacketHandler<Message> ("Message", MessageHandler);
    Connection.StartListening (ConnectionType.TCP, new IPEndPoint (IPAddress.Any, 0));

    The Message class is very similar to the ChatMessage class in the example. I noticed in the ChatWindow class in the example that it has this line:
    ChatApplication.Serializer = DPSManager.GetDataSerializer<NetworkCommsDotNet.DPSBase.ProtobufSerializer>();

    With a variable Serializer in ChatAppBase:
    public DataSerializer Serializer { get; set; }

    But if I try and do the following within my ViewController class (where the rest of the code is), I get an error:
    public DataSerializer Serializer = DPSManager.GetDataSerializer<NetworkCommsDotNet.DPSBase.ProtobufSerializer>();

    Error, even though I’ve got NetworkCommsDotNet in my references:
    The type 'NetworkCommsDotNet.DPSBase.DataSerializer' is defined in an assembly that is not referenced. Consider adding a reference to assembly 'NetworkCommsDotNet, Version=, Culture=neutral, PublicKeyToken=null'

    Sorry if I’m missing something basic with this, but I’m not really sure what to do.

    • This reply was modified 8 years, 7 months ago by .
    • This reply was modified 8 years, 7 months ago by .

    It looks like you are missing references in your project. I would recommend you look at how NetworkComms.Net is referenced in the provided iOS example project and ensure you are replicated that.

    Kind regards,

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.