Home › Forums › Support › System.TypeInitializationException happens on iOS device, not in simulator
Tagged: NetworkComms Exception Xamarin
- This topic has 3 replies, 2 voices, and was last updated 9 years ago by Anonymous.
-
AuthorPosts
-
November 12, 2015 at 15:40 #4219AnonymousInactive
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?
November 13, 2015 at 18:04 #4220AnonymousInactiveHeya 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,
MarcNovember 13, 2015 at 19:00 #4221AnonymousInactiveHi 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=1.0.0.0, 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 9 years ago by .
- This reply was modified 9 years ago by .
November 15, 2015 at 15:25 #4224AnonymousInactiveIt 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,
Marc -
AuthorPosts
- You must be logged in to reply to this topic.