No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer

When you move your Visual Studio solution to another workstation you may encounter the following error message:

System.Data.Entity.Core.MappingException was unhandled by user code
HResult=-2146232032
Message=Schema specified is not valid. Errors:
: error 2062: No mapping specified for instances of the EntitySet and AssociationSet in the EntityContainer …
Source=EntityFramework

 

In this case it may help if you re-import the database objects into the .edmx file.

To import all objects again:

  • Open the .edmx file,
  • Press the Ctrl-A keys to select all tables in the diagram,
  • Press the delete key on the keyboard to delete all tables,
  • Right click the white area and select Model Browser,
  • In the Model Browser expand the {model name}.Store, and the Stored Procedures / Functions element
  • Delete all functions and stored procedures
  • In the {model name} element (the element above the {model name}.Store) expand the Function Imports element
  • Delete all function imports
  • Save the .edmx file
  • Right click the white area of the .edmx file and select Update Model from Database
  • Select all necessary tables, stored procedures, and functions and import them.

If you re-import the tables, but do not delete the stored procedures, functions, and function imports you may get the following error message:

HResult=-2146233079
Message=The function import ‘Tobacco_WebEntities.spGetAgeGroupId’ cannot be executed because it is not mapped to a store function.
Source=EntityFramework

 

Save the key file password in Visual Studio

When you have already set up the project signing of the C# application for ClickOnce deployment, and move the solution to another workstation you may get the following error message when you build the solution:

Severity Code Description Project File Line Suppression State
Error Cannot import the following key file: .....pfx. The key file may be password protected. To correct this, try to import the certificate again or manually install the certificate to the Strong Name CSP with the following key container name: VS_KEY_....

We get this message, because the new workstation does not know the key file password. To solve this problem, we have to save the key file password on the new workstation.

To make your solution work again

  • Open the Visual Studio project properties window,
  • On the Signing tab click the pull down that shows the name of the key file.
  • Select Browse,
  • Select the key file,
  • Enter the password in the Password text box.

No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlClient’

When one of the projects in your solution is referencing the Entity Framework to access a database the Entity Framework NuGet package is added to that project. In the Visual Studio IDE your application may work fine, but when you deploy it to the test or production server the following error message may appear:

Exception Type: System.Data.Entity.Core.MetadataException
Exception: Schema specified is not valid.
Errors: [YOUR_DATABASE].ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name ‘System.Data.SqlClient’. Make sure the provider is registered in the ‘entityFramework’ section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

To resolve the problem add the Entity Framework NuGet package to the main project of your application:

  • In the Solution Explorer right click the main project,
  • Select Manage NuGet Packages… in the context menu,
  • On the left side of the NuGet manager select Online, Microsoft and .NET,
  • On the right side enter EntityFramework into the search field and hit Enter,
  • In the middle click Install in the EntityFramework box.

There is already an open DataReader associated with this Command which must be closed first

When your MVC 5 web application page tries to read the database using the Entity Framework in a loop you may get the following error message:

InnerException: System.InvalidOperationException
HResult=-2146233079
Message=There is already an open DataReader associated with this Command which must be closed first.
Source=System.Data

This usually happens when a cshtml page receives an IEnumerable<> model from the database and makes repeated calls to retrieve the rows one-by-one in a foreach loop.

If your page does not display paged data, read the rows into a List  with the ToList() method and send the list to the cshtml page to iterate through it. This forces the application to read all appropriate rows with one call from the database.

Sometimes you can also eliminate the problem if you add the following to the connection string in the web.config file:

;multipleactiveresultsets=True

How to add tooltip to a Windows Form

In Windows Form applications the tooltip functionality is not built into the controls as in HTML objects.

To add tooltip to your controls on Windows Forms

  • Open the Windows Form in the designer
  • Drag the ToolTip control from the Common Controls section of the Toolbox to the form. The ToolTip control will be placed at the bottom margin of the design surface outside of the visible area of the form.
  • A new item appears in the Misc section of the property list of the form controls (buttons, textboxes, etc): ToolTip on toolTip1
  • Enter the text there you want the users to see when they hover above the control.

How to handle “The target version of the .NET Framework in the project does not match…” warning message in Microsoft Visual Studio

When you build the setup project in Microsoft Visual Studio 2010 you receive the following warning message:

The target version of the .NET Framework in the project does not match the .NET Framework launch condition version ‘.NET Framework 4 Client Profile’. Update the version of the .NET Framework launch condition to match the target version of the.NET Framework in the Advanced Compile Options Dialog Box (VB) or the Application Page (C#, F#).

Cause:

When you add a Setup project to your solution Microsoft Visual Studio 2010 sets two default values that usually don’t match the project settings: prerequisites and launch condition.

These are both set to “.NET Framework 4 Client Profile” and if you set your project’s target framework to “.NET Framework 4” you get the warning message above.

(See the How to solve “The version of the .NET Framework launch condition ‘.NET Framework 4′ does not match…” warning in Microsoft Visual Studio post to handle the error with the incorrect prerequisites.)

Solution:

Change the launch condition in the Setup project:

  • Right click the Setup project,
  • Select “View”, “Launch Conditions”,
  • Expand the “Launch Conditions”,

VS Prerequisites Setup Launch Condition

  • Right click the .NET Framework and select “Properties Window”,
  • In the Properties window set the Version to “.NET Framework 4”.

VS Prerequisites Setup LaunchCondition Properties

 

How to solve “The version of the .NET Framework launch condition ‘.NET Framework 4’ does not match…” warning in Microsoft Visual Studio

When you build the setup project in Microsoft Visual Studio 2010 you receive the following warning message:

The version of the .NET Framework launch condition ‘.NET Framework 4’ does not match the selected .NET Framework bootstrapper package. Update the .NET Framework launch condition to match the version of the .NET Framework selected in the Prerequisites Dialog Box.

Cause:

When you add a Setup project to your solution Microsoft Visual Studio 2010 sets two default values that usually don’t match the project settings: prerequisites and launch condition.

These are both set to “.NET Framework 4 Client Profile” and if you set your project’s target framework to “.NET Framework 4” you get the warning message above.

(See the How to solve “The target version of the .NET Framework in the project does not match…” warning message in Microsoft Visual Studio post to handle the problem with the incorrect launch conditions.)

Solution:

Set the prerequisites to “.NET Framework 4”

VS Prerequisites Setup

  1. Right click the Setup project,
  2. Select “Properties”,
  3. Select the “Release” configuration,
  4. Click the “Prerequisites…” button,
  5. Check “.NET Framework 4 (x86 and x64)”,
  6. Uncheck “.NET Framework 4 Client Profile (x86 and x64)”,
  7. Click OK,
  8. Select the “Debug” configuration,
  9. Repeat steps 4 – 7.

Solving “The type or namespace name … could not be found” error in Microsoft Visual Studio

When you compile a .NET 4.0 C# application the following error message appears:
The type or namespace name … could not be found (are you missing a using directive or an assembly reference?)

There is also a warning message :
The currently targeted framework “.NET Framework,Version=v4.0,Profile=Client” does not include “System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a” which the referenced assembly ….dll” depends on. This caused the referenced assembly to not resolve. To fix this, either (1) change the targeted framework for this project, or (2) remove the referenced assembly from the project.

Cause:
The project targets the .NET framework 4.0 Client profile, but some functionality in the referenced project is not supported by the Client profile.

Solution:
Set the Target Framework of you project to “.NET Framework 4.0”

  • In the Solution Explorer right click the project and select “Properties”,
  • On the “Application” page set the Target Framework to “.NET Framework 4.0”.