Antaris / RazorEngine

Open source templating engine based on Microsoft's Razor parsing engine
http://antaris.github.io/RazorEngine
Other
2.14k stars 577 forks source link

Illegal characters in path during compile #456

Open jws305 opened 7 years ago

jws305 commented 7 years ago

I am encountering a recurring issues where RazorEngine is throwing an ArgumentExceptions during compile. Everything runs fine at first but after the web application runs for a few hours all compilation starts failing. I have the templates set as embedded resources and I am using a EmbeddedResourceTemplateManager. Has anyone encountered this issue before?

=== EXCEPTION TYPE ===
System.ArgumentException
=== MESSAGE ===
Illegal characters in path.
=== STACK TRACE ===
   at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)
   at System.Security.Permissions.FileIOPermission.CheckIllegalCharacters(String[] str)
   at System.Security.Permissions.FileIOPermission.AddPathList(FileIOPermissionAccess access, AccessControlActions control, String[] pathListOrig, Boolean checkForDuplicates, Boolean needFullPath, Boolean copyPathList)
   at System.Security.Permissions.FileIOPermission..ctor(FileIOPermissionAccess access, String path)
   at System.Reflection.RuntimeAssembly.get_Location()
   at RazorEngine.Compilation.ReferenceResolver.UseCurrentAssembliesReferenceResolver.<>c.<GetReferences>b__0_0(Assembly a)
   at System.Linq.Enumerable.WhereArrayIterator`1.MoveNext()
   at System.Linq.Lookup`2.Create[TSource](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.GroupedEnumerable`3.GetEnumerator()
   at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
   at System.Linq.Enumerable.<ConcatIterator>d__58`1.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at RazorEngine.Compilation.CompilerServiceBase.GetAllReferences(TypeContext context)
   at RazorEngine.Compilation.DirectCompilerServiceBase.Compile(TypeContext context)
   at RazorEngine.Compilation.DirectCompilerServiceBase.CompileTypeImpl(TypeContext context)
   at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType_Windows(TypeContext context)
   at RazorEngine.Compilation.DirectCompilerServiceBase.CompileType(TypeContext context)
   at RazorEngine.Templating.RazorEngineCore.CreateTemplateType(ITemplateSource razorTemplate, Type modelType)
   at RazorEngine.Templating.RazorEngineCore.Compile(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.CompileAndCacheInternal(ITemplateKey key, Type modelType)
   at RazorEngine.Templating.RazorEngineService.GetCompiledTemplate(ITemplateKey key, Type modelType, Boolean compileOnCacheMiss)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass15_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
ChrisBriggsy commented 7 years ago

Hi jws305, Did you have any luck solving this issue?

matthid commented 7 years ago

@jws305 You can workaround with your own ReferenceResolver implementation which returns a static set of assemblies... It would be nice if you could further analyze this (for example figure out which assembly it is for which the Location property throws an exception (usually it will return null when there is no location). Which runtime are you using (.NET/ Mono / .NetCore?).

jws305 commented 7 years ago

I hadn't been running in a separate app domain. I am now creating a new app domain for every load which fixed my immediate problem but it now has to recompile every time the page loads.

Digging into the BCL source it seems this exception is only thrown when path == null.

I am using .NET 4.6.1

bviale commented 7 years ago

Hello,

Do you have something new about your bug ? I just came up with the same bug whereas I'm doing the same call to RunCompile. The only difference is that when it works the code is called from my classic asp.net core website, and it fails when it is called from my Azure Functions runtime. The parameters of RunCompile are strictly the same in both cases. Maybe this is due to this special environment ?

zidad commented 6 years ago

@bviale I have the same problem inside an Azure function, did you find any solution to this?

shyamal890 commented 6 years ago

Did anybody find a solution to this issue?