TypeLoadException in Markdig 0.40.0 #719

Closed
opened 2026-01-29 14:43:50 +00:00 by claunia · 1 comment
Owner

Originally created by @UTF-8x on GitHub (Jan 22, 2025).

I'm trying to use Markdig in an Avalonia app but Markdown.Parse and Markdown.ToHtml throw the following exception:

Unhandled exception. System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.MemoryMarshal' from assembly 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Full stack trace
   at Markdig.Helpers.LineReader.ReadLine()
   at Markdig.Parsers.MarkdownParser.ProcessBlocks(BlockProcessor blockProcessor, String text)
   at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context)
   at Markdig.Markdown.Parse(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context)
   at Markdig.Markdown.Parse(String markdown, Boolean trackTrivia)
   at MyApp.Controls.ChatBubble.set_Message(String value) in C:\Users\...\source\repos\MyApp\MyApp\Controls\ChatBubble.axaml.cs:line 23
   at MyApp.MainWindow.SendBtn_OnClick(Object sender, RoutedEventArgs e) in C:\Users\...\source\repos\MyApp\MyApp\MainWindow.axaml.cs:line 52
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
   at Avalonia.Threading.SendOrPostCallbackDispatcherOperation.InvokeCore()
   at Avalonia.Threading.DispatcherOperation.Execute()
   at Avalonia.Threading.Dispatcher.ExecuteJob(DispatcherOperation job)
   at Avalonia.Threading.Dispatcher.ExecuteJobsCore(Boolean fromExplicitBackgroundProcessingCallback)
   at Avalonia.Threading.Dispatcher.Signaled()
   at Avalonia.Win32.Win32Platform.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam)
   at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg)
   at Avalonia.Win32.Win32DispatcherImpl.RunLoop(CancellationToken cancellationToken)
   at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl)
   at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame)
   at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken)
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.StartCore(String[] args)
   at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args)
   at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder)
   at MyApp.Program.Main(String[] args) in C:\Users\...\source\repos\MyApp\MyApp\Program.cs:line 12
Full `.csproj`
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net9.0</TargetFramework>
    <Nullable>enable</Nullable>
    <BuiltInComInteropSupport>true</BuiltInComInteropSupport>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Avalonia" Version="11.2.1" />
    <PackageReference Include="Avalonia.Desktop" Version="11.2.1" />
    <PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1" />
    <PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1" />
    <PackageReference Include="Avalonia.Diagnostics" Version="11.2.1">
      <IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
      <PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
    </PackageReference>
    <PackageReference Include="fluentavaloniaui" Version="2.2.0" />
    <PackageReference Include="markdig" Version="0.40.0" />
    <PackageReference Include="MessageBox.Avalonia" Version="3.2.0" />
    <PackageReference Include="OllamaSharp" Version="5.0.2" />
  </ItemGroup>
</Project>

I've tried deleting my nuget cache and restoring, to no avail.

I'm not really sure what other information is relevant here so please let me know and I'll include it.

Originally created by @UTF-8x on GitHub (Jan 22, 2025). I'm trying to use Markdig in an Avalonia app but `Markdown.Parse` and `Markdown.ToHtml` throw the following exception: ``` Unhandled exception. System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.MemoryMarshal' from assembly 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. ``` <details> <summary>Full stack trace</summary> ```Unhandled exception. System.TypeLoadException: Could not load type 'System.Runtime.InteropServices.MemoryMarshal' from assembly 'System.Runtime, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. at Markdig.Helpers.LineReader.ReadLine() at Markdig.Parsers.MarkdownParser.ProcessBlocks(BlockProcessor blockProcessor, String text) at Markdig.Parsers.MarkdownParser.Parse(String text, MarkdownPipeline pipeline, MarkdownParserContext context) at Markdig.Markdown.Parse(String markdown, MarkdownPipeline pipeline, MarkdownParserContext context) at Markdig.Markdown.Parse(String markdown, Boolean trackTrivia) at MyApp.Controls.ChatBubble.set_Message(String value) in C:\Users\...\source\repos\MyApp\MyApp\Controls\ChatBubble.axaml.cs:line 23 at MyApp.MainWindow.SendBtn_OnClick(Object sender, RoutedEventArgs e) in C:\Users\...\source\repos\MyApp\MyApp\MainWindow.axaml.cs:line 52 at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state) at Avalonia.Threading.SendOrPostCallbackDispatcherOperation.InvokeCore() at Avalonia.Threading.DispatcherOperation.Execute() at Avalonia.Threading.Dispatcher.ExecuteJob(DispatcherOperation job) at Avalonia.Threading.Dispatcher.ExecuteJobsCore(Boolean fromExplicitBackgroundProcessingCallback) at Avalonia.Threading.Dispatcher.Signaled() at Avalonia.Win32.Win32Platform.WndProc(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam) at Avalonia.Win32.Interop.UnmanagedMethods.DispatchMessage(MSG& lpmsg) at Avalonia.Win32.Win32DispatcherImpl.RunLoop(CancellationToken cancellationToken) at Avalonia.Threading.DispatcherFrame.Run(IControlledDispatcherImpl impl) at Avalonia.Threading.Dispatcher.PushFrame(DispatcherFrame frame) at Avalonia.Threading.Dispatcher.MainLoop(CancellationToken cancellationToken) at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.StartCore(String[] args) at Avalonia.Controls.ApplicationLifetimes.ClassicDesktopStyleApplicationLifetime.Start(String[] args) at Avalonia.ClassicDesktopStyleApplicationLifetimeExtensions.StartWithClassicDesktopLifetime(AppBuilder builder, String[] args, Action`1 lifetimeBuilder) at MyApp.Program.Main(String[] args) in C:\Users\...\source\repos\MyApp\MyApp\Program.cs:line 12 ``` </details> <details> <summary>Full `.csproj`</summary> ```xml <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>WinExe</OutputType> <TargetFramework>net9.0</TargetFramework> <Nullable>enable</Nullable> <BuiltInComInteropSupport>true</BuiltInComInteropSupport> <ApplicationManifest>app.manifest</ApplicationManifest> <AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault> </PropertyGroup> <ItemGroup> <PackageReference Include="Avalonia" Version="11.2.1" /> <PackageReference Include="Avalonia.Desktop" Version="11.2.1" /> <PackageReference Include="Avalonia.Themes.Fluent" Version="11.2.1" /> <PackageReference Include="Avalonia.Fonts.Inter" Version="11.2.1" /> <PackageReference Include="Avalonia.Diagnostics" Version="11.2.1"> <IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets> <PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets> </PackageReference> <PackageReference Include="fluentavaloniaui" Version="2.2.0" /> <PackageReference Include="markdig" Version="0.40.0" /> <PackageReference Include="MessageBox.Avalonia" Version="3.2.0" /> <PackageReference Include="OllamaSharp" Version="5.0.2" /> </ItemGroup> </Project> ``` </details> I've tried deleting my nuget cache and restoring, to no avail. I'm not really sure what other information is relevant here so please let me know and I'll include it.
Author
Owner

@UTF-8x commented on GitHub (Jan 22, 2025):

My bad, I was using an old preview dotnet version (9.0.0-preview.7.24405.7). Upgrading to 9.0.1 fixed this issue for me.

I'll leave this here for anyone facing the same issue if you don't mind.

@UTF-8x commented on GitHub (Jan 22, 2025): My bad, I was using an old preview dotnet version (`9.0.0-preview.7.24405.7`). Upgrading to `9.0.1` fixed this issue for me. I'll leave this here for anyone facing the same issue if you don't mind.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#719