What is an alternative to using System.IO Stream when building for webplayer ?

I am streaming data from in my Resources folder in my DLL.

Web Player does not handle System.IO do what is an alternative to System IO Stream ?

In this script I get an image resource from a dll.

It uses Stream, which seems to not be handles by web player ?? MonoCompatability

public static Texture2D Load(string resourceName)
{
    // first try to load as local resource, in case not running dll version
    // also lets you override dll resources locally for rapid iteration
 
    Texture2D texture = (Texture2D)Resources.Load(resourceName);
    if (texture != null)
    {
        Debug.Log("Loaded local resource: " + resourceName);
        return texture;
    }
 
    // if unavailable, try assembly
 
    Assembly myAssembly = Assembly.GetExecutingAssembly();
    Stream myStream = myAssembly.GetManifestResourceStream(myAssembly.GetName().Name + ".Resources." + "monkey.jpg");
    texture = new Texture2D(10, 10, TextureFormat.ARGB32, false);
    texture.LoadImage(ReadToEnd(myStream));
 
    if (texture == null)
    {
        Debug.LogError("Missing Dll resource: " + resourceName);
    }
 
    return texture;
}

I would then pipe myStream into a Stream

static byte[] ReadToEnd(Stream stream)
        {
            long originalPosition = stream.Position;
            stream.Position = 0;

            try
            {
                byte[] readBuffer = new byte[4096];

                int totalBytesRead = 0;
                int bytesRead;

                while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0)
                {
                    totalBytesRead += bytesRead;

                    if (totalBytesRead == readBuffer.Length)
                    {
                        int nextByte = stream.ReadByte();
                        if (nextByte != -1)
                        {
                            byte[] temp = new byte[readBuffer.Length * 2];
                            Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length);
                            Buffer.SetByte(temp, totalBytesRead, (byte)nextByte);
                            readBuffer = temp;
                            totalBytesRead++;
                        }
                    }
                }

                byte[] buffer = readBuffer;
                if (readBuffer.Length != totalBytesRead)
                {
                    buffer = new byte[totalBytesRead];
                    Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead);
                }
                return buffer;
            }
            finally
            {
                stream.Position = originalPosition;
            }
        }

UPDATE TO PROBLEM

I removed to script from the dll , left the monkey.jpg image in the dll as an embedded resource and then made sure to include a dummy class in the dll which i call in a mono script which is placed on a gameobject so that that the dll gets built too when i build the game . then i realised that it was not the scrpt that was the problem but the image …or its setting. I am not sure what to do here

monkey.jpg

@DMDev:
In a webbuild you can’t access the packed assemblies of your game manually. Those are loaded by the webplayer and your scripts don’t have any access to those files in memory. Even when you placed the dlls additionally next to your webbuild so you can load the dll file from your webspace, you still need a way to access the resource data in that dll.

It would make much more sense to place your images directly in your project and just use them. As alternative you can host your images on your webspace and load them with the WWW class.

Btw: The System.IO namespace works fine in a webbuild. You just can’t use any function that works with files. Simply anything that could potentially be a security problem is not allowed. Memory streams, stream readers / writers work just fine in a webbuild.

According to the Mono compatibility page “GetManifestResourceStream” should work in a webbuild as well. Do you get any compilation errors? If so which ones? Do you get any errors at runtime? Have you checked the logfile? Any runtime errors when you use your code? If so, which ones?

Use WWW. System.IO is disabled on webplayer for good.

The problem was not in the script , but in the Resource Designer script of the Project where the DLL is built.

When building for web and you are using a managed dll, not native; with your own embedded image resources . Webplayer does not support System.Drawing. So open the ‘Resource Designer’ script and ensure that any reference to System.Drawing is removed.

as shown in these pictures

alt text

replace Bitmap with Unity’s Texture2D

alt text