RazorEngine icon indicating copy to clipboard operation
RazorEngine copied to clipboard

Illegal characters in path during compile

Open jws305 opened this issue 7 years ago • 6 comments

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)

jws305 avatar Mar 23 '17 15:03 jws305

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

ChrisBriggsy avatar Mar 30 '17 04:03 ChrisBriggsy

@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?).

matthid avatar Apr 01 '17 15:04 matthid

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

jws305 avatar Apr 07 '17 16:04 jws305

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 ?

bviale avatar Sep 12 '17 08:09 bviale

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

zidad avatar Sep 19 '17 19:09 zidad

Did anybody find a solution to this issue?

shyamal890 avatar Jan 28 '18 15:01 shyamal890