Page 1 of 1

TypeInitialization Exception with UWP

Posted: Fri Dec 29, 2017 4:14 pm
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

Re: TypeInitialization Exception with UWP

Posted: Sat Dec 30, 2017 3:18 pm
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

Re: TypeInitialization Exception with UWP

Posted: Mon Jan 01, 2018 11:41 am
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.

Re: TypeInitialization Exception with UWP

Posted: Tue Jan 02, 2018 8:11 pm
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

Re: TypeInitialization Exception with UWP

Posted: Wed Jan 03, 2018 6:58 am
by martinou
I PM you a link.

Thank you

Re: TypeInitialization Exception with UWP

Posted: Wed Jan 03, 2018 9:45 am
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

Re: TypeInitialization Exception with UWP

Posted: Thu Jan 04, 2018 10:22 am
by martinou
It works flawlessly now,
thanks a lot !

Re: TypeInitialization Exception with UWP

Posted: Thu Jan 04, 2018 10:25 am
by Joel
Glad to hear it!

All the best,
Joel