question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Razor runtime compilation with dynamic assemblies fails

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When I load an assembly and then try to use any of its types as a view model I get an error that the provided instance does not match the expected type:

image

As you can see the weird part is that the expected and actual types are the same.

Below are the view, controller and model definitions:

using Microsoft.AspNetCore.Mvc;

namespace DemoNamespace
{
    public class TestController : Controller
    {
        public IActionResult Index()
        {

            return View(new TestViewModel{Name = "Test"});
        }
    }
}
namespace DemoNamespace
{
    public class TestViewModel
    {
        public string Name { get; set; }
    }
}
@using DemoNamespace

@model TestViewModel

<h1>@Model.Name</h1>

I made sure that the assembly is loaded only once and also tested to create an instance of the model within the view manually which worked, so the assembly must be loaded correctly. Also, changing the model directive to dynamic worked as well.

Expected Behavior

To work without any errors.

Steps To Reproduce

Load an assembly runtime and use any of its types as a view model.

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
aloksharma1commented, Apr 8, 2022

@gyankov i have the same issue as you from version 3.1 till now, its not fixed.

1reaction
javiercncommented, Feb 23, 2022

@gyankov thanks for contacting us.

@pranavkm do you have any thoughts here? Is this supported at all?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Razor Runtime Compilation doesn't work with dynamically ...
I get the error: Cannot find compilation library location for package '<name of loaded assembly>'. Setting ...
Read more >
Razor file compilation in ASP.NET Core
Build-time and publish-time compilation of Razor files is enabled by default by the Razor SDK. When enabled, runtime compilation complements ...
Read more >
Dynamically Loading Assemblies at Runtime in RazorPages
I've been working on some tools that create generic, standalone Web servers using ASP.NET Core, in various configurations.
Read more >
Add Razor runtime compilation when developing ASP.NET Core
Runtime compilation of Razor files just worked out of the box with ASP.NET MVC. In this post, I'll show you how we solved...
Read more >
[Fix]-Razor Runtime Compilation - appsloveworld.com
AspNet Core 3.0 and 3.1 : Enable runtime compilation for Razor Pages · Razor Page Runtime Compilation not working · ASP.NET Core Runtime...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found