UnauthorizedAccessException with XmlSerializer from streamingAssetsPath

I’m using an XmlSerializer to load data from the streamingAssetsPath, instead of the usual BinaryFormatter I’ve used before, because the class structure doesn’t Serialize (due to it containing Vector2’s and Rect’s)

Now I’m getting an UnauthorizedAccessException, meaning my access to the streamingAssetsPath is denied for some reason. Here’s the code I’m using:

public void Load()
	{
		if ( System.String.IsNullOrEmpty( spriteGroup ) )
		{
			Debug.LogError( "No spriteGroup indicated" );
			return;
		}
		
		if ( !File.Exists( Application.streamingAssetsPath + "/PackedSprites/"+spriteGroup+".txt" ) )
		{
			Debug.LogError( "No data found for this spriteGroup.");
			return;
		}
		
		MTextureAnim[] mTexAnimations;
		UVAnimation[] anims;
		
		FileStream stream = new FileStream( Application.streamingAssetsPath + "/PackedSprites/"+spriteGroup+".txt", FileMode.Open);
        try {
			
			XmlSerializer xs = new XmlSerializer( typeof( MTextureAnim[] ) );
			mTexAnimations = (MTextureAnim[])xs.Deserialize( stream );
            
			//BinaryFormatter bformatter = new BinaryFormatter();
            //mTexAnimations = (MTextureAnim[])bformatter.Deserialize(stream);
			
			textureAnimations = new TextureAnim[ mTexAnimations.Length ];
			
			for( int i = 0; i < mTexAnimations.Length; ++i )
			{
				textureAnimations[i] = new TextureAnim(); //maybe this works too?
				textureAnimations[i].Copy( mTexAnimations[i] );
			}
        }
        catch (SerializationException e) {
            Debug.LogError("Exception when loading TextureAnimations: " + e.Message);
        }
        finally {
            stream.Close();
        }
		
		//Animations
		stream = new FileStream( Application.streamingAssetsPath + "/PackedSprites/"+spriteGroup+"Animations.txt", FileMode.Open);
        try {
			
			XmlSerializer xs = new XmlSerializer( typeof( UVAnimation[] ) );
			anims = (UVAnimation[])xs.Deserialize( stream );
            
			//BinaryFormatter bformatter = new BinaryFormatter();
            //mTexAnimations = (MTextureAnim[])bformatter.Deserialize(stream);
			
			animations = new UVAnimation[ anims.Length ];
			
			for( int i = 0; i < animations.Length; ++i )
			{
				animations[i] = anims[i];
			}
        }
        catch (SerializationException e) {
            Debug.LogError("Exception when loading TextureAnimations: " + e.Message);
        }
        finally {
            stream.Close();
        }
		
		//clear these for deletion
		anims = null;
		mTexAnimations = null;
		
		loadedFromFile = true;
	}

I’m getting the following error in xCode: System.UnauthorizedAccessException: Access to the path "/var/mobile/Applications/5A980D49-F0D8-41D8-8CF2-925A311047D1/....app/Data/Raw/PackedSprites/BaseProps.txt" is denied.

Now, as far as I know that folder should not be restricted, so why am I getting this error when using the XmlSerializer?

I’ve turned it into a Resources.Load into a TextAsset, to MemoryStream, to XmlReader solution on-device, and stuck with the current implementation for the editor. Seems to work fine now. Just have to keep it all in the Resources folder, but that’s an option for me so no problem.

Still wondering why the error even occurred though…