代码之家  ›  专栏  ›  技术社区  ›  John K

Kentico 10是否使用了与以前版本不同的程序集加载/探测/处理策略?

  •  1
  • John K  · 技术社区  · 8 年前

    http://www.html-to-pdf.net 该产品具有受管理的EphTMLTOPPDF。依赖非托管“helper”dll的dll程序集 epengine.dll 也在web应用程序的垃圾箱/文件夹中,有时在应用程序启动时会引发异常。。。

    在Kentico 9(和早期版本)下 引发异常并

    根据Kentico 10 an epengine发动机 发生异常,并且


    这是

    Event type: Error
    Event time: 7/18/2017 4:00:06 AM
    Source: Discovery
    Event code: E:\Kentico_V9\CMS\bin\epengine.dll
    User ID: 65
    User name: public
    Description: Could not load file or assembly 'epengine.dll' or one of its dependencies. The module was expected to contain an assembly manifest.
    The file E:\Kentico_V9\CMS\bin\epengine.dll is not an assembly or the assembly was compiled for a later version of the .NET runtime.
    Machine name: OX
    Event URL: /register/all
    URL referrer: /Public-(1)/Search-Results
    User agent: Mozilla/5.0 (Windows NT 6.1; Trident/7.0; BOIE9;ENUS; rv:11.0) like Gecko
    

    根据Kentico 10,这是 阻止站点运行的错误。

    *** Assembly Binder Log Entry  (17/07/2017 @ 4:36:56 PM) ***
    
    The operation failed.
    Bind result: hr = 0x80131018. No description available.
    
    Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
    Running under executable  C:\Windows\SysWOW64\inetsrv\w3wp.exe
    --- A detailed error log follows. 
    
    === Pre-bind state information ===
    LOG: DisplayName = epengine
     (Partial)
    WRN: Partial binding information was supplied for an assembly:
    WRN: Assembly Name: epengine | Domain ID: 2
    WRN: A partial bind occurs when only part of the assembly display name is provided.
    WRN: This might result in the binder loading an incorrect assembly.
    WRN: It is recommended to provide a fully specified textual identity for the assembly,
    WRN: that consists of the simple name, version, culture, and public key token.
    WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
    LOG: Appbase = file:///C:/inetpub/wwwroot/website/CMS/
    LOG: Initial PrivatePath = C:\inetpub\wwwroot\website\CMS\bin
    LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\672d45d4
    LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\672d45d4
    LOG: AppName = f7cc5d08
    Calling assembly : (Unknown).
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: C:\inetpub\wwwroot\website\CMS\web.config
    LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
    LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/672d45d4/f7cc5d08/epengine.DLL.
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/672d45d4/f7cc5d08/epengine/epengine.DLL.
    LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/website/CMS/bin/epengine.DLL.
    LOG: Assembly download was successful. Attempting setup of file: C:\inetpub\wwwroot\website\CMS\bin\epengine.dll
    LOG: Entering download cache setup phase.
    ERR: Error extracting manifest import from file (hr = 0x80131018).
    ERR: Setup failed with hr = 0x80131018.
    ERR: Failed to complete setup of assembly (hr = 0x80131018). Probing terminated.
    
    *** Assembly Binder Log Entry  (17/07/2017 @ 4:36:56 PM) ***
    
    The operation failed.
    Bind result: hr = 0x80131018. No description available.
    
    Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
    Running under executable  C:\Windows\SysWOW64\inetsrv\w3wp.exe
    --- A detailed error log follows. 
    
    === Pre-bind state information ===
    LOG: DisplayName = epengine
     (Partial)
    WRN: Partial binding information was supplied for an assembly:
    WRN: Assembly Name: epengine | Domain ID: 2
    WRN: A partial bind occurs when only part of the assembly display name is provided.
    WRN: This might result in the binder loading an incorrect assembly.
    WRN: It is recommended to provide a fully specified textual identity for the assembly,
    WRN: that consists of the simple name, version, culture, and public key token.
    WRN: See whitepaper http://go.microsoft.com/fwlink/?LinkId=109270 for more information and common solutions to this issue.
    LOG: Appbase = file:///C:/inetpub/wwwroot/website/CMS/
    LOG: Initial PrivatePath = C:\inetpub\wwwroot\website\CMS\bin
    LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\672d45d4
    LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\672d45d4
    LOG: AppName = f7cc5d08
    Calling assembly : (Unknown).
    ===
    LOG: This bind starts in default load context.
    LOG: Using application configuration file: C:\inetpub\wwwroot\website\CMS\web.config
    LOG: Using host configuration file: C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet.config
    LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
    LOG: Policy not being applied to reference at this time (private, custom, partial, or location-based assembly bind).
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/672d45d4/f7cc5d08/epengine.DLL.
    LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/672d45d4/f7cc5d08/epengine/epengine.DLL.
    LOG: Attempting download of new URL file:///C:/inetpub/wwwroot/website/CMS/bin/epengine.DLL.
    LOG: Assembly download was successful. Attempting setup of file: C:\inetpub\wwwroot\website\CMS\bin\epengine.dll
    LOG: Entering download cache setup phase.
    ERR: Error extracting manifest import from file (hr = 0x80131018).
    ERR: Setup failed with hr = 0x80131018.
    ERR: Failed to complete setup of assembly (hr = 0x80131018). Probing terminated.
    

    • 改为使用epengine的Nuget源
    • 使用最新版本的epengine组件,也可以尝试旧版本(专家9.0.5-11.0之间)
    • 使用相同的应用程序池设置、.NET版本、ACL权限(并根据测试而更改)
    • Kentico 10的新/基本安装(仍然显示出先前的错误)

    我想知道的是,在程序集加载、探测或异常处理方面是否存在差异,这可能有助于解释为什么该组件的错误会阻止Kentico 10 ASP。NET网站,但不会阻止Kentico 9网站使用相同的IIS加载。NET配置。

    (请注意,我还通过联系供应商直接解决PDF组件错误-最终解决方案将是最佳解决方案)。

    2 回复  |  直到 8 年前
        1
  •  2
  •   Community Mohan Dere    5 年前

    不太理想。该解决方案是解决ephtmltopdf问题的一种变通方法。dll和epengine。dll程序集在web应用程序启动期间从应用程序的bin/文件夹加载时引发错误,导致Kentico 10网站无法加载。

    此解决方案基于 @rocky's

    这有效地导致专家PDF组件在Kentico站点已经运行后加载。

    并非所有PDF生成器的使用都经过测试。这里的代码示例将在直接引用组件不起作用的环境中,使用专家PDF组件成功地将给定URL下载为PDF文档。(它在我的电脑上工作)


    解决方法步骤-

    1. 动态实例化组件(如代码示例所示-请参阅dynamic+CreateInstance)

    // In ~/TestPdf.aspx.cs code-behind page, inside a Kentico 10 website 
    
    namespace CMSApp
    {
        using System;
        //using ExpertPdf.HtmlToPdf; // << Namespace no longer available to C# compiler.
        using System.Reflection;
    
        public partial class test1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
                // var converter = new ExpertPdf.HtmlToPdf.PdfConverter(); // << Type no longer available to C# compiler.
    
                // Dynamically load the Expert PDF Assembly, Type and an instance...
                Assembly assemb = System.Reflection.Assembly.LoadFile(@"C:\KenticoBaseInstalls\Kentico10.2-app\LibMore\ExpertPdf-HtmlToPdf-v11.0.0\Bin\.NET_4.0\ephtmltopdf.dll");
                dynamic converter = assemb.CreateInstance("ExpertPdf.HtmlToPdf.PdfConverter", true);
    
    
                // Continue to use old PDF code but without compiler type checks and VS Editor Intellisense.
    
                byte[] pdfBytes = converter.GetPdfBytesFromUrl("https://www.iana.org/domains/reserved");
                Response.ClearHeaders();
    
                Response.ContentType = "application/octet-stream";
                Response.AppendHeader("Content-Disposition", "attachment; filename=example.pdf");
                Response.BinaryWrite(pdfBytes);
                Response.Flush();
                Response.End();
            }
        }
    }
    

    注意:ExpertPDF程序集中还有其他构造将失败,您必须像上面的示例一样解决,例如:

    • 静态单位转换。像素点(…)
    • HTMLTopFarea类
    • ImageArea类

    解决方案补遗说明

    在上面的代码示例中 System.Reflection.Assembly.LoadFile(..) 在不同环境之间或文件移动时,容易出现位置问题。更可靠的替代方法是使用基于应用程序的子目录来获取程序集,如下所示。请注意,Kentico 10使用了这种策略,我们正在借鉴他们的CMS文件夹结构:

    +---CMSDependencies
        +---ExpertPdfHtmlToPdf.11.0.0
                epengine.dll
                ephtmltopdf.dll
    

    将专家Pdf文件夹的名称添加到web中探测元素的私有路径中。不使用分号替换任何其他值。

      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <probing privatePath="CMSDependencies\Newtonsoft.Json.6.0.0.0;CMSDependencies\ExpertPdfHtmlToPdf.11.0.0"/>
        </assemblyBinding>
      </runtime>
    

    Assembly assemb = System.Reflection.Assembly.Load(new AssemblyName("ephtmltopdf"));
    
        2
  •  0
  •   John K    8 年前

    根据Kentico Support的建议,通过将网站热修复到Kentico 10.0.29(本文撰写时的最高热修复)来解决该问题。

    发件人:Kentico Support
    发送时间:7月25日至17日上午9:46

    主题:回复:专家PDF组件与Kentico 10不兼容,除非动态加载票证:0072002734

    你好,约翰,

    经过调查,有可能 此问题已在Kentico 10 hotfix 10.0.25中修复。 该漏洞与应用程序启动有关,我们的开发人员认为这可能与此有关。

    Could not load file or assembly '\bin\ABCpdf8-64.dll' or one of its dependencies. The module was expected to contain an assembly manifest

    顺致敬意,

    技术支持负责人

    我还通过下载URL并通过编程将其转换为PDF文档,验证了专家PDF组件在热固定基座Kentico 10安装上正常运行。(有关代码示例,请参阅专家PDF网站和文档。)

    因为我们正在将Kentico从8.2升级到10,并使用自定义代码解决多个问题;自定义组件,我在这里留下了最简单的回购场景,它证明了使用专家PDF时的问题,以及解决方案,供任何其他可能在升级或首次安装期间遇到类似问题的人使用。

    1. 使用Kentico 10安装程序创建新的网站应用程序。
    2. 验证该网站是否运行Kentico 10,并且没有修补程序,将报告为10.0.0。
    3. 使用Nuget,参考ExpertPdfHtmlToPdf包(我修补了9.5到11版本)。
    4. 编译并运行该网站-该网站不会加载,而是显示一个带有“epengine”消息的.NET错误,如问题中发布的。

    回购解决方案

    1. 按照Kentico修补程序说明,将最新可用的修补程序应用于Kentico 10安装。
    2. 验证站点现在报告为10.0.x,其中x是应用的修补程序编号。确保它是>=#25如Kentico support所述。
    3. 编译并运行网站-错误消失,网站正常运行。