Issue with the Photon App Domain loading Dlls

I upgraded my nuget packages today and now when I try to run my photon application it is unable to load the correct version of the Microsoft.Extensions.Configuration.Abstractions. It tries to appear to load version 1.0.2.0 but we are on version 2.1.2.0. The dll is present in the dll and is the correct version(2.1.20) but I dont understand why Photon App Domain is not using the binding redirect like another .net framework application. The dll that hosts the ApplicationBase class is MGF.Photon.dll

Error message:
Exception:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=1.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.Extensions.Configuration.Abstractions, Version=1.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at MGF_Photon.PhotonApplication.Setup()
at Photon.SocketServer.ApplicationBase.PhotonHostRuntimeInterfaces.IPhotonControl.OnPhotonRunning()
at PhotonHostRuntime.PhotonDomainManager.PhotonPlainAppDomainBehavior.PhotonRunning()
at PhotonHostRuntime.PhotonDomainManager.PhotonRunning()

the binding redirect in the app.config file and in the MGF.Photon.dll.config




Comments

  • Hi, @mjoye
    it is difficult to say something without seeing your code. so, please provide a snippet from your config.

    Also what version of photon are you using? what .net it uses? what .net version is supported by the new lib?

    best,
    ilya
  • mjoyemjoye
    edited December 2018
    MGF.Photon.dll is using the .net framework 4.6.1
    Photon server v4.0.29.11263
    Microsoft.Extensions.Configuration.Abstractions.dll is a net standard 2.0 lib so it supports all .net frameworks from 4.6.1 and below.
    here is the link to the confing file
  • Hi @mjoye,

    Sometimes we get reports with mentions to "MGF".
    Where do you get that custom framework built on top of Photon?
  • @JohnTube
    We made it our self with a bit of help with Christian Richards. We have heavily modified his framework to meet our need. It is a framework hides away the socket server details so if we switch away from Photon we dont need to rewrite the whole application. However, this is not an issue with framework or anything since we are not even getting into the main assembly of the application, and photon having issues loading the related assembly. This is only a photon issue because when I try loading the MGF.Photon.dll in a console application using the Assembly.LoadFile method, the CLR is able to find and load the correct versions of the ref assembly. I do see that Photon is doing some custom assembly resolving and more custom CLR related classes. It appears that Photon is not respecting binding redirect
  • Hi, @mjoye

    >Microsoft.Extensions.Configuration.Abstractions.dll is a net standard 2.0 lib so it supports all .net frameworks from 4.6.1 and below.

    Here is the place where as I think you are wrong. netstandard 2.0 is not supported by .net framework 4.0 which is used by photon. so, libraries that depened on API from netstandard 2.0 can not be loaded by photon.

    So, it is not photon issue at all. Just use correct versions of your dependencies

    best,
    Ilya
  • @chvetsov
    so i have a working example of another server that uses the .net framework 4.61 and standard 2.0. If you answer was correct, I would not be able to create a working solution using those two frameworks. So either I did something magically with the test solution or your statement is wrong.


    Here is the git repo for the working solution
  • @chvetsov
    Sorry the example that does work using .net framework 4.61 and standard 1.6, and load correctly however we downgraded our game servers code to .net framework 4.61 and standard 1.6 and we are still getting the error loading the Microsoft.Extensions.Configuration.Abstractions assembly, which seem to be causing when we try to load the Autofac library; however, if we load the assembly manually using the Assembly.Load api, then the error does not happen. This point to an issue with the AppDomain not using the common method for loading assemble into the CLR that a normall CLR application does. This is also supported by the fact that in the logs, just right after the log message about the System.IO.FileNotFoundException is print, there is a bunch of log statements related to trying to download the file from different locations. It looks like AppDomain is able the file "Microsoft.Extensions.Configuration.Abstractions.dll"; however, the version are different(there is a message about minor version are mismatch). I check the configs files for the correct bindingRedirect and the config files point version in the bin file(v 2.1.1.0) to be used for version 0.0.0.0-2.1.1.0

    Exception:
    System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' or one of its dependencies. The system cannot find the file specified.
    File name: 'Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
    at MGF_Photon.PhotonApplication.Setup()
    at Photon.SocketServer.ApplicationBase.PhotonHostRuntimeInterfaces.IPhotonControl.OnPhotonRunning()
    at PhotonHostRuntime.PhotonDomainManager.PhotonPlainAppDomainBehavior.PhotonRunning()
    at PhotonHostRuntime.PhotonDomainManager.PhotonRunning()

    === Pre-bind state information ===
    LOG: DisplayName = Microsoft.Extensions.Configuration.Abstractions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
    (Fully-specified)
    LOG: Appbase = file:///C:/photonserversdk/Photon-OnPremise-Server-SDK_v4-0-29-11263/deploy/bin_Win64
    LOG: DEVPATH = C:\ProgramData\Red Gate\.NET Reflector\DevPath
    LOG: Initial PrivatePath = E:\Code\IS\InnerSanctum\deploy\bin;deploy\Shared;
    Calling assembly : Autofac.Configuration, Version=4.0.1.0, Culture=neutral, PublicKeyToken=17863af14b0044da.
    ===
    LOG: This bind starts in LoadFrom load context.
    WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
    LOG: Using application configuration file: E:\Code\IS\InnerSanctum\deploy\bin\MGF.Photon.dll.config
    LOG: Using host configuration file:
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config.
    LOG: Redirect found in application configuration file: 1.0.0.0 redirected to 2.1.2.0.
    LOG: Post-policy reference: Microsoft.Extensions.Configuration.Abstractions, Version=2.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60
    LOG: Attempting download of new URL file:///C:/photonserversdk/Photon-OnPremise-Server-SDK_v4-0-29-11263/deploy/bin_Win64/Microsoft.Extensions.Configuration.Abstractions.DLL.
    LOG: Attempting download of new URL file:///C:/photonserversdk/Photon-OnPremise-Server-SDK_v4-0-29-11263/deploy/bin_Win64/Microsoft.Extensions.Configuration.Abstractions/Microsoft.Extensions.Configuration.Abstractions.DLL.
    LOG: Attempting download of new URL file:///C:/photonserversdk/Photon-OnPremise-Server-SDK_v4-0-29-11263/deploy/bin_Win64/deploy/Shared/Microsoft.Extensions.Configuration.Abstractions.DLL.
    LOG: Attempting download of new URL file:///C:/photonserversdk/Photon-OnPremise-Server-SDK_v4-0-29-11263/deploy/bin_Win64/deploy/Shared/Microsoft.Extensions.Configuration.Abstractions/Microsoft.Extensions.Configuration.Abstractions.DLL.
    LOG: Attempting download of new URL file:///C:/photonserversdk/Photon-OnPremise-Server-SDK_v4-0-29-11263/deploy/bin_Win64/Microsoft.Extensions.Configuration.Abstractions.EXE.
    LOG: Attempting download of new URL file:///C:/photonserversdk/Photon-OnPremise-Server-SDK_v4-0-29-11263/deploy/bin_Win64/Microsoft.Extensions.Configuration.Abstractions/Microsoft.Extensions.Configuration.Abstractions.EXE.
    LOG: Attempting download of new URL file:///C:/photonserversdk/Photon-OnPremise-Server-SDK_v4-0-29-11263/deploy/bin_Win64/deploy/Shared/Microsoft.Extensions.Configuration.Abstractions.EXE.
    LOG: Attempting download of new URL file:///C:/photonserversdk/Photon-OnPremise-Server-SDK_v4-0-29-11263/deploy/bin_Win64/deploy/Shared/Microsoft.Extensions.Configuration.Abstractions/Microsoft.Extensions.Configuration.Abstractions.EXE.
    LOG: Attempting download of new URL file:///E:/Code/IS/InnerSanctum/deploy/bin/Microsoft.Extensions.Configuration.Abstractions.DLL.
    WRN: Comparing the assembly name resulted in the mismatch: Minor Version
    LOG: Attempting download of new URL file:///E:/Code/IS/InnerSanctum/deploy/bin/Microsoft.Extensions.Configuration.Abstractions/Microsoft.Extensions.Configuration.Abstractions.DLL.
    LOG: Attempting download of new URL file:///E:/Code/IS/InnerSanctum/deploy/bin/Microsoft.Extensions.Configuration.Abstractions.EXE.
    LOG: Attempting download of new URL file:///E:/Code/IS/InnerSanctum/deploy/bin/Microsoft.Extensions.Configuration.Abstractions/Microsoft.Extensions.Configuration.Abstractions.EXE.
  • hi, @mjoye

    Photon uses the LoadFrom method to load assemblies. Because Load does not allow you to load the assembly from a custom path.
    After start current directory is set to deploy folder. And as far as I may see Assembly resolver tries to find your libraries there, plus in some predefined paths like (deploy/bin and deploy/Shared). I think you should use those paths.
    I cannot help you more here. This is not really photon issue

    best,
    ilya
  • @chvetsov

    This is a photon issue, this is not related .Net framework, we have open a ticket with the MS Support and they have conclude that using .net framework 4.61 and standard 1.6 should work with the server, and that we should contact the product team to addition support, because we can get it work with a test solution using .net framework 4.61 and standard 1.6 if this was a .Net Framework issue then it would complete impossible to do(which hint hint is not impossible since i can create a sample solution that work ). The dll is in the deploy\bin(we are running photon in debug mood so we can use the debugger to step into the code). This leans me to believe there is config issue or photon issue.


    Note if i add this code the whole works perfectly all i have to add that method to the AssemblyResolve event on the current domain(Hint hint, if this was a .Net Framework this would work since the CLR would not allow it hint hint)

    private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {


    //This handler is called only when the common language runtime tries to bind to the assembly and fails.

    //Retrieve the list of referenced assemblies in an array of AssemblyName.
    Assembly MyAssembly, objExecutingAssemblies;
    string strTempAssmbPath = "";

    objExecutingAssemblies = Assembly.GetExecutingAssembly();
    AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();

    //Loop through the array of referenced assembly names.
    foreach (AssemblyName strAssmbName in arrReferencedAssmbNames)
    {
    //Check for the assembly names that have raised the "AssemblyResolve" event.
    if (strAssmbName.FullName.Substring(0, strAssmbName.FullName.IndexOf(",")) == args.Name.Substring(0, args.Name.IndexOf(",")))
    {
    //Build the path of the assembly from where it has to be loaded.
    //The following line is probably the only line of code in this method you may need to modify:
    strTempAssmbPath = this.BinaryPath +"\\";
    if (strTempAssmbPath.EndsWith("\\")) strTempAssmbPath += "\\";
    strTempAssmbPath += args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
    break;
    }

    }
    //Load the assembly from the specified path.
    MyAssembly = Assembly.LoadFrom(strTempAssmbPath);

    //Return the loaded assembly.
    return MyAssembly;
    }
  • @chvetsov
    First .Net Framework CLR would complain about loading an dll that is not compactable the current CLR version, and the exception that would would not be a System.IO.FileNotFoundException(the dll cant be found) but it would a System.IO.FileLoadException(the dll can be found however there is exception in loading the dll into the appdomain).
  • HI, @mjoye

    We hardly will update currently released SDK to address this issue. If you managed to resolve it using OnAssemblyResolve event, just use this solution.


    best,
    ilya
Sign In or Register to comment.