visual studio

Could Not Load File or Assembly in Release Configuration

Problem:

Solution:


Windows Service Cannot Uninstall Due To Installer Desynchronization

Use Fix problems that block programs from being installed or removed

or

sc delete "Service Name"

Migration Fails When Using Complex Types in AddOrUpdate

AddOrUpdate( p => new { p.Nombre, p.ProcesoID } cannot be used with EntityFramework < 6.2.0

When using scaffolding, visual studio automatically updates EntityFramework to 6.1.3.

You need to upgrade EntityFramework to at least 6.2.0 after scaffolding.

Windows Service Fails To Find Connection String

I  copied+pasted a windows service and a windows service setup projects from one solution to another. Then I changed the connection strings in the app.config file and changed the project references.  Then when I run the service and try to get data from the database I get the following error:

System.InvalidOperationException: No connection string named 'Context' could be found in the application config file.

Yet the connection string named 'Context' was present in the application config file.

The solution at the end was to create the windows service and a windows service setup projects from scratch.


Windows Service Fails To Find Connection String "Flip Out" Version

I needed to add a new connection string to app.config to connect to a new database. The changes were not applied, despite the connection string is in app.config!!! I got the error "System.InvalidOperationException: No connection string named 'Context' could be found in the application config file.". 

I realized that in  MyService\bin\Debug there's a file MyService.exe.config that should have the connection strings listed as they appear in app.config. Instead, it still has the old list.

By chance, I realice that I have a warning to update a nuget package (Newtonsoft.JSON) with a potential security risk! I update the package, build the windows service setup project and voilà, the new connection string works!

When Debugging Windows Service Throws Errror System.InvalidOperationException: The model backing the 'Context' context has changed since the database was created. Consider using Code First Migrations to update the database 

In this case the connection string points to a database in LocalDB and the database is up to date with migrations. 

The error is misleading.  The real error is that you need to set up an account with sufficient privileges for LocalDB access.

Even though the project installer has LocalSystem permissions, when debugging you need to set up an account with sufficient privileges.

Go to Services -> YourService -> double click -> LogIn -> Select "This account"  -> enter credentials for the account with sufficient privileges