serialization exemption when saving a binary file in Unity3d - c#

I'm trying to save two elements, a string and a list of strings to a binary file. I have the class set outside the main script:
}
the main script
}
[Serializable]
class SaveManager
{
public string Info;
public List<InfoSheetList> InfoSheetList ;
}
Then the function that calls it all
public void GetInfoSheet()
{
DatabaseManager.Instance.SQLiteInit();
string Info = PlayerPrefs.GetString ("Info");
string date = PlayerPrefs.GetString ("Date");
string Date=date.Replace("/","-");
string Name = PlayerPrefs.GetString ("Name");
string FilePath="C:/InfoSheets";
DatabaseManager.Instance.SQLiteInit();
InfoSheetList.Clear();
InfoSheetList= DatabaseManager.Instance.MakeInfoSheetList();
Debug.Log("How many in the list " + InfoSheetList.Count);
BinaryFormatter bf = new BinaryFormatter();
FileStream fs = File.Create(FilePath + "/" +Date+Name+"InfoSheet.gig");
Debug.Log (fs);
SaveManager sm= new SaveManager();
sm.Info=Info;
sm.InfoSheetList=InfoSheetList;
//PlayerPrefs.DeleteAll ();
bf.Serialize(fs, sm);
fs.Close();
Debug.Log(sm+ "Saved!");
Only I'm getting an exception-
SerializationException: Type 'InfoSheet' in Assembly 'Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.
System.Runtime.Serialization.FormatterServices.InternalGetSerializableMembers (System.RuntimeType type) (at :0)
System.Runtime.Serialization.FormatterServices+<>c__DisplayClass9_0.b__0 (System.Runtime.Serialization.MemberHolder _) (at :0)
System.Collections.Concurrent.ConcurrentDictionary2[TKey,TValue].GetOrAdd (TKey key, System.Func2[T,TResult] valueFactory) (at :0)
System.Runtime.Serialization.FormatterServices.GetSerializableMembers (System.Type type, System.Runtime.Serialization.StreamingContext context) (at :0)
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitMemberInfo () (at :0)
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.InitSerialize (System.Type objectType, System.Runtime.Serialization.ISurrogateSelector surrogateSelector, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.Formatters.Binary.SerObjectInfoInit serObjectInfoInit, System.Runtime.Serialization.IFormatterConverter converter, System.Runtime.Serialization.SerializationBinder binder) (at :0)
System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo.Serialize (System.Type objectType, System.Runtime.Serialization.ISurrogateSelector surrogateSelector, System.Runtime.Serialization.StreamingContext context, System.Runtime.Serialization.Formatters.Binary.SerObjectInfoInit serObjectInfoInit, System.Runtime.Serialization.IFormatterConverter converter, System.Runtime.Serialization.SerializationBinder binder) (at :0)
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.WriteArray (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo memberObjectInfo) (at :0)
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Write (System.Runtime.Serialization.Formatters.Binary.WriteObjectInfo objectInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo memberNameInfo, System.Runtime.Serialization.Formatters.Binary.NameInfo typeNameInfo) (at :0)
System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize (System.Object graph, System.Runtime.Remoting.Messaging.Header[] inHeaders, System.Runtime.Serialization.Formatters.Binary.__BinaryWriter serWriter, System.Boolean fCheck) (at :0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header[] headers, System.Boolean fCheck) (at :0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph, System.Runtime.Remoting.Messaging.Header[] headers) (at :0)
System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Serialize (System.IO.Stream serializationStream, System.Object graph) (at :0)
GigSheetManager.GetGigSheet () (at Assets/Scripts/GigSheetManager.cs:210)
UnityEngine.Events.InvokableCall.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent.cs:166)
UnityEngine.Events.UnityEvent.Invoke () (at C:/buildslave/unity/build/Runtime/Export/UnityEvent_0.cs:58)
UnityEngine.UI.Button.Press () (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:36)
UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/UI/Core/Button.cs:45)
UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:50)
UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) (at C:/buildslave/unity/build/Extensions/guisystem/UnityEngine.UI/EventSystem/ExecuteEvents.cs:261)
UnityEngine.EventSystems.EventSystem:Update()
What am I missing. The string is serializing, but the list is not.
Thanks in advance!

