Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 edcx · Feb 09, 2017 at 10:50 AM · androidil2cppruntime-errorlog4net

IL2CPP Android - behaviour could not be instantiated! problem

Hello everyone,

In my android application, I am using log4net.dll for logging and I am using il2cpp scripting backend. However, when I run the application logger does not work and in the android logs I see that

 The script behaviour 'Log4NetConfig' could not be instantiated!
                                         System.Diagnostics.StackTrace:init_frames(Int32, Boolean)
                                         UnityEngine.StackTraceUtility:ExtractStackTrace()
                                         System.Collections.Generic.HashSet`1:GetEnumerator()


I don't know how to debug this. When I use mono it works fine. But it does not work with IL2CPP. log4net.dll is a managed dll.

I appreciate any help.

And this is the script using UnityEngine; using System.Collections;

 using log4net.Layout;
 using log4net.Appender;
 using log4net.Config;
 public class Log4NetConfig : MonoBehaviour
 {
 
     static Log4NetConfig instance;
 
     private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); //
 
     void Awake()
     {
 
         if (instance == null)
         {
             instance = this;
         }
         Log4NetConfig[] instances = GameObject.FindObjectsOfType<Log4NetConfig>();
         if (instances.Length > 1)
         {
             for (int i = 0; i < instances.Length; i++)
             {
                 if (instances[i] != instance)
                     Destroy(instances[i].gameObject);
             }
         }
         DontDestroyOnLoad(this);
 
         ConfigureAllLogging();
 
         
     }
     void OnEnable()
     {
         Application.logMessageReceivedThreaded += instance.OnApplicationLog;
     }
     void OnDisable()
     {
         Application.logMessageReceivedThreaded -= instance.OnApplicationLog;
     }
 
 
 
     void OnApplicationLog(string logString, string stackTrace, LogType type)
     {
         switch (type)
         {
             case LogType.Warning:
                 log.Warn(logString + " --- " + stackTrace);
                 break;
             case LogType.Assert:
                 log.Fatal(logString + " --- " + stackTrace);
                 break;
             case LogType.Error:
             case LogType.Exception:
                 log.Error(logString + " --- " + stackTrace);
                 break;
             case LogType.Log:
                 log.Debug(logString + " --- " + stackTrace);
                 break;
         }
 
     }
 
 
     /// <summary>
     ///  Configure logging to write to Logs\EventLog.txt and the Unity console output.
     /// </summary>
     public static void ConfigureAllLogging()
     {
 
         var patternLayout = new PatternLayout
         {
             ConversionPattern = "%date %-5level %logger - %message%newline"
         };
         patternLayout.ActivateOptions();
 
         // setup the appender that writes to Log\EventLog.txt
         var fileAppender = new RollingFileAppender
         {
             AppendToFile = false,
             
             File = Application.persistentDataPath + "/EventLog.txt",
             Layout = patternLayout,
             MaxSizeRollBackups = 3,
             MaximumFileSize = "10MB",
             RollingStyle = RollingFileAppender.RollingMode.Size,
             StaticLogFileName = true
         };
 
 #if UNITY_EDITOR
         var unityLogger = new UnityAppender
         {
             Layout = new PatternLayout()
         };
         unityLogger.ActivateOptions();
         fileAppender.Threshold = log4net.Core.Level.All;
         fileAppender.ActivateOptions();
         BasicConfigurator.Configure(unityLogger, fileAppender);
 #else
         fileAppender.Threshold = log4net.Core.Level.All;
         fileAppender.ActivateOptions();
         BasicConfigurator.Configure(fileAppender);
 #endif
     }
 }
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
0
Best Answer

Answer by JoshPeterson · Feb 09, 2017 at 12:48 PM

I suspect that some parts of the log4net.dll assembly are being stripped. The IL2CPP build toolchain always does managed code stripping of assemblies, removing managed code from that that is not called at runtime. The Mono build toolchain does not do this by default, so that may account for the difference.

You can indicate to the build toolchain that you want some (or all) of the log4net.dll assembly to be preserved from stripping using a link.xml file. See this page in the manual for details (note that this page mentions iOS, but the same information applies to Android with IL2CPP).

Comment
Add comment · Show 3 · 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 edcx · Feb 09, 2017 at 03:10 PM 0
Share

Well, thank you for your response. Now I am getting named mutex error, so believe that I passed previous the previous error. I found out that it is currently not supported.

Just pasting the error here in case you have an idea. Thanks again for helping out.

 02-09 17:45:53.291 7277-7291/? I/Unity: NotSupportedException: C:\Program Files\Unity\Editor\Data\il2cpp\libil2cpp\icalls\mscorlib\System.Threading\$$anonymous$$utex.cpp(25) : Unsupported internal call for IL2CPP:$$anonymous$$utex::Create$$anonymous$$utex_internal - "Named mutexes are not supported"
                                           at UnityEngineInternal.WebRequestUtils.RedirectTo (System.String baseUri, System.String redirectUri) [0x00000] in <filename unknown>:0 
                                           at UnityEngine.UI.ObjectPool`1[T].Release (.T element) [0x00000] in <filename unknown>:0 
                                           at System.Threading.$$anonymous$$utex..ctor (Boolean initiallyOwned, System.String name) [0x00000] in <filename unknown>:0 
                                           at log4net.Appender.RollingFileAppender.ActivateOptions () [0x00000] in <filename unknown>:0 
                                           at Log4NetConfig.ConfigureAllLogging () [0x00000] in <filename unknown>:0 
                                           at UnityEngine.EventSystems.ExecuteEvents.GetEventHandler[T] (UnityEngine.GameObject root) [0x00000] in <filename unknown>:0 
                                           at System.Collections.Generic.HashSet`1[T].GetEnumerator () [0x00000] in <filename unknown>:0 
                                         System.Diagnostics.StackTrace:init_frames(Int32, Boolean
 
avatar image JoshPeterson edcx · Feb 09, 2017 at 03:23 PM 0
Share

Yes, named mutexes don't work well on many platforms, so IL2CPP does not support them. It looks like this is co$$anonymous$$g from the log4net code though, so I'm not sure what to do. $$anonymous$$aybe there is a log4net code path that does not use named mutexes.

avatar image edcx JoshPeterson · Feb 09, 2017 at 03:27 PM 0
Share

I believe that solved the issue. I found the mutex in the source code and changed it with 'lock() {}' then recompiled the dll. It looks like it's working. Thank you very much =)

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

116 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 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 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 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 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

Unity 5.5 il2cpp android doesn't compile -1 Answers

il2cpp android build error unity 2019.1.6f1 6 Answers

IOS IL2CPP runtime error​ NullReferenceException 1 Answer

android use il2cpp backend,continuous Socket.BeginReceive calls return uncontinuous content。 0 Answers

How to post process Unity-built dll before il2cpp kicks in? 1 Answer


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