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

New connection crashes VS when generating a new EF model from database #1445

Closed
roji opened this issue Feb 15, 2017 · 54 comments
Closed

New connection crashes VS when generating a new EF model from database #1445

roji opened this issue Feb 15, 2017 · 54 comments
Assignees
Labels
Milestone

Comments

@roji
Copy link
Member

roji commented Feb 15, 2017

Repro:

  1. Make sure no database connections are configured - open Server Explorer and remove all existing nodes under "Data Connections"
  2. Restart Visual Studio
  3. Right-click on a project nodes -> Add -> New Item ->Data -> EF Entity Data Model ->EF Designer from database -> New Connection...
  4. Select PostgreSQL if it's not already selected
  5. Type one letter in the Host box, and Visual Studio crashes

If a new data connection is added directly to the Server Explorer (not via "EF Designer from database"), and then selected when adding the EF model, everything seems to work fine. @Jasin2069 it would be great if you could confirm you're seeing the same thing.

I'll try to understand what's going on. In the meantime simply work around the issue by creating your connections in Server Explorer before generating a model.

Migrated from #1427 (comment)

/cc @Jasin2069

@Ivutar
Copy link

Ivutar commented Feb 15, 2017

If a new data connection is added directly to the Server Explorer (not via "EF Designer from database"), and then selected when adding the EF model, everything seems to work fine.

Nope.

  1. Create new console app (VS2015, community edition, Update 3)
  2. Install EntityFramework 6.1.3 via NuGet
  3. Install Npgsql 3.2.1 via NuGet
  4. Install EntityFramework6.Npgsql 3.1.1 via NuGet
  5. Install Npgsql PostgreeSQL Integration 3.2.1 via Extensions and Updates
  6. Restart VS2015
  7. Add new db connection via Server Explorer:
    image
  8. Add new Model1.edmx via Solution Explorer
    image
    and
    image
    (Here connection automatically captured from Server Explorer)
    Then click "Next >" button...
  9. No Model1.edmx created, no any error messages. Window silently closed.

@roji
Copy link
Member Author

roji commented Feb 15, 2017

@Ivutar thanks for reporting, but can you please open a new issue for this (even though they may be related)? I'll look at both issues together soon.

@SemperFu
Copy link

SemperFu commented Feb 15, 2017

@roji Thank you for responding. Mine crashes both ways. If I do it the first way it crashes on putting in an IP. If I do it the work around as you say I have the option already selected and I click next and it silently closes like Ivutar posted above. I would be happy to do a webex or provide any logs you need.

@roji
Copy link
Member Author

roji commented Feb 15, 2017

@Jasin2069 thanks for testing.

I'm pretty convinced (but not 100%) that these are two separate bugs. For the first one (typing in the host makes VS crash with an NRE) I've already reliably reproduced it here so it's a matter of finding the time to work on it.

I haven't looked at the other issue yet, if it reproduces as well it shouldn't be too hard.

Will try to look at these soon and will maybe publish a 3.2.1.1 VSIX with the fixes.

@SemperFu
Copy link

@roji Just to update you, I installed VS 2015 to test the same issues. The crash does not happen when typing in the IP. I am able to put in details and test the connection. However clicking next does the same where it will silently crash.

@roji
Copy link
Member Author

roji commented Feb 16, 2017

@kenjiuno, any idea about these issues? I'm not sure what worked before and what didn't, I think you know more about all this than me...

@kenjiuno
Copy link
Contributor

@Jasin2069 Hi
I want to know how Npgsql is resolved in Visual Studio.
Please run this code in Tools→NuGet Package Manager→Package Manager Console in Visual Studio:

