1
Answer

Issue with Azure Function and MySQL Connection

Punar Dutt Rajput

Punar Dutt Rajput

Sep 10
494
1

I have created an Azure Function using C# and I'm trying to connect it to a MySQL database. However, when I attempt to establish the connection, I encounter the following error:

System.Private.CoreLib: Exception while executing function: Function1.
MySql.Data: Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
The system cannot find the file specified.
Bash

Has anyone faced a similar issue or know how to resolve this?

Answers (1)
4
Aman Gupta

Aman Gupta

37 35.2k 2.5m Sep 10

Hi Punar Datt,

This error often occurs because the required dependencies for MySQL are not properly included in the Azure Function project or the correct version is not available.

I also faced this type of issue and by following changes I succeeded to resolve.

1. Check your MySQL NuGet Package version: you need to ensure that you're using the correct version of the MySql.Data NuGet package  also need to install the MySqlConnector if you're using it.

2. Ensure the DiagnosticSource package is included: The error you mentiond i.e System.Diagnostics.DiagnosticSource. This indicates that your project is missing this package or has an incorrect version. 

3. Update Azure Functions Runtime: Ensure your Azure Functions runtime version is compatible with the version of the MySql.Data library you're using. You can set the runtime version in the host.json file or you can update it via Azure Portal.

These steps can be helpful for you, I made my issue resolve by using 1 and 2 solutions.

Thanks

Accepted