Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexOutOfRangeException throw from GetAssemblyFromStringAndCache() #32

Open
kirajhpang opened this issue Nov 12, 2018 · 2 comments
Open

Comments

@kirajhpang
Copy link

Hi, I encounter an error that throw from GetAssemblyFromStringAndCache().

I have setup razorhost in this way.

public class RazorTemplateHelper
    {
        public static RazorStringHostContainer RazorHost { get; set; }

        public static string RenderTemplate(string template, object model/*, out string error*/)
        {
            if (RazorHost == null)
                StartRazorHost(); <-- exception throw from here

            //error = "";
            string result = RazorHost.RenderTemplate(template, model);
            if (result == null)
            {
                Debug.WriteLine(RazorHost.ErrorMessage);
                throw new System.Exception(RazorHost.ErrorMessage);
                //error = RazorHost.ErrorMessage;
            }

            return result;
        }

        public static void StartRazorHost()
        {
            var host = new RazorStringHostContainer()
            {
                //// *** Set your Folder Path here - physical or relative ***
                //TemplatePath = Path.GetFullPath(@".\templates\"),
                //// *** Path to the Assembly path of your application
                //BaseBinaryFolder = Environment.CurrentDirectory
            };

            // Add any assemblies that are referenced in your templates
            host.AddAssemblyFromType(typeof(Microsoft.WindowsAzure.Storage.Table.TableEntity));
           <all assembly>
            host.AddAssemblyFromType(typeof(Softinn.Razor.EmailAppSetting));

            // Always must start the host
            host.Start();

            RazorHost = host;
        }

        public static void StopRazorHost()
        {
            RazorHost?.Stop();
        }
    }
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception while executing function: BookingNotification ---> System.IndexOutOfRangeException : Index was outside the bounds of the array.
   at System.Collections.Generic.Dictionary`2.Insert(TKey key,TValue value,Boolean add)
   at Westwind.RazorHosting.RazorStringHostContainer`1.GetAssemblyFromStringAndCache(String templateText)
   at Westwind.RazorHosting.RazorStringHostContainer`1.RenderTemplate(String templateText,Object model,TextWriter writer,Boolean inferModelType)
   at Softinn.Razor.RazorTemplateHelper.RenderTemplate(String template,Object model) at C:\<path to project>\RazorTemplateHelper.cs : 13
...

What I mess up from this configuration? I seem like Razorhost doesn't load assembly correctly and causing this unexpected error.

@RickStrahl
Copy link
Owner

Not sure what to make of this. If an assembly fails to load you would get a different exception. The error here looks like its failing on the actual add to the dictionary which is odd. Even if the value was null that should work so not sure what's going on there especially given the Index out of Range error.

@kirajhpang
Copy link
Author

kirajhpang commented Jan 8, 2019

@RickStrahl ya, I still can't figure out where is the part possible have IndexOutOfRangeException

Following is the latest exception detail if anyone experiences some error with me under Azure Function, welcome to discuss further.

screenshot 2019-01-08 at 10 43 53 am

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants