MongoDB with custom plugin (Photon Server)

I tried to run MongoDB in my custom plugin, but it gives me following error. Can anybody help me with this?

System.IO.FileLoadException: Could not load file or assembly 'MongoDB.Driver.Legacy' or one of its dependencies. An argument was out of its legal range. (Exception from HRESULT: 0x80131502)
File name: 'MongoDB.Driver.Legacy' ---> System.ArgumentOutOfRangeException: Length cannot be less than zero.
Parameter name: length
at System.String.Substring(Int32 startIndex, Int32 length)
at Photon.Hive.Plugin.PluginManager.OnAssemblyResolve(Object sender, ResolveEventArgs args) in d:\dev\photon-socketserver-sdk_cloud\src-server\Hive\PhotonHive\Plugin\PluginManager.cs:line 424
at System.AppDomain.OnAssemblyResolveEvent(RuntimeAssembly assembly, String assemblyFullName)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.Type.GetType(String typeName)
at MongoDB.Driver.Core.Connections.ClientDocumentHelper.<CreateDriverDocument>g__IsLegacyLoaded|6_0()
at MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateDriverDocument(String driverVersion)
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateClientDocument(String applicationName)
at MongoDB.Driver.Core.Connections.ConnectionInitializer..ctor(String applicationName, IReadOnlyList`1 compressors)
at MongoDB.Driver.Core.Connections.BinaryConnectionFactory..ctor(ConnectionSettings settings, IStreamFactory streamFactory, IEventSubscriber eventSubscriber)
at MongoDB.Driver.Core.Configuration.ClusterBuilder.CreateConnectionPoolFactory()
at MongoDB.Driver.Core.Configuration.ClusterBuilder.CreateServerFactory()
at MongoDB.Driver.Core.Configuration.ClusterBuilder.CreateClusterFactory()
at MongoDB.Driver.ClusterRegistry.CreateCluster(ClusterKey clusterKey)
at MongoDB.Driver.ClusterRegistry.GetOrCreateCluster(ClusterKey clusterKey)
at MongoDB.Driver.MongoClient..ctor(MongoClientSettings settings)
at MyFirstPlugin.MyFirstPlugin.OnCreateGame(ICreateGameCallInfo info) in D:\Photon\Photon-OnPremise-Server-Plugin-SDK_v4-0-29-11263\src-server\Plugins\MyFirstPlugin\MyFirstPlugin.cs:line 23
at Photon.Hive.Plugin.PluginBase.Photon.Hive.Plugin.IGamePlugin.OnCreateGame(ICreateGameCallInfo info) in d:\dev\photon-socketserver-sdk_cloud\src-server\HivePlugin\PluginBase.cs:line 224


UnityEngine.Debug:Log(Object)
Extension:Log(Component, Object) (at Assets/Scripts/Extension.cs:9)
Connection:OnJoinRoomFailed(Int16, String) (at Assets/Scripts/Connection.cs:119)
Photon.Realtime.MatchMakingCallbacksContainer:OnJoinRoomFailed(Int16, String) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:3974)
Photon.Realtime.LoadBalancingClient:CallbackRoomEnterFailed(OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2416)
Photon.Realtime.LoadBalancingClient:OnOperationResponse(OperationResponse) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2553)
ExitGames.Client.Photon.PeerBase:DeserializeMessageAndCallback(StreamBuffer)
ExitGames.Client.Photon.EnetPeer:DispatchIncomingCommands()
ExitGames.Client.Photon.PhotonPeer:DispatchIncomingCommands()
Photon.Pun.PhotonHandler:Dispatch() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:208)
Photon.Pun.PhotonHandler:FixedUpdate() (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:142)

Comments

  • I got the solution.
  • great news
    best,
    ilya
  • I'm facing the same issue now and can't find any relevant solution.

    Could you please share the way you've solved it? 

  • Kashyapdarania
    edited December 2021

    Hi Polina,

    I find the source code file of PluginManager where the error showing.

    I modified that file and create DLL again.

    Especially this one:

    at System.String.Substring(Int32 startIndex, Int32 length)at Photon.Hive.Plugin.PluginManager.OnAssemblyResolve(Object sender, ResolveEventArgs args) in d:\dev\photon-socketserver-sdk_cloud\src-server\Hive\PhotonHive\Plugin\PluginManager.cs:line 424

    I don't remember exactly what I changed but I can share the custom plugin. You just have to put it in the relevant folder in your custom plugin project.

    here is a link: https://drive.google.com/file/d/12JU3URAhM9VxRvthI5DWdSmSyNNuNsTO/view?usp=sharing

    Let me know if this works or not.