locked
VS2019 vs VS2017 and EF 6.0 - big mess RRS feed

  • Question

  • User379720387 posted

    2X Community Edition for visual studio

    My application builds fine in VS2017, no errors.

    Close the solution and now open it in VS2019. Add two non primary key column in one table.

    After "Update model from database", Save and Build: I have 400 errors all related to dbContext and missing customizations on a few tables.

    Close the solution and reopen in VS2017, then I do not see any error messages.

    How is this possible?

    Thursday, October 31, 2019 4:00 PM

Answers

  • User379720387 posted

    There is an issue with EF on the non preview versions of VS2019.

    Someone at Microsoft suggested that I use the preview version which I did. Now EF can again create Model.edmx without any issues.

    https://developercommunity.visualstudio.com/content/problem/806218/update-model-from-database-fails-in-vs2019-not-in.html?childToView=809981#comment-809981

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 31, 2019 2:35 PM

All replies

  • User753101303 posted

    Hi,

    And the most frequent error message is ?

    Thursday, October 31, 2019 4:12 PM
  • User379720387 posted

    Sorry for the delay, had to get some work done first.

    The error types are:

    6 each in the same file:
    Severity Code Description Project File Line Suppression State
    Error CS0246 The type or namespace name 'BTEntities11' could not be found (are you missing a using directive or an assembly reference?) 
    1 each:
    Severity Code Description Project File Line Suppression State
    Error An exception was thrown while trying to compile the transformation code. The following Exception was thrown:
    System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\$(VSAPPIDDIR)EntityFramework.dll'.
    File name: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\$(VSAPPIDDIR)EntityFramework.dll'
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
       at Roslyn.Utilities.FileUtilities.OpenFileStream(String path)
       at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation)
       at Microsoft.VisualStudio.TextTemplating.CompilerBridge.<>c.<.ctor>b__15_0(String x)
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Linq.Enumerable.d__67`1.MoveNext()
       at System.Linq.Enumerable.d__67`1.MoveNext()
       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
       at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
       at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
       at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
       at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithReferences(IEnumerable`1 references)
       at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonWithReferences(IEnumerable`1 newReferences)
       at Microsoft.VisualStudio.TextTemplating.CompilerBridge.PrepareNewCompilation()
       at Microsoft.VisualStudio.TextTemplating.CompilerBridge.Compile()
       at Microsoft.VisualStudio.TextTemplating.TransformationRunner.Compile(String source, String inputFile, IEnumerable`1 references, Boolean debug, SupportedLanguage language, String compilerOptions) 1
    387 each for various tables:
    Severity Code Description Project File Line Suppression State
    Error CS1061 'ProviderSvcTransaction' does not contain a definition for 'ProviderService' and no accessible extension method 'ProviderService' accepting a first argument of type 'ProviderSvcTransaction' could be found (are you missing a using directive or an assembly reference?) 
    Friday, November 1, 2019 8:30 PM
  • User288213138 posted

    Hi wavemaster,

    Error CS0246 The type or namespace name 'BTEntities11' could not be found (are you missing a using directive or an assembly reference?)

    System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\$(VSAPPIDDIR)EntityFramework.dll

    You'll need to make sure that you are referencing the Entity Framework reference files within your Project under References.

    You can do that through the following steps:

    • Right-click your Project in the Solutions Explorer.
    • Choose Manage NuGet Packages...
    • Search for the EntityFramework Package.
    • Click Install to add it to your existing project

    You can also refer to below links about similar error:

    https://stackoverflow.com/questions/5741109/the-type-or-namespace-name-dbcontext-could-not-be-found

    https://forums.asp.net/t/1892907.aspx?The+type+or+namespace+name+DbContext+could+not+be+found

    Best regards,

    Sam

    Monday, November 4, 2019 3:04 AM
  • User379720387 posted

    Keep in mind that this solution works in VS2017, not in VS2019

    NPM has EntityFramework by Microsoft listed in the installed category with version 6.1.3, there is an update to version 6.3.0 available.

    Monday, November 4, 2019 11:40 AM
  • User288213138 posted

    Hi Wavemaster,

    Error CS0246 The type or namespace name 'BTEntities11' could not be found (are you missing a using directive or an assembly reference?)

    Can you show me what 'BTEntities11' is in your project?

    System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\$(VSAPPIDDIR)EntityFramework.dll'.

    Are you sure that there is EntityFramework in your vs2019?

    Best regards,

    sam

    Tuesday, November 5, 2019 9:23 AM
  • User379720387 posted

    In Model.Context.cs I have this:

    using System;
    using System.Data.Entity;
    using System.Data.Entity.Infrastructure;
    using System.Data.Entity.Core.Objects;
    using System.Linq;
    
    public partial class BTEntities11 : DbContext
    {
        public BTEntities11()
            : base("name=BTEntities11")
        {
        }
    
        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }
    
        public virtual DbSet<Appointment> Appointments { get; set; }
        public virtual DbSet<Associate> Associates { get; set; }
    ... plus 100 more of these to cover all the tables in the db

    In Model.edmx:

    EntityContainer Name="BTEntities11" annotation:LazyLoadingEnabled="true">
              <EntitySet Name="Appointments" EntityType="Self.Appointment" />
              <EntitySet Name="Associates" EntityType="Self.Associate" />
    ... all the other tables are here as well

    In web.config:

    <add name="BTEntities11" connectionString="metadata=res://*/App_Code.Model.csdl|res://*/App_Code.Model.ssdl|res://*/App_Code.Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MW10\SSERVER;initial catalog=XX;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    

    There are no squiggles when this solution is open in VS2019 CE, AFTER I have built and saved the project.

    Nuget Package Manager says EF 6.1.3 is installed.

    Is there another way to verify it is installed?

    EDIT:

    Now VS2019 shows a different message:

    Severity Code Description Project File Line Suppression State
    Error An exception was thrown while trying to compile the transformation code. The following Exception was thrown:
    System.IO.FileNotFoundException: Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\$(VSAPPIDDIR)EntityFramework.dll'.
    File name: 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\$(VSAPPIDDIR)EntityFramework.dll'
       at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
       at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
       at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share)
       at Roslyn.Utilities.FileUtilities.OpenFileStream(String path)
       at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation)
       at Microsoft.VisualStudio.TextTemplating.CompilerBridge.<>c.<.ctor>b__15_0(String x)
       at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
       at System.Linq.Enumerable.<UnionIterator>d__67`1.MoveNext()
       at System.Linq.Enumerable.<UnionIterator>d__67`1.MoveNext()
       at System.Linq.Buffer`1..ctor(IEnumerable`1 source)
       at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
       at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable`1 items)
       at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable`1 items)
       at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable`1 references)
       at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithReferences(IEnumerable`1 references)
       at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonWithReferences(IEnumerable`1 newReferences)
       at Microsoft.VisualStudio.TextTemplating.CompilerBridge.PrepareNewCompilation()
       at Microsoft.VisualStudio.TextTemplating.CompilerBridge.Compile()
       at Microsoft.VisualStudio.TextTemplating.TransformationRunner.Compile(String source, String inputFile, IEnumerable`1 references, Boolean debug, SupportedLanguage language, String compilerOptions) 1

    Searching for EntityFramework.dll in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\

     it finds 2 each:

    one in the IDE folder

    one in C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Microsoft\Entity Framework Tools\Runtimes\5.0.0

    Then the question becomes why does "update model from database look at: $(VSAPPIDDIR)EntityFramework.dll

    What does that mean $(VSAPPIDDIR)?

    Tuesday, November 5, 2019 12:00 PM
  • User288213138 posted

    Hi wavemaster,

    Is there another way to verify it is installed?

     Open the References in your project. To see if there is EntitFramework, if it is, you have already installed it.

    What does that mean $(VSAPPIDDIR)?

    The $(VSAPPDIR) is a variable when the project is run.

    Could not find file 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\$(VSAPPIDDIR)EntityFramework.dll'

    There are similar questions here, you can use as a reference. 

    https://developercommunity.visualstudio.com/content/problem/580524/after-update-to-1610-entityframework-code-generati.html

    Best regards,

    sam

    Wednesday, November 6, 2019 10:21 AM
  • User379720387 posted

    There is an issue with EF on the non preview versions of VS2019.

    Someone at Microsoft suggested that I use the preview version which I did. Now EF can again create Model.edmx without any issues.

    https://developercommunity.visualstudio.com/content/problem/806218/update-model-from-database-fails-in-vs2019-not-in.html?childToView=809981#comment-809981

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 31, 2019 2:35 PM