let a= 4
let f arg=
printfn "%s" (nameof arg)
f a
On https://fable.io/ it's working but it's not working with https://tryfsharp.fsbolero.io/
The first run the code on a server. The second run the code with webassembly on the computer calling this it.
https://fable.io/ :
arg
https://tryfsharp.fsbolero.io/
let a= 4
Compiler output:
Compilation succeeded.
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Exception: may not call directly, should always be optimized away
at (wrapper managed-to-native) System.Reflection.RuntimeMethodInfo.InternalInvoke(System.Reflection.RuntimeMethodInfo,object,object[],System.Exception&)
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x34197b0 + 0x000ce> in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.RuntimeMethodInfo.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x34197b0 + 0x000f6> in <filename unknown>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) <0x3419060 + 0x00014> in <filename unknown>:0
at <StartupCode$WebFsc-Client>.$Executor+Run#42-1.Invoke (Microsoft.FSharp.Core.Unit unitVar) <0x4a37948 + 0x00028> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, TResult result1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x4a2e408 + 0x0001a> in <filename unknown>:0
at <StartupCode$FSharp-Core>.$Async+Delay#1064[T].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2e298 + 0x00036> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Invoke[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2ee98 + 0x000a0> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Bind[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, Microsoft.FSharp.Control.FSharpAsync`1[T] part1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x4a374d8 + 0x00068> in <filename unknown>:0
at WebFsc.Client.ScreenOut+Wrap#109-3[a].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a373c8 + 0x00014> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Invoke[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2ee98 + 0x000a0> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, TResult result1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x4a2e408 + 0x00064> in <filename unknown>:0
at <StartupCode$FSharp-Core>.$Async+Delay#1064[T].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2e298 + 0x00036> in <filename unknown>:0
at <StartupCode$FSharp-Core>.$Async+Catch#1142[T].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2de80 + 0x00074> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Invoke[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2dae0 + 0x000a0> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Bind[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, Microsoft.FSharp.Control.FSharpAsync`1[T] part1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x4a2d860 + 0x00068> in <filename unknown>:0
at Elmish.Cmd+bind#52-3[a].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x4a2d5d8 + 0x00014> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.Invoke[T] (Microsoft.FSharp.Control.FSharpAsync`1[T] computation, Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x3a95c38 + 0x000a0> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives.CallThenInvoke[T,TResult] (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt, TResult result1, Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] part2) <0x3a90ed8 + 0x00064> in <filename unknown>:0
at <StartupCode$FSharp-Core>.$Async+Delay#1064[T].Invoke (Microsoft.FSharp.Control.AsyncActivation`1[T] ctxt) <0x3a90ce8 + 0x00036> in <filename unknown>:0
at Microsoft.FSharp.Control.AsyncPrimitives+StartWithContinuations#915[T].Invoke (Microsoft.FSharp.Core.Unit unitVar0) <0x3abbdd0 + 0x000b6> in <filename unknown>:0
at Microsoft.FSharp.Control.Trampoline.Execute (Microsoft.FSharp.Core.FSharpFunc`2[T,TResult] firstAction) <0x3a90560 + 0x0004a> in <filename unknown>:0
does the problem come from webassembly and why?
As #JL0PD correctly guessed in their comment, this is because Bolero's tryfsharp runs an older compiler that doesn't support nameof.
Updating it has been on my to-do list for ever, but there have been non-trivial changes both in Blazor and in the F# compiler service since the latest release of tryfsharp.bolero.
Related
I am facing crash issue in following line of code :
int bytesRead = await this.stream.ReadAsync(buffer, 0, buffer.Length, token);
Error Log :
{System.Security.Authentication.AuthenticationException: A call to SSPI failed, see inner exception. ---> Mono.Security.Interface.TlsException: Unknown Secure Transport error `DecryptionFail'.
at Mono.AppleTls.AppleTlsContext.CheckStatusAndThrow (Mono.AppleTls.SslStatus status, Mono.AppleTls.SslStatus[] acceptable) [0x00096] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/System/Mono.AppleTls/AppleTlsContext.cs:127
at Mono.AppleTls.AppleTlsContext.Read (System.Byte[] buffer, System.Int32 offset, System.Int32 count) [0x0009f] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/System/Mono.AppleTls/AppleTlsContext.cs:810
at Mono.Net.Security.MobileAuthenticatedStream.ProcessRead (Mono.Net.Security.BufferOffsetSize userBuffer) [0x00011] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:632
at Mono.Net.Security.AsyncReadRequest.Run (Mono.Net.Security.AsyncOperationStatus status) [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:320
at Mono.Net.Security.AsyncProtocolRequest+d__24.MoveNext () [0x000ff] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:221
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128
at System.Runtime.CompilerServices.ConfiguredTaskAwaitable+ConfiguredTaskAwaiter.GetResult () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:447
at Mono.Net.Security.AsyncProtocolRequest+d__23.MoveNext () [0x00046] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/System/Mono.Net.Security/AsyncProtocolRequest.cs:187
--- End of inner exception stack trace ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at Mono.Net.Security.MobileAuthenticatedStream+d__58.MoveNext () [0x001b9] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs:380
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:152
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.12.0.4/src/Xamarin.iOS/mcs/class/
Thanks for the help
I have a Xamarin iOS app, it was working properly, but I don't know what I've touched so it started raising this exception when I click on button to move to another view in storyboard:
System.Exception: Failed to marshal the Objective-C object 0x7ffa72c19570 (type: PropertyListViewController). Could not find an existing managed instance for this object, nor was it possible to create a new managed instance (because the type 'Rental.iOS.PropertyListViewController' does not have a constructor that takes one IntPtr argument).
at at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSendSuper_bool_bool (intptr,intptr,bool,bool)
at UIKit.UIViewController.BeginAppearanceTransition (System.Boolean isAppearing, System.Boolean animated) [0x0002c] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/build/ios/native/UIKit/UIViewController.g.cs:168
at XLPagerTabStrip.PagerTabStripViewController.UpdateContent () [0x001c3] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/XLPagerTabStrip/PagerTabStripViewController.cs:271
at XLPagerTabStrip.PagerTabStripViewController.Scrolled (UIKit.UIScrollView scrollView) [0x0000e] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/XLPagerTabStrip/PagerTabStripViewController.cs:339
at at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend_CGPoint (intptr,intptr,CoreGraphics.CGPoint)
at UIKit.UIScrollView.set_ContentOffset (CoreGraphics.CGPoint value) [0x00010] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/build/ios/native/UIKit/UIScrollView.g.cs:387
at XLPagerTabStrip.PagerTabStripViewController.UpdateContent () [0x00068] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/XLPagerTabStrip/PagerTabStripViewController.cs:247
at XLPagerTabStrip.PagerTabStripViewController.Scrolled (UIKit.UIScrollView scrollView) [0x0000e] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/XLPagerTabStrip/PagerTabStripViewController.cs:339
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at Rental.iOS.Application.Main (System.String[] args) [0x00008] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/Main.cs:17
What can I check in Interface Designer to make sure I am not doing anything wrong?
I added thhis constructor:
public partial class PropertyListViewController : UIViewController
{
protected PropertyListViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
~~~~
}
But now I receive this error :
Foundation.MonoTouchException: Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: -[UIViewController _loadViewFromNibNamed:bundle:] loaded the "PropertyListViewController" nib but the view outlet was not set.
Native stack trace:
0 CoreFoundation 0x000000010c73ad4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011713a21e objc_exception_throw + 48
2 CoreFoundation 0x000000010c7a42b5 +[NSException raise:format:] + 197
3 UIKit 0x00000001101b6aea -[UIViewController _loadViewFromNibNamed:bundle:] + 679
4 UIKit 0x00000001101b72e7 -[UIViewController loadView] + 177
5 UIKit 0x00000001101b761c -[UIViewController loadViewIfRequired] + 201
6 UIKit 0x00000001101be062 -[UIViewController __viewWillAppear:] + 118
7 Rental.iOS 0x000000010c0c6f9c xamarin_dyn_objc_msgSendSuper + 220
8 ??? 0x0000000130fb7405 0x0 + 5116752901
at at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSendSuper_bool_bool (intptr,intptr,bool,bool)
at UIKit.UIViewController.BeginAppearanceTransition (System.Boolean isAppearing, System.Boolean animated) [0x0002c] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/build/ios/native/UIKit/UIViewController.g.cs:168
at XLPagerTabStrip.PagerTabStripViewController.UpdateContent () [0x001c3] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/XLPagerTabStrip/PagerTabStripViewController.cs:271
at XLPagerTabStrip.PagerTabStripViewController.Scrolled (UIKit.UIScrollView scrollView) [0x0000e] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/XLPagerTabStrip/PagerTabStripViewController.cs:339
at at (wrapper managed-to-native) ObjCRuntime.Messaging:void_objc_msgSend_CGPoint (intptr,intptr,CoreGraphics.CGPoint)
at UIKit.UIScrollView.set_ContentOffset (CoreGraphics.CGPoint value) [0x00010] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/build/ios/native/UIKit/UIScrollView.g.cs:387
at XLPagerTabStrip.PagerTabStripViewController.UpdateContent () [0x00068] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/XLPagerTabStrip/PagerTabStripViewController.cs:247
at XLPagerTabStrip.PagerTabStripViewController.Scrolled (UIKit.UIScrollView scrollView) [0x0000e] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/XLPagerTabStrip/PagerTabStripViewController.cs:339
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/3969/7beaef43/source/xamarin-macios/src/UIKit/UIApplication.cs:63
at Rental.iOS.Application.Main (System.String[] args) [0x00008] in /Users/abd/Programming/Gits/Rental/Rental/Rental/Rental.iOS/Main.cs:17
PropertyListViewController does not have a constructor that takes one IntPtr argument.
In your UIViewController subclass, add an .ctor like so:
public partial class PropertyListViewController : UIViewController
{
protected PropertyListViewController(IntPtr handle) : base(handle)
{
// Note: this .ctor should not contain any initialization logic.
}
~~~~
}
I'm trying to make a Xamarin.Forms Project with speech recognition. For Android done and easy but i'm in the hell with iOS.
I found and i readed about Open Ears.
When tried to use this, i found some problems:
First i try to use this git: https://github.com/oganix/MonoTouch-OpenEars
but monotouch is not valid for Xamarin.iOS:
https://www.dropbox.com/s/41rc7iyskbwby9n/error_phoenix.png?dl=0
Next, i found this question Xamarin OpenEars Native Binding Not working on Device but works on Simulator.
After read, i tried to make a binding proyect and now i have this issue when use sharpie for autogenerate the Open Ears API:
/Users/cristian.fernandez/Workspace/Speech-iOS/OpenEarsDistribution/Framework/OpenEars.framework/Versions/A/Headers/acmod.h:50:10: fatal error: 'sphinxbase/cmd_ln.h' file not found
#include <sphinxbase/cmd_ln.h>
^
Binding...
System.ArgumentNullException: Value cannot be null.
Parameter name: annotation
at ICSharpCode.NRefactory.AbstractAnnotatable.AddAnnotation (System.Object annotation) in <filename unknown>:line 0
at ICSharpCode.NRefactory.CSharp.AstNode.AddAnnotation (System.Object annotation) in <filename unknown>:line 0
at Sharpie.Bind.Massagers.AnonymousStructMassager.VisitTypeDeclaration (ICSharpCode.NRefactory.CSharp.TypeDeclaration typeDeclaration) in <filename unknown>:line 0
at ICSharpCode.NRefactory.CSharp.TypeDeclaration.AcceptVisitor (IAstVisitor visitor) in <filename unknown>:line 0
at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitChildren (ICSharpCode.NRefactory.CSharp.AstNode node) in <filename unknown>:line 0
at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitTypeDeclaration (ICSharpCode.NRefactory.CSharp.TypeDeclaration typeDeclaration) in <filename unknown>:line 0
at Sharpie.Bind.Massagers.AnonymousStructMassager.VisitTypeDeclaration (ICSharpCode.NRefactory.CSharp.TypeDeclaration typeDeclaration) in <filename unknown>:line 0
at ICSharpCode.NRefactory.CSharp.TypeDeclaration.AcceptVisitor (IAstVisitor visitor) in <filename unknown>:line 0
at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitChildren (ICSharpCode.NRefactory.CSharp.AstNode node) in <filename unknown>:line 0
at ICSharpCode.NRefactory.CSharp.DepthFirstAstVisitor.VisitSyntaxTree (ICSharpCode.NRefactory.CSharp.SyntaxTree syntaxTree) in <filename unknown>:line 0
at Sharpie.Bind.DocumentSyntaxTree.AcceptVisitor (IAstVisitor visitor) in <filename unknown>:line 0
at Sharpie.Bind.BindingMassager.Massage (ICSharpCode.NRefactory.CSharp.AstNode astNode, BindingTarget bindingTarget) in <filename unknown>:line 0
at Sharpie.Bind.BindingFrontend.Bind (Clang.Ast.Decl decl) in <filename unknown>:line 0
at Sharpie.BindTool.HandleTranslationUnit (Clang.Ast.TranslationUnitDecl decl) in <filename unknown>:line 0
at Clang.Driver.HandleTranslationUnit (Clang.Ast.TranslationUnitDecl translationUnit) in <filename unknown>:line 0
at Clang.Driver.HandleTranslationUnit (IntPtr translationUnit) in <filename unknown>:line 0
at (wrapper managed-to-native) Clang.Driver:RunInternal (Clang.Driver,string[],string,Clang.Frontend.DiagnosticConsumer)
at Clang.Driver.Run (System.String[] inputFiles, System.String[] clangArgs, Clang.Frontend.DiagnosticConsumer diagnosticConsumer) in <filename unknown>:line 0
at Sharpie.ParseTool.Run () in <filename unknown>:line 0
at Sharpie.BindTool.CoreRun () in <filename unknown>:line 0
at Sharpie.BindTool.Run () in <filename unknown>:line 0
I use this for launch sharpie:
sharpie bind --output=libOpenEars --namespace=libOpenEars --sdk=iphoneos9.2 /Users/cristian.fernandez/Workspace/Speech-iOS/OpenEarsDistribution/Framework/OpenEars.framework/Versions/A/Headers/*.h
What can i do now besides cry?
Thanks for all and sorry for my English.
Not sure why my code isn't working as I've followed examples I've found. Trying to get my iOS game to save and load data back using Unity3D but not using the player.prefs.
On the scene's I have this
void OnDisable(){
GameController.Save ();
}
void OnEable(){
GameController.Load ();
}
Game Controller is a static method..
static public void Save()
{
Debug.Log("Saving Player Data...");
print ("Saving Player Data...");
var bf = new BinaryFormatter();
var file = File.Create(Application.persistentDataPath + "/CatEscapeInfo.dat");
var data = new PlayerData
{
PlayerLives = PlayerLives,
Score = Score,
Distance = Distance,
CurrentLevelNo = CurrentLevelNo,
HighestLevelCompleted = HighestLevelCompleted
};
bf.Serialize(file, data);
file.Close();
//PlayerPrefs.SetString (data);
Debug.Log ("Player Data Saved: " + PlayerLives + ", " + Score);
print ("Player Data Saved: " + PlayerLives + ", " + Score);
}
static public void Load()
{
Debug.Log("Loading Player Data...");
if (File.Exists(Application.persistentDataPath + "/CatEscapeInfo.dat"))
{
var bf = new BinaryFormatter();
var file = File.Open(Application.persistentDataPath + "/CatEscapeInfo.dat", FileMode.Open);
var data = bf.Deserialize(file) as PlayerData;
file.Close();
Debug.Log("Player Data Loaded: " + data.PlayerLives + ", " + data.Score);
print ("Player Data Loaded: " + data.PlayerLives + ", " + data.Score);
if (data != null)
{
PlayerLives = data.PlayerLives;
Score = data.Score;
Distance = data.Distance;
CurrentLevelNo = data.CurrentLevelNo;
HighestLevelCompleted = data.HighestLevelCompleted;
}
}
}
Even though I have this code running, when I manually close the game on iOS and bring it back up it never loads the game back to the stats it had.
Any thoughts? Am I missing something?
Update:
In iOS XCode, I find it's spitting out this stack trace when trying to "Load" though at the this point the file doesn't exist yet.
On Loading This is Stack Trace:
> (Filename:
> /Applications/buildAgent/work/d63dfc6385190b60/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp
> Line: 49)
>
> SerializationException: Unexpected binary element: 255 at
> System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObject
> (BinaryElement element, System.IO.BinaryReader reader, System.Int64&
> objectId, System.Object& value,
> System.Runtime.Serialization.SerializationInfo& info) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadNextObject
> (BinaryElement element, System.IO.BinaryReader reader) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectReader.ReadObjectGraph
> (BinaryElement elem, System.IO.BinaryReader reader, Boolean
> readHeaders, System.Object& result,
> System.Runtime.Remoting.Messaging.Header[]& headers) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.NoCheckDeserialize
> (System.IO.Stream serializationStream,
> System.Runtime.Remoting.Messaging.HeaderHandler handler) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize
> (System.IO.Stream serializationStream) [0x00000] in <filename
> unknown>:0 at GameController.Load () [0x00000] in <filename
> unknown>:0 at GameController.OnEnable () [0x00000] in <filename
> unknown>:0 (Filename: Line: -1)
On Saving, This is Stack Trace:
> Saving Player Data... UnityEngine.Debug:Internal_Log(Int32, String,
> Object) UnityEngine.Debug:Log(Object)
> UnityEngine.MonoBehaviour:print(Object) GameController:Save()
> GameController:OnDisable() UnityEngine.Object:Destroy(Object, Single)
> UnityEngine.Object:Destroy(Object) GameController:Awake() (Filename:
> /Applications/buildAgent/work/d63dfc6385190b60/artifacts/iPhonePlayer-armv7Generated/UnityEngineDebug.cpp
> Line: 49)
>
> ExecutionEngineException: Attempting to JIT compile method
> 'PlayerData__TypeMetadata4:.ctor ()' while running with --aot-only.
>
> at System.Reflection.MonoCMethod.Invoke (System.Object obj,
> BindingFlags invokeAttr, System.Reflection.Binder binder,
> System.Object[] parameters, System.Globalization.CultureInfo culture)
> [0x00000] in <filename unknown>:0 Rethrow as
> TargetInvocationException: Exception has been thrown by the target of
> an invocation. at System.Reflection.MonoCMethod.Invoke
> (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder
> binder, System.Object[] parameters, System.Globalization.CultureInfo
> culture) [0x00000] in <filename unknown>:0 at
> System.Reflection.MonoCMethod.Invoke (BindingFlags invokeAttr,
> System.Reflection.Binder binder, System.Object[] parameters,
> System.Globalization.CultureInfo culture) [0x00000] in <filename
> unknown>:0 at System.Reflection.ConstructorInfo.Invoke
> (System.Object[] parameters) [0x00000] in <filename unknown>:0 at
> System.Activator.CreateInstance (System.Type type, Boolean nonPublic)
> [0x00000] in <filename unknown>:0 at
> System.Activator.CreateInstance (System.Type type) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.CreateMemberTypeMetadata
> (System.Type type) [0x00000] in <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.GetObjectData
> (System.Object obj,
> System.Runtime.Serialization.Formatters.Binary.TypeMetadata& metadata,
> System.Object& data) [0x00000] in <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObject
> (System.IO.BinaryWriter writer, Int64 id, System.Object obj) [0x00000]
> in <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectInstance
> (System.IO.BinaryWriter writer, System.Object obj, Boolean
> isValueObject) [0x00000] in <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteQueuedObjects
> (System.IO.BinaryWriter writer) [0x00000] in <filename unknown>:0
> at
> System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteObjectGraph
> (System.IO.BinaryWriter writer, System.Object obj,
> System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize
> (System.IO.Stream serializationStream, System.Object graph,
> System.Runtime.Remoting.Messaging.Header[] headers) [0x00000] in
> <filename unknown>:0 at
> System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize
> (System.IO.Stream serializationStream, System.Object graph) [0x00000]
> in <filename unknown>:0 at GameController.Save () [0x00000] in
> <filename unknown>:0 at GameController.OnDisable () [0x00000] in
> <filename unknown>:0 UnityEngine.Object:Destroy(Object, Single)
> UnityEngine.Object:Destroy(Object) GameController:Awake()
Put this code to Awake or Start funtion in your scene script:
// Forces a different code path in the BinaryFormatter that doesn't rely on run-time code generation (which would break on iOS).
Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
By default Mono binary-serializer uses JIT-compilation which is unsupported by iOS. Fortunately, there is a way (the code above) to switch it to use reflection instead.
Proof / See also:
http://answers.unity3d.com/questions/725419/filestream-binaryformatter-from-c-to-ios-doesnt-wo.html
http://answers.unity3d.com/questions/30930/why-did-my-binaryserialzer-stop-working.html
Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER", "yes");
Create an error in the Unity editor like:
"Environment" not found in namespace
After hours of searching I found the following code that works perfectly:
System.Environment.SetEnvironmentVariable("MONO_REFLECTION_SERIALIZER","yes");
I hope it'll help.
I am getting this error when trying to create a new View in an ASP.Net MVC 4 project in Xamarin Studio. There are no pending updates in my setup. How can I fix this?
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. ---> System.TypeLoadException: A type
load exception has occurred. at
MonoDevelop.AspNet.Mvc.Gui.FolderCommandHandler.AddView () [0x00070]
in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/addins/AspNet/MonoDevelop.AspNet.Mvc/Gui/FolderNodeBuilderExtension.cs:154
at (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke
(System.Reflection.MonoMethod,object,object[],System.Exception&) at
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[]
parameters, System.Globalization.CultureInfo culture) [0x00054] in
/private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Reflection/MonoMethod.cs:230
--- End of inner exception stack trace --- at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags
invokeAttr, System.Reflection.Binder binder, System.Object[]
parameters, System.Globalization.CultureInfo culture) [0x00069] in
/private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Reflection/MonoMethod.cs:238
at System.Reflection.MethodBase.Invoke (System.Object obj,
System.Object[] parameters) [0x00000] in
/private/tmp/source/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-3.2.5/mcs/class/corlib/System.Reflection/MethodBase.cs:114
at MonoDevelop.Components.Commands.DefaultCommandHandler.Run
(System.Object target, MonoDevelop.Components.Commands.Command cmd)
[0x00019] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs:2094
at MonoDevelop.Components.Commands.CustomCommandTargetAttribute.Run
(System.Object target, MonoDevelop.Components.Commands.Command cmd)
[0x00009] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CustomCommandTargetAttribute.cs:101
at
MonoDevelop.Ide.Gui.Components.NodeCommandHandler+TransactedNodeHandlerAttribute.Run
(System.Object target, MonoDevelop.Components.Commands.Command cmd)
[0x0002d] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Gui.Components/NodeCommandHandler.cs:296
at
MonoDevelop.Components.Commands.CustomCommandTargetAttribute.MonoDevelop.Components.Commands.ICommandTargetHandler.Run
(System.Object target, MonoDevelop.Components.Commands.Command cmd)
[0x00004] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CustomCommandTargetAttribute.cs:58
at MonoDevelop.Components.Commands.CommandHandlerInfo.Run
(System.Object cmdTarget, MonoDevelop.Components.Commands.Command cmd)
[0x00021] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs:1963
at
MonoDevelop.Components.Commands.CommandManager+c_AnonStorey82.<>m_D2
() [0x0005f] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs:1054
at MonoDevelop.Components.Commands.CommandManager.DispatchCommand
(System.Object commandId, System.Object dataItem, System.Object
initialTarget, CommandSource source) [0x002b0] in
/Users/builder/data/lanes/monodevelop-lion-license-sync/c5f82958/source/monodevelop/main/src/core/MonoDevelop.Ide/MonoDevelop.Components.Commands/CommandManager.cs:1071