Unable to connect to MySQL on ASP.Net Core 2.0 - mysql-connector

I created a new Asp.Net core 2.0 project, added MySql.Data
When I try:
mySqlConnection.Open();
then this exception occurs:
An unhandled exception occurred while processing the request.
FileNotFoundException: Could not load file or assembly 'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. O sistema não pode encontrar o arquivo especificado.
MySql.Data.MySqlClient.MySqlConnectAttrs.get_OSDetails()
TargetInvocationException: Exception has been thrown by the target of an invocation.
System.RuntimeMethodHandle.InvokeMethod(object target, Object[] arguments, Signature sig, bool constructor)
I searched and did not find System.Management on NuGet for ASP.Net Core.
Also on the Dependencies (References),
This shows on:
Package 'MySql.Data.6.9.9' was restored using
'.NETFramework,Version=v4.6.1' instead of the project target framework
'.NETCoreApp,Version=v2.0'. This package may not be fully compatible
with your project.
How to connect to MySQL using Nuget on this situation?

For the .net core only the pre-release nugets work. As of now the latest version is 8.0.8-dmr. To access these you can either check the "include prereleases" option in your nuget manager or for packet manager you can use:
Install-Package MySql.Data -Version 8.0.8-dmr
Or on CLI you can use:
dotnet add package MySql.Data --version 8.0.8-dmr

Related

Using VS2019, .Net 5.0, Winforms.Wasm 1.0.19137.60 Nuget package - produces unhandled Mono.Cecil.AssemblyResolutionExceptions

I am trying to port 6 class libraries developed under .Net 4.5.2 to .Net 5.00 using VS 2019. I chose .Net 5.00 (and VS 2019) as my final goal is to deliver the solution as a web assembly. I have set the target framework for each of the libaries to .NET 5.0.
One of my class libraries uses Winforms so I have downloaded the Nuget package Winforms.Wasm (1.0.191137.60) by Roozbeh Gh into VS 2019.
On building I initially got the error:
1>C:\Users\howar_000\.nuget\packages\winforms.wasm\1.0.19137.60\build\netstandard2.0\Winforms.Wasm.targets(13,5): error :
Unhandled Exception: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Windows.Forms, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
... at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
... at Driver.Import(String ra, AssemblyKind kind)
... at Driver.Run(String[] args)
... at Driver.Main(String[] args)
I was able to get past this problem by adding:
<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
as per instructions I found on the Winforms.Wasm GIT repository recommended by Roozbeh Gh.
1>C:\Users\howar_000\.nuget\packages\winforms.wasm\1.0.19137.60\build\netstandard2.0\Winforms.Wasm.targets(13,5): error :
Unhandled Exception: Mono.Cecil.AssemblyResolutionException: Failed to resolve assembly: 'System.Formats.Asn1, Version=5.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' 1>C:\Users\howar_000\.nuget\packages\winforms.wasm\1.0.19137.60\build\netstandard2.0\Winforms.Wasm.targets(13,5): error : at Mono.Cecil.BaseAssemblyResolver.Resolve(AssemblyNameReference name, ReaderParameters parameters)
... at Driver.Import(String ra, AssemblyKind kind)
... at Driver.Import(String ra, AssemblyKind kind)
... at Driver.Import(String ra, AssemblyKind kind)
... at Driver.Import(String ra, AssemblyKind kind)
... at Driver.Run(String[] args)
i.e. it just moved the problem along to another library distributed along with Winforms.Wasm. I have also tried to explicitly exclude the Nuget version of the System.Formats.Asn.dll but this hasnt worked either.
I realise the problem is that the Nuget Winforms.Wasm package includes netstardard2.0 libraries so that the package download is as a complete standalone distribution. Further that VS 2019 MSBuild is identifying a clash with the dotnet net5.0 distribution.
I have done a lot of investigation trying to resolve this problem - even overwriting
C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\5.0.0\ref\net5.0\System.Formats.Asn1.dll
with
C:\Users\howar_000.nuget\packages\system.formats.asn1\5.0.0\lib\netstandard2.0\System.Formats.Asn1.dll
and visa versa but to no avail.
But reading through swathes of literature on the web, I came to the realisation that this is a recurring problem that has plagued developers trying to use VS with .Net and Nuget packages for some time. Surely either Microsoft need to change the implementation of VS MSBuild to accommodate Nuget packages or Nuget package writers need to come up with a VS compliant distribution - rather than leaving developers spending many hours trying to establish work arounds and understand the inner works of VS MSBuild.
I am thinking of moving away from VS 2019 to use the Mono Developer toolkit - I will let you know how I get on.
Any help/suggestions on how best to migrate .Net 4.5.2 assemblies that use Nuget packages to equivalent web assemblies would be much appreciated.

.NET Core Azure Function missing reference

I've added a Nuget-package to my .NET Core "Azure Function"-project:
Install-Package SharePointPnPCoreOnline -Version 2.22.1801
But I receive an error in my code:
Microsoft.Azure.WebJobs.Host.FunctionInvocationException : Exception
while executing function: StoreInDatabase --->
System.IO.FileNotFoundException : Could not load file or assembly
'SharePointPnP.IdentityModel.Extensions, Version=1.2.3.0,
Culture=neutral, PublicKeyToken=5e633289e95c321a' or one of its
dependencies. The system cannot find the file specified.
This assembly should be included from the Nuget Package, but it doesn't.
As I'm new to .NET Core and Azure Functions, does anyone know how to solve this one?
Update
I see the package has another version number than in the error-details.
But still no idea how to solve this... any ideas?
Looking at the nuget package with the wrong version number, I saw that previous versions are "hidden" in NuGet...
https://www.nuget.org/packages/SharePointPnP.IdentityModel.Extensions/
I solved this by installing the latest version of the package
So in my case, I just ran the command:
Install-Package SharePointPnP.IdentityModel.Extensions -Version 1.2.3

