0
votes

I am attempting to implement this workaround for a problem where RazorEngine is not deployable in a Razor 2.0 application since it relies on the incompatible Razor 1.0.

What I have done is created two directories in the bin folder: 1.0 and 2.0 and placed the respective System.Web.Razor.dll files into each. I then added dependentAssembly/codeBase hints to web.config to point the assembly loader in the right direction.

However, I cannot seem to get Asp.net to honor the codeBase overrides I have applied for the System.Web.Razor assembly. The result is that System.Web.Razor 1.0.0.0 cannot be loaded for use by RazorEngine.

Web.config

<configuration>
    <runtime xmlns="">
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
                <codeBase version="1.0.0.0" href="file://c:\apps\lr2\web\arcs\bin\1.0\System.Web.Razor.dll" />
                <codeBase version="2.0.0.0" href="file://c:\apps\lr2\web\arcs\bin\2.0\System.Web.Razor.dll" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
</configuration>

Output from Fusion assembly loading log for System.Web.Razor 1.0.0.0:

LOG: User = NT AUTHORITY\SYSTEM LOG: DisplayName = System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 (Fully-specified)

LOG: Appbase = file:///C:/apps/lr2/web/arcs/

LOG: Initial PrivatePath = C:\apps\lr2\web\arcs\bin

LOG: Dynamic Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a63cc915

LOG: Cache Base = C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\a63cc915

LOG: AppName = 98966cc9

Calling assembly : RazorEngine, Version=3.0.8.0, Culture=neutral, PublicKeyToken=9ee697374c7e744a.

LOG: This bind starts in default load context.

LOG: Using application configuration file: C:\apps\lr2\web\arcs\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: Post-policy reference: System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35

LOG: GAC Lookup was unsuccessful.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/a63cc915/98966cc9/System.Web.Razor.DLL.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/a63cc915/98966cc9/System.Web.Razor/System.Web.Razor.DLL.
LOG: Attempting download of new URL file:///C:/apps/lr2/web/arcs/bin/System.Web.Razor.DLL.

LOG: Attempting download of new URL file:///C:/apps/lr2/web/arcs/bin/System.Web.Razor/System.Web.Razor.DLL.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/a63cc915/98966cc9/System.Web.Razor.EXE.

LOG: Attempting download of new URL file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/Temporary ASP.NET Files/root/a63cc915/98966cc9/System.Web.Razor/System.Web.Razor.EXE.

LOG: Attempting download of new URL file:///C:/apps/lr2/web/arcs/bin/System.Web.Razor.EXE.

LOG: Attempting download of new URL file:///C:/apps/lr2/web/arcs/bin/System.Web.Razor/System.Web.Razor.EXE.

LOG: All probing URLs attempted and failed.

Any idea why Asp.net never attempts to dig down into bin\1.0?

I did check machine.config and there is no sign of a conflicting assemblyBinding.

Appreciate the help!

1

1 Answers

-1
votes

I solved this like a champ by using the AppDomain.CurrentDomain.AssemblyResolve event instead.

    System.AppDomain.CurrentDomain.AssemblyResolve += (o, e) =>
    {
        if (e.Name == "System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35")
            return System.Reflection.Assembly.LoadFrom(Server.MapPath("~/bin/1.0/System.Web.Razor.dll"));

        return null;
    };