I had a similar problem when compiling strongly typed views failed due to the inability to find the type. One solution is to create a custom assembly provider that inherits from RazorBuildProvider:
public class CustomRazorBuildProvider : RazorBuildProvider { public override void GenerateCode(System.Web.Compilation.AssemblyBuilder assemblyBuilder) { Assembly a = Assembly.LoadFrom([PATH_TO_YOUR_ASSEMBLY]); assemblyBuilder.AddAssemblyReference(a); base.GenerateCode(assemblyBuilder); }
}
Then you need to register this custom assembly provider with web.config:
<compilation debug="true" targetFramework="4.0"> <assemblies> ... </assemblies> <buildProviders> <remove extension=".cshtml" /> <add extension=".cshtml" type="YouAssembly.CustomRazorBuildProvider, YourAssembly"/> </buildProviders> </compilation>
This works, but the bad thing is that assemblies need to be referenced every time the view is compiled.
Here , I posted a question for a nicer solution (for example, it looks like AppDomain.CurrentDomain.AddPrivatePath), where you just specify the private path once, and this will be at the directory level, and not at the assembly level.
source share