NuGet package restore failed Access to path is denied

This turned out to be a problem when NuGet packages are checked in to the source control system in folder packages.

The problem occurs when

  • Automatically restore missing NuGet packages is turned on in Visual Studio.
  • There are NuGet packages checked in to the source control system.
  • The TFS work space is a server work space.

When VS tries to restore NuGet packages, it will try to access the existing packages already in TFS, because the packages are read only as the workspace is a server workspace. VS will be denied access to the path to the package.

To solve this, either delete the existing packages, or turn off automatic package restore in Visual Studio.

The correct way is to have no packages checked in to the source control system, either keep the project up to date with NuGet, or create a local cache of packages.

Breakpoints cannot be hit when debugging C# in Visual Studio

When this happens, there can be a few reasons

-You attached to the wrong process.

-The build profile was changed to Release instead of Debug, thus no symbols are generated for debugging.

-You opened multiple instances of Visual Studio or programs that lock the PDB file, so when you make a new build the PDB file fails to be regenerated to match the new DLL.

-There are assemblies with classes with same name in the same namespace (for example DI may be configured to load different assemblies depending on some configuration). Visual Studio load the debug file for the wrong assembly when you are debugging some code. VS may assume that there is only one implementation of a a class in same namespace.

Steps to resolve

Make sure you attach to the correct process.

Make sure the build profile is Debug.

Clean and rebuild the solution.

If there are multiple assemblies with classes with the same name, try deleting the one that is not in use and then rebuild. Best option is to avoid classes with same name in same namespace. VS will be confused.

Last step, log out and log in again, or restart the computer to kill the processes that are locking the PDB. It could even be some Visual Studio bug.

Non-English characters become question marks when inserting into MySQL server in Ubuntu Linux server

This is because when the query is sent to MySQL, it’s encoded using the default charset, which is usually set to latin.

For some reason, it’s not a problem in Windows.

For PHP, when creating a connection to MySQL, call set_charset to set the character set to UTF8.

For ASP.NET Core application, set the charset in the connection string: CharSet=utf8.

Child component state not updated in Flutter.

It seems that when child component has its own state which is created by passing from the parent component’s state, if the parent component changes the state and try to re-create the child component with this new state passing in as a parameter for the constructor, the child somehow still uses its old state.

Maybe the rule of thumb is, state should only be changed by the direct owner of the state, not the containers?

Anyway I solved this issue by converting the child component into a StatelessWidget in Flutter, still trying to get my head around this Unidirection data flow pattern created by React.

Unit testing code using Entity Framework Core

https://docs.microsoft.com/en-us/ef/core/miscellaneous/testing/

I tried to use Moq to mock the DbContext and IQueryable<>, but it seems to be really complicated. It’s also not recommended by Microsoft.

For unit testing, it’s recommended to use a real database, perhaps using an in-memory database or a temporary sqlite database. Whatever the type of database you use, install the required NuGet package.