Matlab .Net Assembly compatible with .Net Core1.1

I am trying to use Matab module compiled as .Net assembly in a .Net Core Project, but I receive the following exception:
Unhandled Exception: System.IO.FileNotFoundException: Could not load
file or ass embly 'MWArray, Version=2.17.1.0, Culture=neutral,
PublicKeyToken=e1d84a0da19db8 6f'. The system cannot find the file
specified. at ConsoleAppCore1._1.Program.Main(String[] args)
MCR_R2017b_win64_installer.exe is installed on the system and I am able to load same Matlab module in .Net4.5 project.
Any clue to make it work with .Net Core1.1?
Simply NO - mathworks supports only "classic"/desktop .net framework on Windows platforms
Please refer to this: mathworks doc

TypeInitializationException accessing MonoGame GraphicsAdapter.Adapters, could not load type 'SharpDX.Rectangle'

Converting VB code from XNA 3.1 to MonoGame.
Any attempt to access class GraphicsAdapter throws the exception below. For example, trying to enumerate GraphicsAdapters. On this line:
For Each adapter As GraphicsAdapter In GraphicsAdapter.Adapters
Result is an exception:
System.TypeInitializationException occurred
HResult=-2146233036
Message=The type initializer for 'Microsoft.Xna.Framework.Graphics.GraphicsAdapter' threw an exception.
Source=MonoGame.Framework
TypeName=Microsoft.Xna.Framework.Graphics.GraphicsAdapter
StackTrace:
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter.get_Adapters()
at ...my code...
InnerException:
HResult=-2146233054
Message=Could not load type 'SharpDX.Rectangle' from assembly 'SharpDX, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1'.
Source=MonoGame.Framework
TypeName=SharpDX.Rectangle
StackTrace:
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter.CreateAdapter(Adapter1 device, Output monitor)
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter.PlatformInitializeAdapters(ReadOnlyCollection`1& adapters)
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter..cctor()
Note the inner exception:
Could not load type 'SharpDX.Rectangle' from assembly 'SharpDX, ...Version=4.0.1.0, ...
The project references these assemblies (among others):
MonoGame.Framework version=3.6.0.1625
from NuGet "MonoGame.Framework.WindowsDX", file
packages\MonoGame.Framework.WindowsDX.3.6.0.1625\lib\net40\MonoGame.Framework.dll
SharpDX version=4.0.1.0
SharpDX.Direct2D1 version=4.0.1.0
SharpDX.Direct3D9 version=4.0.1.0
SharpDX.DXGI version=4.0.1.0
SharpDX.Mathematics version=4.0.1.0
So I don't see why it would fail this way.
What could be wrong? Not compatible with this SharpDX version?
NOTE: These are all up-to-date packages from NuGet, in Visual Studio 2015. Targeting .Net 4.5.2.
UPDATE
To prove it isn't a problem with SharpDX, I put this line before that GraphicsAdapter line:
Dim testRect As SharpDX.Rectangle = New Rectangle()
This successfully created testRect. No Exception until attempt to access GraphicsAdapter. Also tried all the other Shared (static) properties of GraphicsAdapter, such as GraphicsAdapter.DefaultDevice. Any one fails with same exception.
I posted the same question to MonoGame forums:
http://community.monogame.net/t/solved-typeinitializationexception-accessing-graphicsadapter-adapters-could-not-load-type-sharpdx-rectangle/9803
Cause of problem:
Current release of MonoGame.Framework for WindowsDX (Windows OS + DirectX drivers), 3.6.0.1625 is built against SharpDX 2.6.3, and is not compatible with more recent SharpDX versions.
(Interim) Solution:
The developer branch of MonoGame does target the current SharpDX. Builds can be obtained from MonoGame's teamcity (free registration required).
Tested MonoGame.Framework build 3.7.0.994; it worked with SharpDX 4.0.1:
http://teamcity.monogame.net/viewLog.html?buildId=56483&tab=artifacts&buildTypeId=MonoGame_PackagingWindows
That build installs most SharpDX dlls to
C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows
However, SharpDX.Mathematics.dll is currently missing,
so I still install SharpDX from NuGet, rather than using those.
Standard location for MonoGame releases:
(look for at least 3.7, which is not there yet, as I write this):
http://www.monogame.net/downloads/
(If instead of NuGet packages for MonoGame and SharpDX, I had downloaded MonoGame 3.6 installer and used its version of SharpDX dlls at C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows, then I would not have had this incompatibility. However, that was not recent enough SharpDX for my purposes. This should be resolved by release of MonoGame 3.7)

Entity Framework 7 with Universal Windows Platform Add-Migration

I'm trying to implement Universal Windows Platform application with EntityFramework and SQLite (according to: http://ef.readthedocs.org/en/latest/platforms/uwp/getting-started.html) but I have problem with Add-Migration command.
Here is my setup:
Visual Studio 2015 Update 1
EntityFramework.SQLite: "7.0.0-rc1-final"
Error that I got while adding migrations is:
Could not load file or assembly 'System.Collections.Immutable, Version=1.1.36.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
Thanks in advance for your help!
It is clearly that you miss a dll "System.Collections.Immutable, Version=1.1.36.0" in your project.
To solve this problem, you can open the Nuget tool, and search for System.Collections.Immutable, then in the "Version" label select the Version 1.1.36, by default it is the latest version 1.1.37.
You can also try to update your VS tool, this possible may also solve your problem.