Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Antti · Jan 09, 2014 at 10:25 AM · mono.net

How to use System.Net with code stripping?

Setting Unity's stripping level to Strip Assemblies or Strip ByteCode from Player Settings -> Optimization causes (at least) some of the System.Net functionality fail.

To test the issue, I created a simple project that only tries to use System.Net.WebRequest.Create():

 using UnityEngine;
 using System.Net;
 
 public class NetworkAccessTest : MonoBehaviour
 {
     void Start()
     {
         bool succeeded = false;
         try
         {
             WebRequest.Create("http://www.google.com"); 
             succeeded = true;
         }
         catch (System.Exception e)
         {
             Debug.Log(string.Format("Exception: {0}", e));
             succeeded = false;
         }
         Debug.Log(string.Format("Web request creation succeeded: {0}", succeeded));
     }
 }
 

It works fine without stripping. But without sripping:


Exception: System.NotSupportedException: http://www.google.com/
  at System.Net.WebRequest.GetCreator (System.String prefix) [0x00000] in :0 
  at System.Net.WebRequest.Create (System.Uri requestUri) [0x00000] in :0 
  at System.Net.WebRequest.Create (System.String requestUriString) [0x00000] in :0 
  at NetworkAccessTest.Start () [0x00000] in :0 

The questions:

  1. Is it possible to use WebRequest and other networking classes from System.Net with code stripping?

  2. And if it's possible, how?

It's possible to list types that shouldn't be stripped: docs.unity3d.com/Documentation/Manual/iphone-playerSizeOptimization.html. Would that solve the issue? How would I conveniently find out which types to list there? I can only think of reading the Mono source code and trying to deduce the missing types that could cause the expections.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Antti · Jan 09, 2014 at 12:20 PM

Adding the following link.xml to Assets direcotry solves my little test case:

 <linker>
     <assembly fullname="System">
         <type fullname="System.Net.HttpRequestCreator" preserve="all"/>        
     </assembly>
 </linker>

I found the needed type by reading Mono sources for System.Net. Finding all necessary types for a large application is a pain in a neck, though, so any ideas on making that easier would be still appreciated.

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 TonyLi · Jan 09, 2014 at 04:53 PM 0
Share

The method here sounds like it would work. I haven't tried it myself, but I plan to later today.

avatar image GrayedFox · Sep 30, 2014 at 07:17 AM 0
Share

Hi @Antti - sorry to bring up an old thread but how did you pinpoint the HttpRequestCreator as the culprit? I've been debugging our own stripping errors - currently stuck on one due to a file stream request over http - and I cannot find the type name (i.e. System.IO.StreamRequestCreator) or something similar. $$anonymous$$SDN is incredibly unhelpful for this endeavour! Your little link.xml did however solve 2 of our problems.

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

19 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

Related Questions

how to reference a .NET 4 targeted, native code wrapper assembly in Unity (beta)? 0 Answers

Is it possible to reference .NET references and give up cross-platform? 1 Answer

Target Platform for .NET DLLs, And Should I Use Linq? 0 Answers

Use .NET native dll calls 1 Answer

Using Microsoft surface 2.0 with Unity 3 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