Handlebars-Net / Handlebars.Net.Helpers

Handlebars.Net helpers in the categories: 'Boolean', 'Constants', 'Enumerable', 'Environment', 'Math', 'Regex', 'String', 'DateTime' and 'Url'.
MIT License
40 stars 15 forks source link

Error attempting to register helpers #23

Closed mrbelk closed 3 years ago

mrbelk commented 3 years ago

I'm trying to incorporate the helpers into a Xamarin.Forms app, but when I make the call to register the helpers like this:

var compiler = Handlebars.Create();
HandlebarsHelpers.Register(compiler);

I get this error in the application output window:

Error - Error MSG: Error printing test page | Exception: System.UnauthorizedAccessException: Access to the path '/' is denied. ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
  at System.IO.Enumeration.FileSystemEnumerator`1[TResult].CreateDirectoryHandle (System.String path, System.Boolean ignoreNotFound) [0x0002a] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Unix.cs:89 
  at System.IO.Enumeration.FileSystemEnumerator`1[TResult]..ctor (System.String directory, System.IO.EnumerationOptions options) [0x00048] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerator.Unix.cs:49 
  at System.IO.Enumeration.FileSystemEnumerable`1+DelegateEnumerator[TResult]..ctor (System.IO.Enumeration.FileSystemEnumerable`1[TResult] enumerable) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerable.cs:57 
  at System.IO.Enumeration.FileSystemEnumerable`1[TResult]..ctor (System.String directory, System.IO.Enumeration.FileSystemEnumerable`1+FindTransform[TResult] transform, System.IO.EnumerationOptions options) [0x00042] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerable.cs:29 
  at System.IO.Enumeration.FileSystemEnumerableFactory.UserFiles (System.String directory, System.String expression, System.IO.EnumerationOptions options) [0x00014] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/Enumeration/FileSystemEnumerableFactory.cs:90 
  at System.IO.Directory.InternalEnumeratePaths (System.String path, System.String searchPattern, System.IO.SearchTarget searchTarget, System.IO.EnumerationOptions options) [0x0003c] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/Directory.cs:178 
  at System.IO.Directory.GetFiles (System.String path, System.String searchPattern, System.IO.EnumerationOptions enumerationOptions) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/Directory.cs:140 
  at System.IO.Directory.GetFiles (System.String path, System.String searchPattern) [0x00000] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.IO.FileSystem/src/System/IO/Directory.cs:134 
  at HandlebarsDotNet.Helpers.Plugin.PluginLoader+<>c.<Load>b__0_0 (System.String path) [0x00000] in <dc3b1b4f75c84a8bb21766ec28a61ccd>:0 
  at System.Linq.Enumerable+SelectManySingleSelectorIterator`2[TSource,TResult].MoveNext () [0x00051] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/external/corefx/src/System.Linq/src/System/Linq/SelectMany.cs:204 
  at HandlebarsDotNet.Helpers.Plugin.PluginLoader.Load (System.Collections.Generic.IEnumerable`1[T] paths, System.Collections.Generic.IDictionary`2[TKey,TValue] items, System.Object[] args) [0x00064] in <dc3b1b4f75c84a8bb21766ec28a61ccd>:0 
  at HandlebarsDotNet.Helpers.HandlebarsHelpers.Register (HandlebarsDotNet.IHandlebars handlebarsContext, System.Action`1[T] optionsCallback) [0x00102] in <dc3b1b4f75c84a8bb21766ec28a61ccd>:0 
  at HandlebarsDotNet.Helpers.HandlebarsHelpers.Register (HandlebarsDotNet.IHandlebars handlebarsContext, HandlebarsDotNet.Helpers.Enums.Category[] categories) [0x0000d] in <dc3b1b4f75c84a8bb21766ec28a61ccd>:0 
  at goRoamPOD.Services.HandlebarsHelper.ConfigCompiler () [0x00008] in /Users/matthew/Projects/goRoamPOD/goRoamPOD/Services/HandlebarsHelpers.cs:21 
  at goRoamPOD.Services.PrintingHelpers.PrintTestPage () [0x00158] in /Users/matthew/Projects/goRoamPOD/goRoamPOD/Services/PrintingHelpers.cs:539 

I am running on an Android 8 device, and using Xamarin.Android 11.2.2.1, with .Net Core 5.0.201 (and 3.1.407)

Thanks, Matthew

Zulu-Inuoe commented 3 years ago

@mrbelk By default, Handlebars.Net.Helpers will attempt to load "plugins" by loading all dlls in the current directory as assemblies and peeking for types implementing IHelper.. I'd recommend always using

            var h = Handlebars.Create();
            HandlebarsHelpers.Register(h, opt => { opt.CustomHelperPaths = new string[0]; });

or equivalent to prevent this.

mrbelk commented 3 years ago

That did the trick. Thanks.