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 BradyIrv · Dec 10, 2020 at 06:01 PM · serializationil2cppstrippinglinker

Issue with IL2CPP where Default Constructor is possibly stripped from assembly

Apologies if this is not the right place to ask about this error. I've been at this for 4-5 days.


Specs: protobuf-net 3.0.73 integrated into a Unity 2019.4.6f1 project that targets .NET Standard 2.0 when building for Xbox console with IL2CPP set to Low Stripping. Exact log: "MissingMthodException: Default constructor not found for type ProtoBuf.Internal.PrimaryTypeProvider"


The project built in Editor works exactly as intended and that's why I think it's the IL2CPP stripping. Error is reported when attempting to assign a new data field of ProtoTest. Might be important to note that the ProtoTest class is a C# Library DLL coded and programmed outside of the Unity environment, as required per ProtoBuf Custom serialization. (To my knowledge). I then built it and ported it into Unity Plugins folder along with the matching Serializer.

 ProtoTest saveFile = new ProtoTest(); // This is the call made where the code will fail

 ----- // Decorated class
 [ProtoContract()]
 public class ProtoTest
 {
     [ProtoMember(1)]
     public string testString;
     [ProtoMember(2)]
     public int testint;
     [ProtoMember(3)]
     public int testBool;
     [ProtoMember(4)]
     public int[] testFixedIntArray;
     [ProtoMember(5)]
     public List<int> testList = new List<int>();
     [ProtoMember(6)]
     public Dictionary<int, string> testDictionary = new Dictionary<int, string>();

     // This is the constructor that is being stripped (to my knowledge)
     public ProtoTest()  { }
 }

I suspect that some off the protobuf files are being stripped during the build, I don't have a lot of experience with handling this. However I attempted to omit the protobuf namespace from stripping by writing a Linker referencing the namespaces used to create all the protobuf data I know of.

Might be important to note that the ProtoTest class is a C# Library DLL coded and programmed outside of the Unity environment, as required per ProtoBuf Custom serialization. (To my knowledge).

Attempt 1

 <linker>
   <assembly fullname="ProtoBuf">
     <namespace fullname="ProtoBuf.Internal.PrimaryTypeProvider" preserve="all"/>
   </assembly>
 </linker>

Attempt 2

 <linker>
   <assembly fullname="ProtoSave" preserve="all"/>
   <assembly fullname="ProtoBuf" preserve="all"/>
   <assembly fullname="ProtoBuf.Internal" preserve="all"/>
   <assembly fullname="ProtoBuf.Meta" preserve="all"/>
 </linker>

Attempt 3

 <linker>
   <namespace fullname="ProtoSave" preserve="all"/>
   <namespace fullname="ProtoBuf" preserve="all"/>
   <namespace fullname="ProtoBuf.Internal" preserve="all"/>
   <namespace fullname="ProtoBuf.Meta" preserve="all"/>
   <namespace fullname="ProtoBuf.Serializers" preserve="all"/>
   <namespace fullname="DataSerializer" preserve="all"/>
 </linker>
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
1

Answer by JoshPeterson · Dec 11, 2020 at 12:05 PM

I would recommend reviewing the documentation about the linker if you have not done so: https://docs.unity3d.com/Manual/ManagedCodeStripping.html.

I think the question is, which assembly does the ProtoTest type live in? Once you know that, you can start by preserving that entire assemly:

 <linker>
     <assembly fullname="ProtoTestAssembly" preserve="all"/>
 </linker>

This is probably not a good long term solution, but it will help isolate the issue. Once you know this, then you can more specific preserve only the types in that assembly that you need.

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 BradyIrv · Dec 11, 2020 at 02:31 PM 0
Share

I will look into this, but that being said the ProtoTest class lives in the ProtoSave assembly. And in my second attempt at the linker, I did include that assembly.

$$anonymous$$issing$$anonymous$$ethodException: Default constructor not found for type ProtoBuf.Internal.PrimaryTypeProvider at System.RuntimeType.CreateInstance$$anonymous$$ono (System.Boolean nonPublic) [0x00000] in :0 at System.Activator.CreateInstance (System.Type type, System.Boolean nonPublic) [0x00000] in :0 at ProtoBuf.Serializers.SerializerCache`1[TProvider]..cctor () [0x00000] in :0 at ProtoBuf.Internal.TypeHelper`1[T]..cctor () [0x00000] in :0 at ProtoBuf.$$anonymous$$eta.Type$$anonymous$$odel.SerializeImpl[T] (ProtoBuf.ProtoWriter+State& state, T value) [0x00000] in :0 at ProtoBuf.$$anonymous$$eta.Type$$anonymous$$odel.Serialize[T] (System.IO.Stream dest, T value, System.Object userState) [0x00000] in :0 at PlatformDeskTop.SaveFileAsProto[T] (CPlatformDataFile _FileData) [0x00000] in :0 at System.EventHandler`1[TEventArgs].Invoke (System.Object sender, TEventArgs e) [0x00000] in :0 at UI$$anonymous$$enuButtonGroup.Update () [0x00000] in :0 Rethrow as TypeInitializationException: The type initializer for 'ProtoBuf.Serializers.SerializerCache' threw an exception. at ProtoBuf.Internal.TypeHelper`1[T]..cctor () [0x00000] in :0 at ProtoBuf.$$anonymous$$eta.Type$$anonymous$$odel.SerializeImpl[T] (ProtoBuf.ProtoWriter+State& state, T value) [0x00000] in :0 at ProtoBuf.$$anonymous$$eta.Type$$anonymous$$odel.Serialize[T] (System.IO.Stream dest, T value, System.Object userState) [0x00000] in :0 at PlatformDeskTop.SaveFileAsProto[T] (CPlatformDataFile _FileData) [0x00000] in :0 at System.EventHandler`1[TEventArgs].Invoke (System.Object sender, TEventArgs e) [0x00000] in :0 at UI$$anonymous$$enuButtonGroup.Update () [0x00000] in :0 Rethrow as TypeInitializationException: The type initializer for 'ProtoBuf.Internal.TypeHelper' threw an exception. at ProtoBuf.$$anonymous$$eta.Type$$anonymous$$odel.SerializeImpl[T] (ProtoBuf.ProtoWriter+State& state, T value) [0x00000] in :0 at ProtoBuf.$$anonymous$$eta.Type$$anonymous$$odel.Serialize[T] (System.IO.Stream dest, T value, System.Object userState) [0x00000] in :0 at PlatformDeskTop.SaveFileAsProto[T] (CPlatformDataFile _FileData) [0x00000] in :0 at System.EventHandler`1[TEventArgs].Invoke (System.Object sender, TEventArgs e) [0x00000] in :0 at UI$$anonymous$$enuButtonGroup.Update () [0x00000] in :0

avatar image JoshPeterson BradyIrv · Dec 11, 2020 at 02:56 PM 0
Share

It looks like this error is for a different type now: ProtoBuf.Internal.PrimaryTypeProvider

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

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

Linker error - Unity on iOS/React Native project 1 Answer

DataContract serialization with IL2CPP 1 Answer

Cloud Build warning: Can't find custom attr constructor image 2 Answers

No Line numbers in stack trace for debug android build using IL2CPP 1 Answer

Did logic for selecting assemblies for UnusedByteCodeStripper2 and il2cpp change? 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