TypeInitialization Exception with UWP

Easy Save 2 has been replaced by Easy Save 3, so is no longer supported.
Locked
martinou
Posts: 4
Joined: Fri Dec 29, 2017 2:21 pm

TypeInitialization Exception with UWP

Post by martinou »

Hi,
I had to use the last update from ES2 to get it to work with the last release from Unity.
However it throw an exception on UWP (works fine in Editor and Android) when I use ES2.Save() and no file is created in the persistentDataPath (others plugins manage to write in this path);

Example
ES2.Save("test","savetest.bin?tag=thisIsATest");
TypeInitializationException: The type initializer for 'PDM' threw an exception.

ArgumentException: Path cannot be the empty string or all whitespace.
at System.IO.Directory.CreateDirectory(String path)
at ES2FileStream.CreateStorageStream()
at ES2FileStream.Store()
at ES2.Save[T](T param, String identifier)
at InitialisationScript.$Invoke0(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
(Filename: <Unknown> Line: 0)



Is this a bug or is there a workaround ?
Regards
User avatar
Joel
Moodkie Staff
Posts: 4988
Joined: Wed Nov 07, 2012 10:32 pm

Re: TypeInitialization Exception with UWP

Post by Joel »

Hi there,

We've not seen this error before and don't seem to be able to replicate it at our end.

You seem to have pasted two separate exceptions below, but haven't shown the stack trace for the TypeInitializationException. Would you be able to show the stack trace for this, as this is likely to be the cause of the error.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
martinou
Posts: 4
Joined: Fri Dec 29, 2017 2:21 pm

Re: TypeInitialization Exception with UWP

Post by martinou »

Happy New Year Joel,

I made a test project with an empty scene where I attached this script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test : MonoBehaviour {

	// Use this for initialization
	void Start(){
		ES2.Save("toto","savetest.bin?tag=yuyu");
		Debug.Log("Save completed");
		}
}
I made a build for UWP, using .NET scripting backend and 4.6 API compatibility level.
I can't mangage to get the trace from Unity (Localhost prohibited), but it seems it's due to the fact System.IO.Directory.CreateDirectory doesn't handle an empty path where other builds points to Persistentpath when the path is empty.
I have this trace in Visual Studio
UnloadTime: 14.892981 ms

ArgumentException: Path cannot be the empty string or all whitespace.
at System.IO.Directory.CreateDirectory(String path)
at ES2FileStream.CreateStorageStream()
at ES2FileStream.Store()
at ES2.Save[T](T param, String identifier)
at Test.Start()
at Test.$Invoke0Start(Int64 instance, Int64* args)
at UnityEngine.Internal.$MethodUtility.InvokeMethod(Int64 instance, Int64* args, IntPtr method)
(Filename: <Unknown> Line: 0)


End showing splash screen.
User avatar
Joel
Moodkie Staff
Posts: 4988
Joined: Wed Nov 07, 2012 10:32 pm

Re: TypeInitialization Exception with UWP

Post by Joel »

Hi there, and happy New Year to you too.

In Easy Save 2, data is stored in Isolated Storage rather than in the actual filesystem to maintain backward compatibility. We do this using dedicated code, so Directory.CreateDirectory shouldn't be getting called at all as this should be stripped out by the precomplier. It sounds like the precompiler isn't doing this and is instead using the non-UWP specific code.

Would you be able to PM me a link to a basic project so I can try it at my end, because I don't seem to be getting the same issue?

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
martinou
Posts: 4
Joined: Fri Dec 29, 2017 2:21 pm

Re: TypeInitialization Exception with UWP

Post by martinou »

I PM you a link.

Thank you
User avatar
Joel
Moodkie Staff
Posts: 4988
Joined: Wed Nov 07, 2012 10:32 pm

Re: TypeInitialization Exception with UWP

Post by Joel »

Hi there,

Thanks for your patience. I believe I've managed to find the issue. It seems like one of the recent updates we submitted to the Asset Store didn't go through, so the UWP-specific code is missing on one of the versions.

I've PM'd you a package with the UWP-specific code included, and will see about getting the update resubmitted.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
martinou
Posts: 4
Joined: Fri Dec 29, 2017 2:21 pm

Re: TypeInitialization Exception with UWP

Post by martinou »

It works flawlessly now,
thanks a lot !
User avatar
Joel
Moodkie Staff
Posts: 4988
Joined: Wed Nov 07, 2012 10:32 pm

Re: TypeInitialization Exception with UWP

Post by Joel »

Glad to hear it!

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
Locked