(new-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/kenjiuno/CheckNpgsqlSetupStatus/master/CheckNpgsqlStatus.ps1") | iex ; CheckNpgsqlStatus

Let me know the output from the PowerShell script.

image

@SemperFu
Copy link

@kenjiuno Here is the output

Npgsql from DbProviderFactories.GetFactory:
Not available!
Npgsql in active project:
Npgsql, Version=3.2.1.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
C:\Users\Jasin\documents\visual studio 2017\Projects\PGTest\packages\Npgsql.3.2.1\lib\net451\Npgsql.dll
Npgsql in OutputPath:
3.2.1.0
C:\Users\Jasin\documents\visual studio 2017\Projects\PGTest\PGTest\bin\Npgsql.dll

@kenjiuno
Copy link
Contributor

@Jasin2069 Thank you for checking it!

Npgsql from DbProviderFactories.GetFactory:
Not available!

Finally we seem to need Npgsql-3.2.1.msi https://github.com/npgsql/npgsql/releases for only VS2015.
Please install it, and restart VS2015, and try to create new entity data model.

@SemperFu
Copy link

@kenjiuno I have installed that before and just tried it now with the same exact issue. I am using 2017 mostly but 2015 has the same problem.

Also I thought that was no needed if you are using the visual studio extention

@kenjiuno
Copy link
Contributor

@Jasin2069 Thanks for checking again,

Also I thought that was no needed if you are using the visual studio extention

Yea, we inject Npgsql ADO.NET data provider into DbProviderFactories at runtime.
https://github.com/npgsql/npgsql/blob/v3.2.1/src/VSIX/NpgsqlVSPackage.cs#L92-L94

The above way will help us to emit the following descritpion in machine.config only for Visual Studio integration.

<system.data>
  <DbProviderFactories>
    <add name="Npgsql Data Provider" invariant="Npgsql"
         description="Data Provider for PostgreSQL"
         type="Npgsql.NpgsqlFactory, Npgsql" />
  </DbProviderFactories>
</system.data>

(Copied from http://stackoverflow.com/a/19867046)

I think this method works in most case, but it may not work on some cases.

Now I'm going back to the original problem:

No Model1.edmx created, no any error messages. Window silently closed.

However clicking next does the same where it will silently crash.

This is right, however Exception is internally thrown inside Visual Studio.

In my research it was System.InvalidCastException. #445 (comment)

System.Data.Entity.Core.ProviderIncompatibleException: The provider did not return a ProviderManifestToken string. ---> System.InvalidCastException: [A]Npgsql.NpgsqlConnection cannot be cast to [B]Npgsql.NpgsqlConnection. Type A originates from 'Npgsql, Version=2.2.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Npgsql\v4.0_2.2.3.0__5d8b90d52f46fda7\Npgsql.dll'. Type B originates from 'Npgsql, Version=2.2.4.3, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' in the context 'Default' at location 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Npgsql\v4.0_2.2.4.3__5d8b90d52f46fda7\Npgsql.dll'.
   at Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection connection)
   at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)
   --- End of inner exception stack trace ---
   at System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection connection)

In order to catch the actual Exception, we need to attach a Managed Debugger (like Visual Studio) to the target Visual Studio running ADO.NET EDM Wizard.

I'll find a way to do this easily. I need some time.

@roji
Copy link
Member Author

roji commented Feb 28, 2017

@kenjiuno, FYI it's possible to debug the VSIX extension by simply running the project:

  • Open the Npgsql solution
  • Right-click VSIX project -> Set as startup project
  • Right-click VSIX project -> Properties -> Debug
    • Start external program: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe
    • Command line arguments: /rootsuffix Exp (you can also add the sln of a test project to make things easier to test).

After doing this, simply hitting F5 will launch a new instance of VS2017 (experimental) with the Npgsql VSIX loaded inside, so you can play around and set breakpoints.

When doing this, I caught a NullReferenceException when executing the scenario described in this issue. The problem seems to be that no Site is injected into the NpgsqlConnectionUIControl. When the user types a character into any text field, NpgsqlConnectionUIControl attempts to update the Site with the information and boom.

For some reason, when adding a new connection via the Server Explorer, a Site is properly injected, but not when doing it via the EDM Wizard... Any ideas??

@kenjiuno
Copy link
Contributor

Ok I'll check this later...

@SemperFu
Copy link

SemperFu commented Mar 3, 2017

Is there any thing else you guys would like me to try?

@roji
Copy link
Member Author

roji commented Mar 3, 2017

@Jasin2069 at least from my side it seems like we have what we need - I can easily reproduce the crash. Understanding why Visual Studio doesn't inject the site in this particular scenario is another matter.

@kenjiuno I hope you'll be able to understand what's going on... If you need help etc. let me know.

@SemperFu
Copy link

SemperFu commented Mar 4, 2017

So not sure what my options are at this point? I have no way to make a model from db atm.

@roji
Copy link
Member Author

roji commented Mar 4, 2017

@Jasin2069, I have been able to reproduce the crash when typing a character in the dialog - this is what this issue is about.

However, if the connection is first defined in Server Explorer and then selected in the EDM wizard, the model seems to be generated just fine. Can you please open a different issue for the second problem (silent crash after clicking next), and try to provide very detailed repro instructions (similar to what I wrote at the top of this issue)?

@dropyghost
Copy link

After creating the Server Explorer connection was able to create the model. But show a warning.