Alexander, you are right. All I had to do is to add System.Serializable to the Infosheet Class. After I did that it worked! Thanks!

Related

Observable Collection crashes while updating values

Not able to replace entire observable collection. As it throws exception.
How do I replace entire observable collection item? The suggested answers from other threads didn't work. Tried the following. Any suggestion would help on this.
Xaml
<Picker
x:Name=“Picker1”
Style="{StaticResource PickerStyle}"
ItemsSource="{Binding CodeNumberList}"
SelectedItem="{Binding CodeNumberText}”>
<Picker.Behaviors>
<xct:EventToCommandBehavior
EventName="SelectedIndexChanged"
Command="{Binding ItemChangedCommand}"
CommandParameter="{Binding Source={x:Reference Picker1},
Path=SelectedItem}"/>
</Picker.Behaviors>
</Picker>
<Picker
x:Name=“Picker2”
Style="{StaticResource PickerStyle}"
ItemsSource="{Binding PhoneNumberList}"
SelectedItem="{Binding PhoneNumberText}”>
</Picker>
ViewModel
private ObservableCollection<string> _phumberList;
public ObservableCollection<string> PhNumberList
{
get
{
return _phumberList;
}
set
{
_phumberList = value;
RaisePropertyChanged(nameof(this.PhNumberList));
}
}
private void ItemChangedCommandHandler(string obj)
{
PopulatePhoneList();
}
private void PopulatePhoneList()
{
// tried clearing PhNumberList.Clear() and then added items, that didn't work too
//Invalid cast exception thrown in below line
PhNumberList = new ObservableCollection<string>();
foreach (var item in CurrentUser?.InformationDetailItems)
{
PhNumberList.Add (item.PhoneNumber);
}
}
public On NavigatedTo(){
// populate default pickerList
PopulatePhoneList();
}
Exception :
//Invalid cast exception thrown in below line
PhNumberList = new ObservableCollection();
Stack Trace
at (wrapper castclass) System.Object.__castclass_with_cache(object,intptr,intptr)
at Prism.Commands.DelegateCommand`1[T].CanExecute (System.Object parameter) [0x00000] in d:\a\1\s\Source\Prism\Commands\DelegateCommand{T}.cs:113
at Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.CanExecute (System.Object parameter) [0x00000] in d:\a\1\s\Source\Prism\Commands\DelegateCommandBase.cs:67
at Xamarin.CommunityToolkit.Behaviors.EventToCommandBehavior.OnTriggerHandled (System.Object sender, System.Object eventArgs) [0x00039] in <823f4019dc404dea9e9331c7114e4863>:0
at Xamarin.Forms.Picker.OnSelectedIndexChanged (System.Object bindable, System.Object oldValue, System.Object newValue) [0x00012] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:283
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:512
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0004d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:374
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:349
at Xamarin.Forms.Picker.set_SelectedIndex (System.Int32 value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:114
at Xamarin.Forms.Picker.OnItemsCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00007] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:205
at (wrapper delegate-invoke) <Module>.invoke_void_object_NotifyCollectionChangedEventArgs(object,System.Collections.Specialized.NotifyCollectionChangedEventArgs)
at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00018] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:263
at System.Collections.ObjectModel.ObservableCollection`1[T].OnCollectionReset () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:362
at System.Collections.ObjectModel.ObservableCollection`1[T].ClearItems () [0x00018] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/System.ObjectModel/src/System/Collections/ObjectModel/ObservableCollection.cs:166
at System.Collections.ObjectModel.Collection`1[T].Clear () [0x00014] in /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/src/Xamarin.iOS/external/corefx/src/Common/src/CoreLib/System/Collections/ObjectModel/Collection.cs:81
at Xamarin.Forms.Internals.LockableObservableListWrapper.InternalClear () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\LockableObservableListWrapper.cs:71
at Xamarin.Forms.Picker.ResetItems () [0x00009] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:273
at Xamarin.Forms.Picker.OnItemsSourceChanged (System.Collections.IList oldValue, System.Collections.IList newValue) [0x0004c] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:231
at Xamarin.Forms.Picker.OnItemsSourceChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:213
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:512
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446
at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00226] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:160
at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:56
at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__49_0 () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:762
at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x000cb] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:773
at Xamarin.Forms.BindingExpression+WeakPropertyChangedProxy.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00012] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:666
at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
at Prism.Mvvm.BindableBase.OnPropertyChanged (System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in d:\a\1\s\Source\Prism\Mvvm\BindableBase.cs:99
at Prism.Mvvm.BindableBase.OnPropertyChanged (System.String propertyName) [0x00000] in d:\a\1\s\Source\Prism\Mvvm\BindableBase.cs:90
at Prism.Mvvm.BindableBase.RaisePropertyChanged (System.String propertyName) [0x00000] in d:\a\1\s\Source\Prism\Mvvm\BindableBase.cs:76
-->at ProjectMobile.ViewModels.DarFormPageViewModel.set_EquipmentNumberList (System.Collections.ObjectModel.ObservableCollection`1[T] value) [0x00008] in /Users/vpo1/Project-Mobile/MobileApp/ProjectMobile.ViewModels/PhFormPageViewModel:104 <--
at ProjectMobile.ViewModels.DarFormPageViewModel.PopulateEquipmentList (System.Boolean IsFromNavigatedTo) [0x00013] in /Users/vpo1/Project-Mobile/MobileApp/ProjectMobile.ViewModels/PhFormPageViewModel:940
at ProjectMobile.ViewModels.DarFormPageViewModel.DeliveryItemChangedCommandHandler (System.String obj) [0x00008] in /Users/vpo1/Project-Mobile/MobileApp/ProjectMobile.ViewModels/PhFormPageViewModel:61
at Prism.Commands.DelegateCommand`1[T].Execute (T parameter) [0x00000] in d:\a\1\s\Source\Prism\Commands\DelegateCommand{T}.cs:82
at Prism.Commands.DelegateCommand`1[T].Execute (System.Object parameter) [0x00000] in d:\a\1\s\Source\Prism\Commands\DelegateCommand{T}.cs:103
at Prism.Commands.DelegateCommandBase.System.Windows.Input.ICommand.Execute (System.Object parameter) [0x00000] in d:\a\1\s\Source\Prism\Commands\DelegateCommandBase.cs:62
at Xamarin.CommunityToolkit.Behaviors.EventToCommandBehavior.OnTriggerHandled (System.Object sender, System.Object eventArgs) [0x00042] in <823f4019dc404dea9e9331c7114e4863>:0
at Xamarin.Forms.Picker.OnSelectedIndexChanged (System.Object bindable, System.Object oldValue, System.Object newValue) [0x00012] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:283
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:512
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0004d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:374
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:349
at Xamarin.Forms.Picker.set_SelectedIndex (System.Int32 value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:114
at Xamarin.Forms.Picker.UpdateSelectedIndex (System.Object selectedItem) [0x00008] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:296
at Xamarin.Forms.Picker.OnSelectedItemChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00006] in D:\a\1\s\Xamarin.Forms.Core\Picker.cs:289
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:512
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x00173] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:446
at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x00226] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:160
at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:56
at Xamarin.Forms.BindingExpression+BindingExpressionPart.<PropertyChanged>b__49_0 () [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:762
at Xamarin.Forms.BindingExpression+BindingExpressionPart.PropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs args) [0x000cb] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:773
at Xamarin.Forms.BindingExpression+WeakPropertyChangedProxy.OnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00012] in D:\a\1\s\Xamarin.Forms.Core\BindingExpression.cs:666
at (wrapper delegate-invoke) <Module>.invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
at Prism.Mvvm.BindableBase.OnPropertyChanged (System.ComponentModel.PropertyChangedEventArgs args) [0x00000] in d:\a\1\s\Source\Prism\Mvvm\BindableBase.cs:99
at Prism.Mvvm.BindableBase.OnPropertyChanged (System.String propertyName) [0x00000] in d:\a\1\s\Source\Prism\Mvvm\BindableBase.cs:90
at Prism.Mvvm.BindableBase.RaisePropertyChanged (System.String propertyName) [0x00000] in d:\a\1\s\Source\Prism\Mvvm\BindableBase.cs:76
at ProjectMobile.ViewModels.DarFormPageViewModel.set_BolNumberText (System.String value) [0x00008] in /Users/vpo1/Project-Mobile/MobileApp/ProjectMobile.ViewModels/PhFormPageViewModel:118
at ProjectMobile.ViewModels.DarFormPageViewModel.OnNavigatedTo (Prism.Navigation.INavigationParameters parameters) [0x00170] in /Users/vpo1/Project-Mobile/MobileApp/ProjectMobile.ViewModels/PhFormPageViewModel:863
Removing this part of the code should resolve the problem:
<xct:EventToCommandBehavior
EventName="SelectedIndexChanged"
Command="{Binding ItemChangedCommand}"
CommandParameter="{Binding Source={x:Reference Picker1},
Path=SelectedItem}"/>
This can be done in many other ways, like using the CodeNumberText property to handle it. As it is likely a bug in that open source component you can submit the bug to their GitHub or fix it yourself.

Why when trying to make vertical scroll in editorwindow I'm getting exception InvalidOperationException: Stack empty.?

What I'm trying to do is to add automatic vertical scroll when expanding the editorwindow too much to the bottom :
If in the screenshot for example this is the original editorwindow size :
When clicking for example the Conversations and collapsing it then I want to make it with a vertical scroll :
I can keep stretching down the window with the mouse but I want to use scroll in that case instead :
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;
public class ConversationsEditorWindow : EditorWindow
{
[MenuItem("Window/Editor Window Test")]
static void Init()
{
// Get existing open window or if none, make a new one:
ConversationsEditorWindow window = (ConversationsEditorWindow)EditorWindow.GetWindow(typeof(ConversationsEditorWindow));
}
void OnGUI()
{
GameObject sel = Selection.activeGameObject;
ConversationTrigger targetComp = sel.GetComponent<ConversationTrigger>();
if (targetComp != null)
{
EditorGUILayout.BeginVertical();
var editor = Editor.CreateEditor(targetComp);
var tar = editor.targets;
editor.OnInspectorGUI();
EditorGUILayout.EndScrollView();
EditorGUILayout.EndVertical();
}
}
}
The exception message is a bit long :
The exception is on line 27 :
EditorGUILayout.EndScrollView();
InvalidOperationException: Stack empty.
System.Collections.Stack.Peek () (at :0)
UnityEngine.GUI.EndScrollView (System.Boolean handleScrollWheel) (at C:/buildslave/unity/build/Modules/IMGUI/GUI.cs:1481)
UnityEngine.GUILayout.EndScrollView (System.Boolean handleScrollWheel) (at C:/buildslave/unity/build/Modules/IMGUI/GUILayout.cs:387)
UnityEditor.EditorGUILayout.EndScrollView () (at C:/buildslave/unity/build/Editor/Mono/EditorGUI.cs:9203)
ConversationsEditorWindow.OnGUI () (at Assets/Editor/ConversationsEditorWindow.cs:27)
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at :0)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at :0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at :0)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:342)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:336)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:310)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect, System.Boolean customBorder, System.Boolean floatingWindow, System.Boolean isBottomTab) (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:361)
UnityEditor.DockArea.OldOnGUI () (at C:/buildslave/unity/build/Editor/Mono/GUI/DockArea.cs:320)
UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout) (at C:/buildslave/unity/build/Modules/UIElements/IMGUIContainer.cs:244)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
Stack empty message gives a clue what goes on - you are making a call to : EditorGUILayout.EndScrollView(); (trying to pop from gui stack) without calling BeginScrollView() beforehand.

ConfigurationErrorsException

I am getting an exception I have no clue how to debug. It is thrown on the following line:
var serializer = new XmlSerializer(typeof(Universe));
System.Configuration.ConfigurationErrorsException has been thrown
Error Initializing the configuration system.
What is the configuration system, where is it getting initialized and what does it have to do with the XmlSerializer?
The full exception:
System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system. ---> System.Configuration.ConfigurationErrorsException: Unrecognized configuration section <runtime> (/MyPath/Projects/Stars/Stars/Stars.Desktop/bin/Debug/net471/Stars.Desktop.app/Contents/MonoBundle/Stars.Desktop.exe.config line 3)
at System.Configuration.ConfigInfo.ThrowException (System.String text, System.Xml.XmlReader reader) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ConfigInfo.cs:77
at System.Configuration.SectionGroupInfo.ReadContent (System.Xml.XmlReader reader, System.Configuration.Configuration config, System.Boolean overrideAllowed, System.Boolean root) [0x0011f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/SectionGroupInfo.cs:330
at System.Configuration.SectionGroupInfo.ReadRootData (System.Xml.XmlReader reader, System.Configuration.Configuration config, System.Boolean overrideAllowed) [0x00007] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/SectionGroupInfo.cs:273
at System.Configuration.Configuration.ReadConfigFile (System.Xml.XmlReader reader, System.String fileName) [0x000ce] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/Configuration.cs:572
at System.Configuration.Configuration.Load () [0x00043] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/Configuration.cs:532
at System.Configuration.Configuration.Init (System.Configuration.Internal.IConfigSystem system, System.String configPath, System.Configuration.Configuration parent) [0x0005d] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/Configuration.cs:138
at System.Configuration.Configuration..ctor (System.Configuration.InternalConfigurationSystem system, System.String locationSubPath) [0x00056] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/Configuration.cs:96
at System.Configuration.InternalConfigurationFactory.Create (System.Type typeConfigHost, System.Object[] hostInitConfigurationParams) [0x0000d] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/InternalConfigurationFactory.cs:41
at System.Configuration.ConfigurationManager.OpenExeConfigurationInternal (System.Configuration.ConfigurationUserLevel userLevel, System.Reflection.Assembly calling_assembly, System.String exePath) [0x000ea] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ConfigurationManager.cs:119
at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x0000e] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs:49
--- End of inner exception stack trace ---
at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x0001f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs:52
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ClientConfigurationSystem.cs:61
at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/System.Configuration/System.Configuration/ConfigurationManager.cs:159
at System.Configuration.PrivilegedConfigurationManager.GetSection (System.String sectionName) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/misc/PrivilegedConfigurationManager.cs:24
at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/DiagnosticsConfiguration.cs:171
at System.Diagnostics.DiagnosticsConfiguration.Initialize () [0x0002a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/DiagnosticsConfiguration.cs:209
at System.Diagnostics.DiagnosticsConfiguration.get_SwitchSettings () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/DiagnosticsConfiguration.cs:29
at System.Diagnostics.Switch.InitializeConfigSettings () [0x00013] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/Switch.cs:272
at System.Diagnostics.Switch.InitializeWithStatus () [0x00046] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/Switch.cs:211
at System.Diagnostics.Switch.get_SwitchSetting () [0x0000a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/Switch.cs:144
at System.Diagnostics.BooleanSwitch.get_Enabled () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/compmod/system/diagnostics/BooleanSwitch.cs:39
at System.Xml.Serialization.TempAssembly.LoadGeneratedAssembly (System.Type type, System.String defaultNamespace, System.Xml.Serialization.XmlSerializerImplementation& contract) [0x00015] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System.Xml/System/Xml/Serialization/Compilation.cs:164
at System.Xml.Serialization.XmlSerializer..ctor (System.Type type, System.String defaultNamespace) [0x0007e] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System.Xml/System/Xml/Serialization/XmlSerializer.cs:198
at System.Xml.Serialization.XmlSerializer..ctor (System.Type type) [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2018-06/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System.Xml/System/Xml/Serialization/XmlSerializer.cs:177
at Stars.SaveManager.SaveLoader.SaveUniverse (Stars.Game.Universe universe) [0x0005d] in /MypPath/Projects/Stars/Stars/Stars/SaveManager/SaveLoader.cs:39
You have an error in app.config file. There is a problem with the section runtime. Be sure it is declared in and has valid structure and values.
Here the Inner exception message gives the hint
System.Configuration.ConfigurationErrorsException: Unrecognized configuration section <runtime>

Please call CachedImageRenderer.Init method in a platform specific project to use FFImageLoading?

When trying to use Xamarin FFImageLoading plugin on iOs I get this exception:
System.Exception: Please call CachedImageRenderer.Init method in a platform specific project to use FFImageLoading!
at FFImageLoading.Forms.CachedImage.OnSourcePropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00007] in C:\projects\ffimageloading\source\FFImageLoading.Forms\CachedImage.cs:133
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:625
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in D:\a\1\s\Xam
arin.Forms.Core\BindableObject.cs:417
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0003d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:573
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:99
at FFImageLoading.Forms.CachedImage.set_Source (Xamarin.Forms.ImageSource value) [0x00000] in C:\projects\ffimageloading\source\FFImageLoading.Forms\CachedImage.cs:173
at Demo.MainViewModel..ctor () [0x0001f] in <4cd5393447f94973bb9eef7c0de8880d>:0
at FullCameraApp.CameraPage.getLayoutImage (System.Int32 index) [0x00001] in <4cd5393447f94973bb9eef7c0de8880d>:0
at FullCameraApp.CameraPage..ctor (ScoreScan.webServices.WebServices webServices, System.Collections.Generic.List`1[T] imageBytesList) [0x0060b] in <4cd5393447f94973bb9eef7c0de8880d>:0
at ScoreScan.App..ctor () [0x0
0025] in <4cd5393447f94973bb9eef7c0de8880d>:0
at ScoreScan.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x0000d] in <4cd5393447f94973bb9eef7c0de8880d>:0
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 /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0002c] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.14.0.14/src/Xamarin.iOS/UIKit/UIApplication.cs:63
at ScoreScan.iOS.Application.Main (System.String[] args) [0x00001] in <4cd5393447f94973bb9eef7c0de8880d>:0
2018-10-08 19:47:10.229 ScoreScan.iOS[324:13181] Unhandled managed exception:
Please call CachedImageRenderer.Init method in a platform specific project to use FFImageLoading! (System.Exception)
at FFImageLoading.Forms.CachedImage.OnSourcePropertyChanged (Xamarin.Forms.BindableObject bindable, System.Object oldValue, System.Object newValue) [0x00007] in C:\projects\ffimageloading\source\FFImageLoading.Forms\CachedImage.cs:133
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00120] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:625
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in D:\a
\1\s\Xamarin.Forms.Core\BindableObject.cs:417
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value, System.Boolean fromStyle, System.Boolean checkAccess) [0x0003d] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:573
at Xamarin.Forms.BindableObject.SetValue (Xamarin.Forms.BindableProperty property, System.Object value) [0x00000] in D:\a\1\s\Xamarin.Forms.Core\BindableObject.cs:99
at FFImageLoading.Forms.CachedImage.set_Source (Xamarin.Forms.ImageSource value) [0x00000] in C:\projects\ffimageloading\source\FFImageLoading.Forms\CachedImage.cs:173
at Demo.MainViewModel..ctor () [0x0001f] in <4cd5393447f94973bb9eef7c0de8880d>:0
at FullCameraApp.CameraPage.getLayoutImage (System.Int32 index) [0x00001] in <4cd5393447f94973bb9eef7c0de8880d>:0
at FullCameraApp.CameraPage..ctor (ScoreScan.webServices.WebServices webServices, System.Collections.Generic.List`1[T] imageBytesList) [0x0060b] in <4cd5393447f94973bb9eef7c0de8880d>:0
at ScoreScan.App..ctor
ktrace:
How Can I solve this exception?
Call CachedImageRenderer.Init after global::Xamarin.Forms.Forms.Init(); in FinishedLaunching method present in AppDelegate.cs file of iOS project.
It clearly mention that you need to call Init method inside this. The details will be given in the github repository of FFImageLoading plugin
It is mentioned in the following link

Returning SpreadsheetGear workbook stream from WebMethod

I would like to provide a web service that lets me download certain Excel workbooks. These Excel workbooks are SpreadsheetGear objects that may be modified with data. I don't want to write them as a file and return the file. Instead, I'd like to stream them into the browser so the user gets a downloaded file.
Here is my attempt that does not work, drawn from this guide from SpreadsheetGear's site:
[System.Web.Services.WebMethod(
Description = "Returns a stream for the excel file")]
public ActionResult downloadTemplate(string excelFileName)
{
var workbook = makeSpreadsheetGearWorkbookFrom(excelFileName);
// Save workbook to an Open XML (XLSX) workbook stream.
System.IO.Stream stream = workbook.SaveToStream(
SpreadsheetGear.FileFormat.OpenXMLWorkbook);
// Reset stream's current position back to the beginning.
stream.Seek(0, System.IO.SeekOrigin.Begin);
return new FileStreamResult(stream,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
}
I get the following error:
The web service returned the following result:
500 - Internal Server Error
System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: System.Web.Mvc.FileStreamResult cannot be serialized because it does not have a parameterless constructor.
at System.Xml.Serialization.TypeDesc.CheckSupported () [0x0001c] in <611e64636ff745389933c69c817b2d4a>:0
at System.Xml.Serialization.TypeScope.GetTypeDesc (System.Type type, System.Reflection.MemberInfo source, System.Boolean directReference, System.Boolean throwOnError) [0x0006a] in <611e64636ff745389933c69c817b2d4a>:0
at System.Xml.Serialization.TypeScope.GetTypeDesc (System.Type type) [0x00000] in <611e64636ff745389933c69c817b2d4a>:0
at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException (System.Type type) [0x00039] in <611e64636ff745389933c69c817b2d4a>:0
at System.Xml.Serialization.XmlSerializationWriter.CreateUnknownTypeException (System.Object o) [0x00007] in <611e64636ff745389933c69c817b2d4a>:0
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write3_ActionResult (System.String n, System.String ns, System.Web.Mvc.ActionResult o, System.Boolean isNullable, System.Boolean needType) [0x00048] in <3fa7e61a58e74ec08df7a46ab2fb8972>:0
at Microsoft.Xml.Serialization.GeneratedAssembly.XmlSerializationWriter1.Write7_ActionResult (System.Object o) [0x00028] in <3fa7e61a58e74ec08df7a46ab2fb8972>:0
at Microsoft.Xml.Serialization.GeneratedAssembly.ActionResultSerializer.Serialize (System.Object objectToSerialize, System.Xml.Serialization.XmlSerializationWriter writer) [0x00000] in <3fa7e61a58e74ec08df7a46ab2fb8972>:0
at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter xmlWriter, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces, System.String encodingStyle, System.String id) [0x00098] in <611e64636ff745389933c69c817b2d4a>:0
StackTraceEnd
at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter xmlWriter, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces, System.String encodingStyle, System.String id) [0x0012f] in <611e64636ff745389933c69c817b2d4a>:0
at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter xmlWriter, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces, System.String encodingStyle) [0x00000] in <611e64636ff745389933c69c817b2d4a>:0
at System.Xml.Serialization.XmlSerializer.Serialize (System.Xml.XmlWriter xmlWriter, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces) [0x00000] in <611e64636ff745389933c69c817b2d4a>:0
at System.Xml.Serialization.XmlSerializer.Serialize (System.IO.TextWriter textWriter, System.Object o, System.Xml.Serialization.XmlSerializerNamespaces namespaces) [0x00015] in <611e64636ff745389933c69c817b2d4a>:0
at System.Xml.Serialization.XmlSerializer.Serialize (System.IO.TextWriter textWriter, System.Object o) [0x00000] in <611e64636ff745389933c69c817b2d4a>:0
at System.Web.Services.Protocols.XmlReturnWriter.Write (System.Web.HttpResponse response, System.IO.Stream outputStream, System.Object returnValue) [0x00079] in <11189ae945ae429a8c10c5e8a65a097a>:0
at System.Web.Services.Protocols.HttpServerProtocol.WriteReturns (System.Object[] returnValues, System.IO.Stream outputStream) [0x0003f] in <11189ae945ae429a8c10c5e8a65a097a>:0
at System.Web.Services.Protocols.WebServiceHandler.WriteReturns (System.Object[] returnValues) [0x00051] in <11189ae945ae429a8c10c5e8a65a097a>:0
at System.Web.Services.Protocols.WebServiceHandler.Invoke () [0x000cc] in <11189ae945ae429a8c10c5e8a65a097a>:0
How should I approach this?
Solved the problem by returning a list of bytes instead of a StreamResult, like so:
public byte[] downloadTemplate(string excelFileName)
//...
byte[] modelData = toByteArray(stream);
return modelData;
}
public byte[] toByteArray(System.IO.Stream stream)
{
using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
{
stream.CopyTo(ms);
return ms.ToArray();
}
}
It is easy to put the byte array into a JObject and then into an XML Envelope.

Categories

Resources