Razor runtime compilation with dynamic assemblies fails
See original GitHub issueIs 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:
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:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@gyankov i have the same issue as you from version 3.1 till now, its not fixed.
@gyankov thanks for contacting us.
@pranavkm do you have any thoughts here? Is this supported at all?