Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DaiMangouDev · Jul 18, 2015 at 09:11 PM · c#errorbuildwebplayer

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DaiMangouDev · Jul 23, 2015 at 08:27 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Bunny83 · Jul 22, 2015 at 04:46 AM

@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?

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaiMangouDev · Jul 22, 2015 at 11:41 AM 0
Share

HI thanks a lot for the information . I too had noticed that many of the members under System.IO were in green so i was confused.

I get 2 build errors.

I can send you a example project if that is okay.

the first build error is "ArgumentException: The Assembly System.Drawing is referenced by Name of dll ('path to asset.dll'). But the dll is not allowed to be included or could not be found. UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1 alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2 cache, BuildTarget target) (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/AssemblyHelper.cs:154) UnityEditor.AssemblyHelper.AddReferencedAssembliesRecurse (System.String assemblyPath, System.Collections.Generic.List`1 alreadyFoundAssemblies, System.String[] allAssemblyPaths, System.String[] foldersToSearch, System.Collections.Generic.Dictionary`2 cache, BuildTarget target) (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/AssemblyHelper.cs:160) UnityEditor.AssemblyHelper.FindAssembliesReferencedBy (System.String[] paths, System.String[] foldersToSearch, BuildTarget target) (at C:/buildslave/unity/build/Editor/$$anonymous$$ono/AssemblyHelper.cs:192) UnityEditor.HostView:OnGUI()"

the second build error is "Error building Player: Extracting referenced dlls failed."

from the errors I assumed that I am using some member that is not compatible with eeb player so i checked out the mono compatibility page.

avatar image DaiMangouDev · Jul 22, 2015 at 02:32 PM 0
Share

I have traced the issue back to the monkey.jpg image itself.

avatar image DaiMangouDev · Jul 22, 2015 at 02:49 PM 0
Share

@Bunny83 , I do not fully understand these settings . but when it is set to Embedded Resource and I try to build out the game I get an error .

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

enr.jpg (37.2 kB)
avatar image Bunny83 · Jul 23, 2015 at 04:25 PM 1
Share

In a webbuild you can't use the "System.Drawing" library as it contains code that work directly with files. Assemblies with such code can't be included. Unity has a special mscorlib (which contains most of the System.IO namespace) for each platform. The webplayer version literally doesn't have those "banned classes / methods".

What do you actually use from the "System.Drawing.dll"? Are you sure you need that dll? You should remove references to other assemblies you don't need / use. So check the references list in your DLL project.

Besides that I still don't understand why you embed that image in a .NET assembly? If the assembly is in your project it will get packed into your built project. Why don't you add the image as seperate asset to your Unity project?

avatar image DaiMangouDev · Jul 23, 2015 at 08:18 PM 0
Share

That is just it , I use nothing from System.Drawing in my code.

Oh, the Dll is used by an editor window also , that's why i embed the images.

I removed the System.Drawing Reference and tried to rebuild the dll and got a few errors that seem to points to the problem.

The Resource Designer was using System.Drawing ....

alt text

So I decided to replace Bitmap with Unity's Texture2D

alt text

Thanks for the help. Problem solved.

sdp2.jpg (42.0 kB)
sdp.jpg (140.7 kB)
avatar image
0

Answer by Positive7 · Jul 18, 2015 at 10:55 PM

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaiMangouDev · Jul 21, 2015 at 01:12 PM 0
Share

okay great , can you tell me how i would go about strea$$anonymous$$g data from the dll using WWW , I have been trying but i have made no progress.

avatar image DaiMangouDev · Jul 23, 2015 at 08:29 PM 0
Share

Thanks for the help, It seems that only some members of System.IO cant be run in web

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

24 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Distribute terrain in zones 3 Answers

Builds Crashing with "UnityPlayer.dll caused an Access Violation (0xc0000005)" 2 Answers

How do you save the Audio Mixer once changed? 0 Answers

Multiple Cars not working 1 Answer

System.Net.Mail For Web Player 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges