[SOLVED]  Could not load file or assembly “Renci.SshNet.dll”- MySQL

Solved Could not load file or assembly 'Renci.SshNet, Version=2016.1.0.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106' or one of its dependencies?


In application development, it is important to ensure whether you are referencing an assembly with the correct version always, the worse cases sometimes could be an exception thrown like  - could not load file or assembly or one of its dependencies access is denied.

 
This is how I solved right below,

If you are reading this line, great are at the right spot. 

The solution is provided with step-by-step actions to solve assembly dependency errors. 

Let's get started, 

 

[SOLVED]  Could not load file or assembly “Renci.SshNet.dll”- MySQL

What happened before? 

As a developer, you would agree errors and solutions are part of lives always.

It was a day when meeting with one of our internal team heads, all the while demo an unexpected error popped out - the situation questions the reputation.

Yes, the same did happen to me only with the demo - no wonder why me always?

A quite few questions raised within but the answer is no at the time. Somehow managed to demo with the rest of the work and answered as expected.


So, What kind of questions raised within? 

Asking the right question - is the best way to solve anything before that's gonna happen later. 

The very simple question is -  "Will there be smoke without fire? 

apply that in this problem, yes without root causes it wouldn't be an error right in the application?


This is where I jumped in to find the root cause first before solving the problem and made me pull the answers for you.


That's all right - What is the project actually worked?

This is a desktop project developed in C#  Visual Studio and MySQL as the back-end.  

How I spot the issue?

After my demo came back to the desk, started running the project from Visual Studio (shortcut key F5)  

Now...What? 

MySQL connection is lost for no reason.

When initiating the connection.open() method and C# compiler throws an exception below. 

Could not load file or assembly 'Renci.SshNet, Version=2016.1.0.0, Culture=neutral, PublicKeyToken=1cee9f8bde3db106' or one of its dependencies. The system cannot find the file specified. 

What would you do usually as a developer? 

Yes when you are familiar with visual studio tools, these are a couple of things Clean and Build in the visual studio project solution. 

Because the Clean command clears the unused files and the Build command compiles the program that helps the error.

Un-doubtfully most of the time problems are resolved - but not in this case.

What would do next thing - Google?

Yes, Indeed Stack overflow helps a lot but not always. It's better to get our hands dirty to find get the solution.

Googled a lot and not much of help - that's what made me write down the answer here.

First thing, I checked whether MySQL client library mysql.data.client.dll exists in project solution or not - it exists as below image, which means you are progressing near a solution.

 

MySQL Client library
MySQL Client Library Marked



Nothing wrong to read error message - twice

Now I gazed at the exception message shown and noticed a particular keyword Renci.SshNet. So randomly searched at NuGet Package in Visual Studio and installed the library.

Here the root cause was,

MYSQL client library is missing its dependencies.
There are times during project development MySQL could not load assembly solved here 

Actions Step by Step 

 
1. Go to your Visual Studio Project Solution Explorer 
2. Right click on the References  - Image below round circle 1
3. Click on Manage NuGet Package References and click Browse
4. Search for Renci.SshNet.Async - image below round circle 2
5. Install and ReBuild the project solution
6. Now, try to initiate MySQL database connection will be successful

Just in case you have missed out on the steps above - it's okay here are images easy to follow numbers with a circle.

 

Right click on dll to add from Nuget Packages


Adding MySQL dependency dll reference



MySQL Renci.SshNet dll reference added


 

Summary  

This article describes the root cause MySQL client library missed its dependency and step by step actions to solve to save your time. And also using NuGet packages installation of Renci.SshNet.dll in application development. 


There are more articles related to MySQL