Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Console App with Entity Framework Core: 'The process has no package identity' only when started without debugging

I have a .NET Console App integrated with Entity Framework and Discord Sharp Plus with the following libraries:

  • DSharpPlus
  • DSharpPlus.CommandsNext
  • Microsoft.EntityFrameworkCore.Design
  • Microsoft.EntityFrameworkCore.Sqlite
  • Microsoft.EntityFrameworkCore.Tools

Running the application without debugging (Control + F5 in Visual Studio) works just fine, no crashes issued.

However, if I run with debugging, upon accessing my DbContext, I get an error

InvalidOperationException: The Process has no package identity (0x80073D54)

An example being this line:

Database.Commands.SingleOrDefault(x => x.CommandTrigger == name)

For debugging purposes, if I change SingleOrDefault to ElementAt(0), I get the following error:

System.InvalidOperationException
HResult=0x80131509
Message=Processing of the LINQ expression 'DbSet .ElementAtOrDefault(__p_0)' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information.
Source=Microsoft.EntityFrameworkCore

StackTrace:

at Microsoft.EntityFrameworkCore.Query.Internal.NavigationExpandingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)

This is NOT an UWP app. It is a .NET console application with several class libraries.

Here's my Dbcontext class:

private readonly string dbPath = $"Data Source={Environment.GetEnvironmentVariable("YuutaDbPath")}";

public DbSet<Guild> Guilds { get; set; }
// ...
// ...

protected override void OnConfiguring(DbContextOptionsBuilder options)
    => options.UseSqlite(dbPath);

protected override void OnModelCreating(ModelBuilder builder)
{
    builder.SeedEnumValues//....
}
like image 531
Ali Bdeir Avatar asked Jun 24 '20 17:06

Ali Bdeir


People also ask

How to create a console app using Entity Framework Core?

In the Create a new project wizard, select the Console option, and select the Console App (.NET Core) template. Click on Next when done In the Configure your new project wizard, enter the project name and click on Create to Create new Console Project. Now, we need to install Entity Framework Core.

Can I use async main with Entity Framework Core?

We can also switch our application to use C# 7.1 and use async Main with new asynchronous methods of Entity Framework Core. Console .WriteLine ( " Press any key to continue ..." ); Entity Framework Core can be also used with .NET Core console applications.

What is included in Entity Framework Core package?

The Package Installs. The Entity Framework Core Tools contains command-line interface tools (CLI). These tools contain the command to create migrations, apply migrations, generate script migrations, and generate code for a model based on an existing database.

How to install EF Core in Package Manager Console?

In the New Project popup, expand Installed -> Visual C# in the left pane and select the Console App (.NET Core) template in the middle pane. Enter the Project Name & Location and click the OK button to create a console application, as shown below. Now, we need to install EF Core in our console application using Package Manager Console.


1 Answers

This is could be an internal exception which is handled by EF Core. You will see this kind of exceptions if you have disabled 'Enable Just My Code' in Visual Studio: Tools -> Options -> Debugging

enter image description here Enabling this option should fix the issue.

Essentially this will break code execution when exception occurs outside of your code even if handled.

If you hit F5 when the exception occurs it should continue running - this is way your program is running without issues when there is not debugger attached.

like image 70
vasil oreshenski Avatar answered Oct 17 '22 19:10

vasil oreshenski