Runtime AOT compilation errors of WebGL release build

Hello. :slight_smile:

My team is ready to make pre-production build. In our project we use Zenject framework + UniRx. We’ve got dev build and now I’m trying to build WebGL for release. But unfortunately, an application, that made as a release build, throws exception during runtime:

46d1010d-e005-4d4b-8fc5-801f2bc343c0:8 ExecutionEngineException: Attempting to call method ‘Zenject.PlaceholderFactory`3[[Model.UnlockType, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[Model.ILocker, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]::.ctor’ for which no ahead of time (AOT) code was generated.

Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.Reflection.MonoCMethod.InternalInvoke (System.Object obj, System.Object[ ] parameters) [0x00000] in <00000000000000000000000000000000>:0
Rethrow as ZenjectException: Error occurred while instantiating object with type ‘PlaceholderFactory<UnlockType, string, ILocker>’
at Zenject.DiContainer.InstantiateInternal (System.Type concreteType, System.Boolean autoInject, System.Collections.Generic.List`1[T] extraArgs, Zenject.InjectContext context, System.Object concreteIdentifier) [0x00000] in <00000000000000000000000000000000>:0

(Filename: currently not available on il2cpp Line: -1)

I suppose that next line of bind installer causes the exception:

Container.BindIFactory<UnlockType, string, ILocker>().FromFactory<LockerFactory>();

I found that because of WebGL is AOT platform I have to force the compilation of reflected members and types ahead of time as written here:

So I download Bolt package from Asset Store and add Zenject libraries here:

8003174--1028970--upload_2022-3-29_4-49-34.png8003174--1028972--upload_2022-3-29_4-49-55.png

I used pre-build option as it mentioned in manual and got two files: aotScrubs.cs with a lot of commented lines and link.xml.

Now I can’t find docs what I have to do next. I’ve tried to make release build again but nothing has changed.

Please tell me what I’m doing wrong.
Thanks for any help.

For anyone how have same issue.
There is link.xml file in Zenject folder. There can be more then one link.xml for your project. Each Plugin can have it’s own link.xml. In my case I added several placeholder factories in link.xml:

<linker>
  <assembly fullname="Zenject-usage" preserve="all"/>
  <assembly fullname="Zenject" preserve="all">
    <type fullname="Zenject.SceneContextRegistry" preserve="all"/>
    <type fullname="Zenject.ZenjectManagersInstaller" preserve="all"/>
    <type fullname="Zenject.PlaceholderFactory`1" preserve="all"/>
    <type fullname="Zenject.PlaceholderFactory`2" preserve="all"/>
    <type fullname="Zenject.PlaceholderFactory`3" preserve="all"/>
    <type fullname="Zenject.PlaceholderFactory`4" preserve="all"/>
    <type fullname="Zenject.PlaceholderFactory`5" preserve="all"/>
  </assembly>
</linker>