Statiq.Framework: "Object does not match target type" error on dotnet 6 rc1 on linux and macOS

Seeing this error compiling razor on dotnet 6 rc1 but only with Linux and macOS - Object does not match target type

Preview releases of dotnet 6 worked fine, but with the latest version this is failing on cshtml.

You can see a full build output here but here is the full stack trace.

[DBUG] Exception while executing pipeline Archives/PostProcess: System.Reflection.TargetException: Object does not match target type.
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
   at Statiq.Razor.StatiqViewCompiler.CreateCompilation(String generatedCode, String assemblyName)
   at Statiq.Razor.StatiqViewCompiler.CompileAndEmit(RazorCodeDocument codeDocument, String generatedCode)
   at Statiq.Razor.RazorCompiler.GetCompilation(RazorProjectItem projectItem)
   at Statiq.Razor.RazorCompiler.<>c__DisplayClass11_0.<CompilePage>b__0(CompilerCacheKey _)
   at Statiq.Common.ConcurrentCache`2.<>c__DisplayClass2_1.<GetOrAdd>b__1()
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)
   at Statiq.Razor.CachingCompiler.GetOrAddCachedCompilation(CompilerCacheKey cacheKey, Func`2 valueFactory)
   at Statiq.Razor.RazorCompiler.CompilePage(RenderRequest request, Int32 contentCacheCode, RazorProjectItem projectItem)
   at Statiq.Razor.RazorCompiler.GetPageFromStreamAsync(IServiceProvider serviceProvider, RenderRequest request)
   at System.Lazy`1.CreateValue()
   at Statiq.Common.ConcurrentCache`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Statiq.Razor.CachingCompiler.GetOrAddCachedCompilation(CompilerCacheKey cacheKey, Func`2 valueFactory)
   at Statiq.Razor.RazorCompiler.CompilePage(RenderRequest request, Int32 contentCacheCode, RazorProjectItem projectItem)
   at Statiq.Razor.RazorCompiler.GetPageFromStreamAsync(IServiceProvider serviceProvider, RenderRequest request)
   at System.Lazy`1.CreateValue()
   at Statiq.Common.ConcurrentCache`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Statiq.Razor.CachingCompiler.GetOrAddCachedCompilation(CompilerCacheKey cacheKey, Func`2 valueFactory)
   at Statiq.Razor.RazorCompiler.CompilePage(RenderRequest request, Int32 contentCacheCode, RazorProjectItem projectItem)
   at Statiq.Razor.RazorCompiler.GetPageFromStreamAsync(IServiceProvider serviceProvider, RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RenderRazor.<>c__DisplayClass16_0.<<ExecuteContextAsync>g__RenderDocumentAsync|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RenderRazor.<>c__DisplayClass16_0.<<ExecuteContextAsync>g__RenderDocumentAsync|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorCompiler.RenderPageAsync(RenderRequest request)
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RenderRazor.<>c__DisplayClass16_0.<<ExecuteContextAsync>g__RenderDocumentAsync|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Statiq.Razor.RenderRazor.<>c__DisplayClass16_0.<<ExecuteContextAsync>g__RenderDocumentAsync|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Statiq.Razor.RenderRazor.<>c__DisplayClass16_0.<<ExecuteContextAsync>g__RenderDocumentAsync|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Statiq.Razor.RazorService.RenderAsync(RenderRequest request)
   at Statiq.Razor.RenderRazor.<>c__DisplayClass16_0.<<ExecuteContextAsync>g__RenderDocumentAsync|1>d.MoveNext()
--- End of stack trace from previous location ---
   at Statiq.Razor.RenderRazor.<>c__DisplayClass16_0.<<ExecuteContextAsync>g__RenderDocumentAsync|1>d.MoveNext()

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 16 (16 by maintainers)

Commits related to this issue

Most upvoted comments

Saw the latest release and I wanted to confirm it fixes this issue for anyone else that ends up here googling the error.

Thanks!

Sorry for the train of thought here, but I’m in the weeds and I wanted to dump what I found so hopefully someone smarter than me can pick up the trail, or at least tell me I’m on a wild goose chase here.

This change is sus, especially considering this comment “This name is hardcoded in RazorRuntimeCompilationMvcCoreBuilderExtensions. Make sure it’s updated if this is ever renamed.” Looks like with this commit they merged the DefaultViewCompiler and DefaultViewCompilerProvider into one class.

But tbh I’m struggling wrapping my head around whether this would cause my failure. With Statiq being compiled against 3.1 it feels like this conditional might not trigger with the new name causing the TryAddSingleton to skip the add because a previous instance never got removed. But that doesn’t quite explain why it works in Windows and not macOS or Ubuntu. And I’m not sure why a different runtime would even cause this either.

FWIW, I didn’t notice any changes to this code in the dotnet repo, but just to be sure I checked RC2. No magic - still not working.

Okay - fix is in, just wanted to make sure it wouldn’t break on older .NET targets (though it’s a pretty low-risk change given the existing behavior). I’ll get a release out later this week - have a couple more things in flight so not quite ready to publish one yet.

Going to move this issue to Framework since it’s almost certainly with the Framework Razor extension.

Also for anyone else who ends up here with the same problem, a global.json locking .NET to 5 until this is resolved should help work around it (https://docs.microsoft.com/en-us/dotnet/core/versions/selection#the-sdk-uses-the-latest-installed-version):

{
  "sdk": {
    "version": "5.0.0"
  }
}