Severity Code Description Project File Line Suppression State
Warning Compiling transformation: Assuming assembly reference 'mscorlib, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' used by 'EnvDTE' matches identity 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' of 'mscorlib', you may need to supply runtime policy NpgsqlSetup C:\Users\juan.oropeza\NpgsqlSetup\Model1.tt

After google the error I install this microsoft fix. https://msdn.microsoft.com/en-us/library/mt695655.aspx

Cumulative Servicing Release for Microsoft Visual Studio 2015 Update 2 (KB3151378)

But now I cant connect again

image

@roji
Copy link
Member Author

roji commented Mar 19, 2017

@kenjiuno any success with this?

@roji roji removed this from the 3.2.2 milestone Mar 19, 2017
@sreekanthbantu
Copy link

Update to Npgsql 3.2.1, everything should work as expected.

@pentagra
Copy link

pentagra commented Oct 4, 2018

I still have this problem with latest 4.0.3 version and VS 2017 (15.8.6) :(

@ignacioinnovo
Copy link

Dear Npgsql Team,

I have the same problem with VS2017.

Thank you for your great tool!

@williansdejulio
Copy link

williansdejulio commented Oct 30, 2018

I also have the same problem with VS2017.

I am using:

  • Visual Studio 2017: 15.6.0
  • .NET Framework: 4.6.1
  • EntityFramework: 6.2.0
  • Npgsql: 4.0.3
  • EntityFramework6.Npgsql: 3.2.0

I created an empty project and tried to create an EF Designer from database. I chose my PostgreSQL connection previously created, and click "Next".

entities

After clicking "Next" on this screen, the window silently closes. No errors and no edmx.
I read the whole thread, and it could be the extension not still not autoloading. Can I manually load it?
Is there another temporary solution?

Thanks!

@Avantura82
Copy link

Avantura82 commented Nov 2, 2018

  1. Remove all npgsql and postresql related entries from all "machine.config" and "devenv.exe.config"
    (use Everything from voidtools.com to find them)
  2. Remove your DB connection from Server Explorer
  3. Remove all Nuget Packages (EF, EF6.npgsql, npgsql, all other related)
  4. Clean up your App.config / Web.config from all EF and npgsql related sections
  5. Remove all Nuget Packages from Filesystem (use Everything again to find them)
  6. Check the Extensions and Updates
  7. Restart VS2017
  8. Add Nugets again
  9. Build Project
  10. Close VS2017
  11. Cleanup Project Directories (bin, obj, etc.) (use git cleanup)
  12. Restart VS2017
  13. Add new Model now

Repeat step 10. to 13. everytime new or update Model is needed.

@ZipionLive
Copy link

Having the exact same problem as @williansdejulio in both VS2015 and VS2017, with the same packages and on the same .NET framework version. This has really been blocking me for two days in my current project, any fix known ?

@Avantura82 I tried that a few times already, the problem remains no matter how many times I clean up and restart the whole ordeal, and on both versions of VS.

@ZipionLive
Copy link

ZipionLive commented Nov 14, 2018

Here are my installed nuget packages :

capture

@gyzod
Copy link

gyzod commented Jan 30, 2019

Hi @roji, any update on this issue ? I have the same problems. Creating a new postgres database in server explorer crashes. Adding a new ADO.Net Entity Data Model also fails with after selecting the database. The workaround provided by Avantura82 doesn't work for me.

EntityFramework v6.2.0
EntityFramework6.Npgsql v3.2.0
Npgsql v4.0.4
VS2017 15.9.6

Thanks

@pentagra
Copy link

I think author thinks that issue resolved since the status is "Closed" ...
But I have the same issue too with 4.0.3 (had no time to check with latest version, but there is nothing about it in bug list)

@dahateb
Copy link

dahateb commented Feb 5, 2019

don't know if that helps but it seems i solved it by uninstalling the entity framework visual editor

@roji
Copy link
Member Author

roji commented Feb 7, 2019

I'll try to look at this again, but in the past I haven't gotten this to repro on my machine, and the root cause was always some old version of the extension that was still somehow being used. For all people encountering this, please try to follow the cleanup instructions above, and also to test on a completely new machine to be extra sure. Please post your findings either way.

@roji roji reopened this Feb 7, 2019
@asimdeveloper
Copy link

When i try to connect and type something it shows this error and window closes

image

@YohDeadfall
Copy link
Contributor

@asimdeveloper There is not enough info in your message. What version of VS are you using? What version of Npgsql VSIX?

@asimdeveloper
Copy link

I am using VS 19
EF 6
.net framework 4.6

I am manged to solve the above issue.. now i am getting this error

image

@YohDeadfall
Copy link
Contributor

If you provide information about how you solved it, you would help other developers to solve their problems too.

The problem you see is tracked by #2670.

@richmcd
Copy link

richmcd commented Nov 6, 2019

I am seeing silent crashes when generating EF model from database as well.

VS 2017(15.9.17)
.NET Framework version installed 4.8.03752 (Project is targeting .NET Framework 4.5)
Npgsql VSIX version 4.0.10
EntityFramework6.Npgsql NuGet package version 6.3.0
Npgsql NuGet package version 4.0.10 (required by EntityFramework6.Npgsql and .NetFramework v4.5 latest stable version 4.1.1 does not target .NetFramework v4.5)
EntityFramework NuGet package version 6.3.0 (Latest Stable required by EntityFramework.Npgsql)

I don't know if this is the issue, but I had originally added the NuGet package for EntityFramework.Npgsql v2.2.7, which also added the Npgsql package v2.2.7 to the project before I realized the name change for EF6. I removed those packages then added the packages listed above before installing the VSIX for version 4.1.1.2. I encountered the error listed in #2670 so I uninstalled that VSIX and installed the VSIX for v4.0.10, which solved the error during creation of the database connection, but now I'm receiving this error when generating a model from a database.

I have tried creating the connection in Server Explorer first, as well as creating the connection when adding a new ADO.Net Entity Data Model. I also tried creating an empty data model and using the Generate Model from Database option in the context menu of the Model Explorer. Each method attempts to open the wizard, and I can see the radio button for Entity Framework 6.x before the window closes silently. After this happens I notice that the connection in Server Explorer is created, but has a red X as though it's disconnected (clicking refresh or the expand arrow reconnects the database).

I have tried the cleanup steps mentioned above, but after uninstalling the NuGet packages and the VSIX I do not see any references to Npgsql in either the machine.config or devenv.exe.config. I have also tried a new ASP.Net Web Application (Web API) project targeting .NET Framework v4.5, all packages updated to latest stable with the exception of Npgsql due to .NetFramework v4.5 limitation, with the same results.

CheckNpgsqlStatus output:

Host

Microsoft Visual Studio 15.0 Enterprise

GetSection system.data/DbProviderFactories


Name                                                  Description                                                              InvariantName                    AssemblyQualifiedName                              
----                                                  -----------                                                              -------------                    ---------------------                              
...
Npgsql Data Provider                                  .NET Data Provider for PostgreSQL                                        Npgsql                           Npgsql.NpgsqlFactory, Npgsql                       


DbProviderFactories.GetFactoryClasses


Name                                                  Description                                                              InvariantName                    AssemblyQualifiedName                              
----                                                  -----------                                                              -------------                    ---------------------                              
…
Npgsql Data Provider                                  .NET Data Provider for PostgreSQL                                        Npgsql                           Npgsql.NpgsqlFactory, Npgsql                       


Npgsql from DbProviderFactories.GetFactory

Npgsql, Version=4.0.10.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
%USERPROFILE%\APPDATA\LOCAL\MICROSOFT\VISUALSTUDIO\15.0_2A827E38\EXTENSIONS\D4YC4RC2.XBO\Npgsql.dll

Npgsql in active project

  • Real assembly version:
    Npgsql, Version=4.0.10.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
    %SolutionFolder%\packages\Npgsql.4.0.10\lib\net45\Npgsql.dll
  • Actually loaded version where bindingRedirect affects:
    Npgsql, Version=4.0.10.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
    %SolutionFolder%\packages\Npgsql.4.0.10\lib\net45\Npgsql.dll

Npgsql in OutputPath

  • Real assembly version:
    Npgsql, Version=4.0.10.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
    %ProjectFolder%\bin\Npgsql.dll
  • Actually loaded version where bindingRedirect affects:
    Npgsql, Version=4.0.10.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7
    %ProjectFolder%\bin\Npgsql.dll

@roji
Copy link
Member Author

roji commented Nov 6, 2019

@richmcd note that you're not supposed to see Npgsql in your machines.config or in your GAC - newer versions of the VSIX don't do that anymore (Npgsql is simply part of the VSIX). We're aware that machines that had older versions of the VSIX sometimes need extensive cleanup precisely because those versions affected global Windows state - any chance you can try out on a clean machine?

@richmcd
Copy link

richmcd commented Nov 6, 2019

... - any chance you can try out on a clean machine?

Unfortunately no, I only have access to this machine for development.

@lotodore
Copy link

I have debugged the issue with the silent crashes (where the wizard closes with the Entity Framework 6.x radio button shown for a short time). The following exception occurs:
System.InvalidCastException HResult=0x80004002 Message=[A]Npgsql.NpgsqlConnection cannot be cast to [B]Npgsql.NpgsqlConnection. Type A originates from 'Npgsql, Version=4.0.4.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' in the context 'Default' at location 'c:\users\xyz\appdata\local\microsoft\visualstudio\15.0_4c5f304dexp\extensions\npgsql\npgsql postgresql integration\4.0.4\Npgsql.dll'. Type B originates from 'Npgsql, Version=4.0.10.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' in the context 'LoadNeither' at location 'C:\Users\xyz\AppData\Local\Microsoft\VisualStudio\15.0_4c5f304dExp\ProjectAssemblies\c9c6zl0q01\Npgsql.dll'. Source=EntityFramework6.Npgsql StackTrace: at Npgsql.NpgsqlServices.GetDbProviderManifestToken(DbConnection connection)
This means that the crash is caused by incompatible versions of Npgsql.dll in the plugin directory and downloaded by nuget. After downgrading the nuget version of npgsql to the one supplied by the Visual Studio plugin, code generation works without crash.
However, this leads to a bad situation: Certain recent fixes in npgsql are quite important, but downgrading the Visual Studio plugin is required due to #2670, and due to this bug it enforces downgrading of the npgsql nuget package. A fix would be greatly appreciated.

@diordonez
Copy link

I was having the exact same issue, here my steps to solve it, perhaps it might be useful for some of you.

  1. Check the exact version of your Postgresql Integration VSIX
    https://marketplace.visualstudio.com/items?itemName=RojanskyS.NpgsqlPostgreSQLIntegration

In my case it is 4.1.1.2

  1. Install the exact same version via NUGET of NPGSQL, i.e. npgsql 4.1.1

  2. Install EntityFramework6.Npgsql a version compatible with npgsql 4.1.1
    In my case it is --> 6.3.0 ( Even if the 6.4.0 is already available)

DO NOT UPGRADE NPGSQL

That's it, my Entity Data Model Wizard is working well so far, no more crashes.

Cheers

@akhmadhamzahs
Copy link

I was having the exact same issue, here my steps to solve it, perhaps it might be useful for some of you.

1. Check the exact version of your Postgresql Integration VSIX
   https://marketplace.visualstudio.com/items?itemName=RojanskyS.NpgsqlPostgreSQLIntegration

In my case it is 4.1.1.2

1. Install the **exact same version** via NUGET of NPGSQL, i.e. npgsql 4.1.1

2. Install EntityFramework6.Npgsql a version compatible with npgsql 4.1.1
   In my case it is --> 6.3.0 ( Even if the 6.4.0 is already available)

DO NOT UPGRADE NPGSQL

That's it, my Entity Data Model Wizard is working well so far, no more crashes.

Cheers

@diordonez
I already used your method but when I press finish, I get this.
any other ideas?

thank you

image

@Yang09701194
Copy link

I got this Error but I'm using Oracle Database with Oracle.ManagedDataAccess.dll, and I found it's related to the version of Oracle Developer Tool For Visual Studio I installed should match the version of Oracle.ManagedDataAccess.dll,

for example:

ODT version: 12.2.1200 - match - Oracle.ManagedDataAccess.dll version: 4.122.1.0

@Nessitro
Copy link

I also got the "The provider did not return a ProviderManifestToken string" but usually nothing shows

@roji roji closed this as completed in d932f3b Nov 15, 2020
@john-larson
Copy link

I was also experiencing the disappearing wizard problem when entering the connection information. Uninstalling the vsix extension and reinstalling it seemed to solve the issue. Then, the next step in the wizard had the same problem. I again reinstalled the extension and now everything seems to work fine.

@WojGrab
Copy link

WojGrab commented Oct 28, 2021

Still same issue... Aligning nuget and vsix versions doesn't work. Reinstalling vsix and rebuilding project neither.

@AresDraco
Copy link

Was this ever fixed? have same issue with VS 2019 community...

@roji
Copy link
Member Author

roji commented Apr 24, 2022

Everyone, please note that the VSIX is no longer being maintained, among other things because issues such as the above were very hard to diagnose and fix.

@JamesRedway
Copy link

For me adding this to my web.config seemed to solve the issue.

<system.data>
  <DbProviderFactories>
      <remove invariant="Npgsql"/>
      <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF"/>
  </DbProviderFactories>
</system.data>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests