adoconnection / RazorEngineCore

.NET6 Razor Template Engine
MIT License
565 stars 84 forks source link

A break mode occurs in Maui .net android app. It works fine in Win UI #129

Open upswing1 opened 1 year ago

upswing1 commented 1 year ago

When running this code var engine = new RazorEngineCore.RazorEngine(); I get the following error in Android emulator:
Your app has entered a break state, but there is no code to show because all threads were executing external code

This happens under .net MAUI for an android app. It works fine for WINUI

Call stack 0x29 in System.Reflection.ConstructorInvoker.InterpretedInvoke C# 0x4 in System.Reflection.ConstructorInvoker.InlinedInvoke C# 0xBD in System.RuntimeType.CreateInstanceMono C# 0x1F in System.RuntimeType.CreateInstanceDefaultCtor C# 0x30 in System.Activator.CreateInstance C# 0x3 in System.Activator.CreateInstance C# 0x2 in System.Activator.CreateInstance C# 0x48 in Microsoft.Maui.Controls.ShellContent. at D:\a_work\1\s\src\Controls\src\Core\Shell\ShellContent.cs:75,8 C# 0x27 in Microsoft.Maui.Controls.ElementTemplate.CreateContent at D:\a_work\1\s\src\Controls\src\Core\ElementTemplate.cs:85,4 C# 0x8 in Microsoft.Maui.Controls.Internals.DataTemplateExtensions.CreateContent at D:\a_work\1\s\src\Controls\src\Core\DataTemplateExtensions.cs:22,4 C# 0x77 in Microsoft.Maui.Controls.ShellContent.Microsoft.Maui.Controls.IShellContentController.GetOrCreateContent at D:\a_work\1\s\src\Controls\src\Core\Shell\ShellContent.cs:80,5 C# 0x16E in Microsoft.Maui.Controls.Platform.Compatibility.ShellSectionRenderer.OnCreateView at D:\a_work\1\s\src\Controls\src\Core\Compatibility\Handlers\Shell\Android\ShellSectionRenderer.cs:123,5 C# 0x24 in AndroidX.Fragment.App.Fragment.n_OnCreateView_Landroid_view_LayoutInflater_Landroid_view_ViewGroup_Landroid_osBundle at /Users/runner/work/1/s/generated/androidx.fragment.fragment/obj/Release/net6.0-android/generated/src/AndroidX.Fragment.App.Fragment.cs:2031,4 C# 0xD in Android.Runtime.JNINativeWrapper.Wrap_JniMarshal_PPLLL_L at /Users/runner/work/1/s/xamarin-android/src/Mono.Android/Android.Runtime/JNINativeWrapper.g.cs:352,5 C#

I get the following error in actual device

       var engine = new RazorEngineCore.RazorEngine();

        try
        {
            var compiledTemplate = engine.Compile(template);  <==== Exception

            var result = compiledTemplate.Run(model);

            return result;
        }
        catch(Exception ex) 
        { 
            string s = ex.Message;
            return s;
        }

Exception The method or operation is not implemented. at System.Reflection.Metadata.AssemblyExtensions.TryGetRawMetadata(Assembly assembly, Byte*& blob, Int32& length) at RazorEngineCore.RazorEngine.<>c.b__4_1(Assembly ass) at System.Linq.Enumerable.SelectEnumerableIterator2[[System.Reflection.Assembly, System.Private.CoreLib, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e],[Microsoft.CodeAnalysis.PortableExecutableReference, Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].MoveNext() at System.Linq.Enumerable.ConcatIterator1[[Microsoft.CodeAnalysis.MetadataReference, Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]].MoveNext() at System.Collections.Generic.List1[[Microsoft.CodeAnalysis.MetadataReference, Microsoft.CodeAnalysis, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]..ctor(IEnumerable1 collection) at System.Linq.Enumerable.ToList[MetadataReference](IEnumerable1 source) at RazorEngineCore.RazorEngine.CreateAndCompileToStream(String templateSource, RazorEngineCompilationOptions options) at RazorEngineCore.RazorEngine.Compile(String content, Action1 builderAction) at ReportsComponents.Reports.ReportGenerator.GenerateReport(String template, Object model) in D:\repos\FeatureReports\FeatureReportsComponents\Reports\ReportGenerator.cs:line 13

template is

<html>
<body>
    <h1>Report for @Model.UserName</h1>
`
    <p>Account Balance: @Model.AccountBalance</p>

    <table>
        <thead>
            <tr>
                <th>Transaction Date</th>
                <th>Description</th>
                <th>Amount</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var transaction in Model.Transactions)
            {
                <tr>
                    <td>@transaction.TransactionDate.ToShortDateString()</td>
                    <td>@transaction.Description</td>
                    <td>@string.Format("{0:C}", transaction.Amount)</td>
                </tr>
            }
        </tbody>
    </table>
</body>
</html>

`