Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DbContext is working fine in Debug mode but not in release mode ( using Microsoft.EntityFrameworkCore.Sqlite v 2.2.6 and Microsoft.NETCore.UniversalWindowsPlatform v 6.2.9) #20122

Closed
RituparnaGoswamiMishra opened this issue Mar 2, 2020 · 7 comments

Comments

@RituparnaGoswamiMishra
Copy link

RituparnaGoswamiMishra commented Mar 2, 2020

I am not sure if this is version issue or not but , when I try to install Microsoft.EntityFrameworkCore.Sqlite , latest verion 3.1.2, I get build error

"Severity Code Description Project File Line Suppression StateError Payload contains two or more files with the same destination path 'e_sqlite3.dll'. Source files:
C:\Users\ritup.nuget\packages\sqlitepclraw.lib.e_sqlite3\2.0.2\runtimes\win10-x86\nativeassets\uap10.0\e_sqlite3.dll
C:\Users\ritup.nuget\packages\sqlitepclraw.lib.e_sqlite3.v140\1.1.2\runtimes\win10-x86\native\e_sqlite3.dll pave.myLocation.Player
"
After initial googling, I downgraded the version to 2.2.6.

Now everything works fine in debug, but in release , the db context is not working properly for the unit tests... I have tried by creating the db file in the local folder as well as with in memory db for sqlite.

Implementing SQlite without EF should work fine, writing all the db queries and statements are not only troublesome but also error prone. does anyone has any lead on this. ?

This is how you can reproduce the issue:-
my database context

public class DatabaseContext : DbContext
    {

        public DbSet<TestEntity> TestEntity { get; set; }

        public DatabaseContext(DbContextOptions<DatabaseContext> options)
            : base(options)
        { }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<TestEntity>().HasKey(x => x.Uid);
            base.OnModelCreating(modelBuilder);
        }
    }

my entity

[Table("TestEntity")]
    public class TestEntity
    {
        [Key]
        public Guid Uid { get; set; }
        public string Id { get; set; }
        public string Name {get; set;}
   }

My db service that uses the db context

public class DatabaseService
    {
        private DatabaseContext _context;
       
        public DatabaseService( DatabaseContext context)
        {
            _context = context;
          
        }


        public void InitializeDatabase()
        {
              _context.Database.EnsureCreated();
        }

        public void InsertData(ObservableCollection<TestEntity> testEntitys)
        {
         
                    _context.TestEntity.AddRange(testEntitys);
                    _context.SaveChanges();
                   
        }

My test case

public class DatabaseServiceTestCases
   {
       readonly ObservableCollection<TestEntity> _data = new ObservableCollection<TestEntity>();
       public DatabaseServiceTestCases()
       {
// prepares data and fills the _data object
           DataPreperation();
       }
       [Fact]

       public void DatabaseService_InsertDataTest()
       {
          var connection = new SqliteConnection("DataSource=:memory:");
         
           connection.Open();

           try
           {
               var options = new DbContextOptionsBuilder<DatabaseContext>()
                   .UseSqlite(connection)
                   .Options;

               // Create the schema in the database
               using (var context = new DatabaseContext(options))
               {
                   var service = new DatabaseService(context);
                   service.InitializeDatabase();

                   service.InsertData(_data);
                   Assert.Equal(4, context.TestEntity.Count());
               }
           }
           finally
           {
               connection.Close();
           }
       }

in debug mode everything works fine, but in release apparently the context.TestEntity is null.
this is the error I am getting

Source: DatabaseServiceTestCases.cs line 39
Duration: 115 ms

Message:
System.ArgumentNullException : Value cannot be null.
Parameter name: source
Stack Trace:
Queryable.CountTSource + 0xb5
DatabaseServiceTestCases.DatabaseService_InsertDataTest() + 0x1d0
InvokeRetV(Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x2f
Call(IntPtr, Object, IntPtr, InvokeUtils.ArgSetupState&, Boolean) + 0x2c
InvokeUtils.CallDynamicInvokeMethod(Object, IntPtr, Object, IntPtr, IntPtr, Object, Object[], BinderBundle, Boolean, Boolean, Boolean) + 0x119

thanks in advance!!

@ajcvickers
Copy link
Member

@bricelam to take a look

@bricelam
Copy link
Contributor

bricelam commented Mar 2, 2020

Looks like you are bringing in both version 2.0.2 and 1.1.2 of SQLitePCLRaw. These two versions are incompatible. Find the dependency that is using 1.x and update (or remove) it.

@RituparnaGoswamiMishra
Copy link
Author

Looks like you are bringing in both version 2.0.2 and 1.1.2 of SQLitePCLRaw. These two versions are incompatible. Find the dependency that is using 1.x and update (or remove) it.

That's what I did, downgraded to version to 2.2.6, but now the problem is the DBcontext works fine in debug mode but not in release

@bricelam
Copy link
Contributor

bricelam commented Mar 3, 2020

I wonder if this is related to #19535

@RituparnaGoswamiMishra
Copy link
Author

RituparnaGoswamiMishra commented Mar 4, 2020

I wonder if this is related to #19535

I don't think so, my dataset doesn't have a collection. It is a very simple one.

@ajcvickers
Copy link
Member

@RituparnaGoswamiMishra Please note that EF Core 2.2 is now out-of-support. As @bricelam said above, you should "find the dependency using 1.x and update (or remove) it.". Then if you're still seeing issues we can investigate.

@ajcvickers
Copy link
Member

EF Team Triage: Closing this issue as the requested additional details have not been provided and we have been unable to reproduce it.

BTW this is a canned response and may have info or details that do not directly apply to this particular issue. While we'd like to spend the time to uniquely address every incoming issue, we get a lot traffic on the EF projects and that is not practical. To ensure we maximize the time we have to work on fixing bugs, implementing new features, etc. we use canned responses for common triage decisions.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants