Odd_Dev_404
C#.NET Core Console Application with Xunit not detecting the console project as a project reference.
I have created a C#.NET Core Console Application. And added new Xunit project under the same solution. Then added a project reference to the console application project under Xunit project, and then I can write unit tests for the console application. I can see that the reference has been added successfully as below:
<ItemGroup>
<ProjectReference Include="..\ConsoleApp1\ConsoleApp1.csproj" />
</ItemGroup>
But when I was trying to use console application's classes after importing the namespace to the unit test project, it doesn't detect as expected.
Both projects have the same .NET core version 8.
Can someone help me with this please?
13 replies
ASP.Net Core MVC Razor view rendering data from controller with dynamic casting
In my MVC application I'm using IEnumerable interface inside my repository for the database model, and using it in the controller to pass the data to view using ViewData["roles"] = _userRolesRepository.GetAll(); which is GetAll() uses IEnumerable interface here.
But when I'm trying to foreach the data on Razor view using:
@{
var users = ViewData["roles"];
}
@if (users is not null)
{
@foreach (var user in users)
{
<h3>Test User Roles Results Set</h3>
<h3>Id: @user.Id</h3>
<h3>Name: @user.Name</h3>
}
}
But then compiler throws and error - "foreach statement cannot operate on variables of type 'type1' because 'type2' does not contain a public definition for 'identifier'".
When I cast the users data to "dynamic" all good.
@{
var users = ViewData["roles"];
}
@if (users is not null)
{
@foreach (var user in (dynamic)users)
{
<h3>Test User Roles Results Set</h3>
<h3>Id: @user.Id</h3>
<h3>Name: @user.Name</h3>
}
}
I would like to know what happens here?
8 replies