7
Vote

An assembly with the same simple name has already been imported

description

I've started getting this in my web application that makes use of RazorEngine. It started after an update in which I copied in some new DLLs. It's not always the same DLL it's failing on - sometimes it's one of my library DLLs and sometimes it's the web app's DLL. There are not multiple copies of the DLLs. The template has previously been parsed and compiled (prior to the app restart from updating the /bin folder). Do the cached copies of the compiled templates get persisted somewhere that would cause problems when an app restart occurs?
 
Error Parsing Template: RazorEngine.Templating.TemplateCompilationException: Unable to compile template. An assembly with the same simple name 'MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null has already been imported. Try removing one of the references or sign them to enable side-by-side. Other compilation errors may have occurred. Check the Errors property for more information. at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) in C:\Dev\RazorEngine\src\Core\RazorEngine.Core\Compilation\DirectCompilerServiceBase.cs:line 106 at RazorEngine.Templating.TemplateService.CreateTemplateType(String razorTemplate, Type modelType) in C:\Dev\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 287 at RazorEngine.Templating.TemplateService.GetTemplate[T](String razorTemplate, T model, String name) in C:\Dev\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 459 at RazorEngine.Templating.TemplateService.Parse[T](String razorTemplate, T model, String name) in C:\Dev\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 628

comments

ssmith wrote Nov 9, 2011 at 1:06 PM

Still getting this error a week later...

ssmith wrote Nov 9, 2011 at 1:17 PM

Here's the latest stacktrace - somehow the template is trying to import every file in my /bin folder, it looks like, in alphabetical order:
System.ApplicationException: Error Parsing Template: RazorEngine.Templating.TemplateCompilationException: Unable to compile template. An assembly with the same identity 'AutoMapper, Version=1.1.0.188, Culture=neutral, PublicKeyToken=be96cd2c38ef1005' has already been imported. Try removing one of the duplicate references. Other compilation errors may have occurred. Check the Errors property for more information. at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context) in C:\Dev\RazorEngine\src\Core\RazorEngine.Core\Compilation\DirectCompilerServiceBase.cs:line 106 at RazorEngine.Templating.TemplateService.CreateTemplateType(String razorTemplate, Type modelType) in C:\Dev\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 287 at RazorEngine.Templating.TemplateService.GetTemplate[T](String razorTemplate, T model, String name) in C:\Dev\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 459 at RazorEngine.Templating.TemplateService.Parse[T](String razorTemplate, T model, String name) in C:\Dev\RazorEngine\src\Core\RazorEngine.Core\Templating\TemplateService.cs:line 628 at MailQueue.Infrastructure.Impl.RazorTemplateParser.Parse[T](String template, T model, String name) in C:\Dev_Work_Mailer\apps.LakeQuincy.com\src\Infrastructure\Impl\RazorTemplateParser.cs:line 28
error CS1703: An assembly with the same identity 'AutoMapper, Version=1.1.0.188, Culture=neutral, PublicKeyToken=be96cd2c38ef1005' has already been imported. Try removing one of the duplicate references.
error CS1703: An assembly with the same identity 'Argotic.Extensions, Version=2008.0.2.0, Culture=neutral, PublicKeyToken=84b2ce808fb02469' has already been imported. Try removing one of the duplicate references.
error CS1703: An assembly with the same identity 'Argotic.Common, Version=2008.0.2.0, Culture=neutral, PublicKeyToken=84b2ce808fb02469' has already been imported. Try removing one of the duplicate references.

AntarisZX wrote Nov 10, 2011 at 12:55 PM

You're still getting this error a week later because I haven't look at it yet.

v3 is nearing beta stage, and will be hopefully pushed out later this week, but we're no longer pushing changes to CodePlex, they are being pushed to Github (https://github.com/Antaris/RazorEngine)

ssmith wrote Nov 10, 2011 at 2:11 PM

Sorry, didn't mean to sound demanding, was just noting that it was still an issue. I got the latest from GitHub yesterday, built locally, fixed a couple of minor API changes that affected my code, and redeployed. The issue did not recur. I don't know that it's totally gone, but at least for now it's not impacting me. Glad to hear v3 is coming soon!

AntarisZX wrote Nov 11, 2011 at 3:28 PM

This issue should be resolved with v3. We're performing a .Distinct() on the assembly references before compiling the template. References are aggregated two ways:
  1. We get all the assemblies in the current AppDomain that aren't dynamic.
  2. A CompilerService can provide a separate set of assemblies that must be referenced (e.g. the CSharpDirectCompilerService references the Microsoft.CSharp lib for dynamic support).
We combine these and compare using Upper case to ensure that no duplicate assemblies are loaded.

wlf84k wrote Jan 17, 2012 at 10:50 AM

What is the status of this issue? I keep getting this error too.

wlf84k wrote Jan 17, 2012 at 10:52 AM

P.S.: I use v3.0.7

mickdelaney wrote Feb 21, 2012 at 2:55 PM

using v3.0.7 still getting error.... this time its when running in a resharper unit test session.. its trying to load the same nunit framework dll more than once.

WStealth wrote Apr 6, 2012 at 12:39 PM

I have this error as well :(

eon123 wrote Jul 15, 2013 at 9:48 PM

Is this resolved? I am having the same issue.