A
A
Andrey Strelkov2020-03-19 11:06:38
MySQL
Andrey Strelkov, 2020-03-19 11:06:38

How to use MySQL .NET Connector in Powershell?

Good afternoon, I'm trying to use .Net Connector for MySQL ( https://dev.mysql.com/downloads/connector/net/)
in a powershell script
But when I try to use MySQL.Data.dll I get an

Add-Type -Path "C:\temp\MySQL.Data.dll"

error:

Add-Type : Невозможно загрузить файл или сборку "file:///C:\temp\MySql.Data.dll" или один из зависимых от них компонентов. Сборка создана в более поздней версии среды выполнения чем текущая, и не может быть загружена.
строка:1 знак:9
+ Add-Type <<<<  -Path 'C:\temp\MySql.Data.dll'
    + CategoryInfo          : NotSpecified: (:) [Add-Type], BadImageFormatException
    + FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.AddTypeCommand


As I understand it, the library used is compiled for an older version, but why?

Windows 7, Net Framework 4.7 installed
$psversiontable.psversion shows that I have powershell version 2.

What is wrong with my configuration to use this library?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
azarij, 2020-03-19
@azarij

I would start by upgrading to 5.1 or 7.0, but 7.0 is completely fresh and has its own nuances.
download windows management framework 5.1 and install. then try again.
ps and if the update does not help, then try loading the library like this:

[void][system.reflection.Assembly]::LoadFrom("C:\temp\MySQL.Data.dll")

M
MaxKozlov, 2020-03-19
@MaxKozlov

Windows 7, Net Framework 4.7 installed
$psversiontable.psversion shows that I have 2nd version of powershell

PSv2 is based on .Net2 - that's why the assembly is not loaded
, just install a new PS,
or look for the version of the library under Net2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question