I'm trying to swap database providers out in .NET code to MariaDB. As part of that, I'm trying to open a MySqlConnection. This in turn results in an argument null execption with a message of: "Value cannot be null. Parameter name: element" and the following call stack:
mscorlib.dll!System.Attribute.GetCustomAttributes(System.Reflection.Assembly element, System.Type attributeType, bool inherit) Line 756 C#
mscorlib.dll!System.Attribute.GetCustomAttribute(System.Reflection.Assembly element, System.Type attributeType, bool inherit) Line 814 C#
mscorlib.dll!System.Reflection.CustomAttributeExtensions.GetCustomAttribute<System.Runtime.Versioning.TargetFrameworkAttribute>(System.Reflection.Assembly element) Line 27 C#
> MySql.Data.dll!MySql.Data.MySqlClient.MySqlConnectAttrs.InitFramework() Unknown
MySql.Data.dll!MySql.Data.MySqlClient.MySqlConnectAttrs.MySqlConnectAttrs() Unknown
[Native to Managed Transition]
[Managed to Native Transition]
MySql.Data.dll!MySql.Data.MySqlClient.NativeDriver.SetConnectAttrs() Unknown
MySql.Data.dll!MySql.Data.MySqlClient.Authentication.MySqlAuthenticationPlugin.Authenticate(bool reset) Unknown
MySql.Data.dll!MySql.Data.MySqlClient.NativeDriver.Authenticate(string authMethod, bool reset) Unknown
MySql.Data.dll!MySql.Data.MySqlClient.NativeDriver.Open() Unknown
MySql.Data.dll!MySql.Data.MySqlClient.Driver.Open() Unknown
MySql.Data.dll!MySql.Data.MySqlClient.Driver.Create(MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) Unknown
MySql.Data.dll!MySql.Data.Failover.FailoverManager.AttemptConnection(MySql.Data.MySqlClient.MySqlConnection connection, string originalConnectionString, out string connectionString, bool mySqlPoolManager) Unknown
MySql.Data.dll!MySql.Data.MySqlClient.MySqlConnection.Open() Unknown
(My code below this point)
I'm using a connection string similar to:
<add name="MyMariaDatabase" connectionString="server=myservername.rds.amazonaws.com;port=3306; database=mydb;uid=myuser; pwd=mypassword" providerName="MySql.Data.MySqlClient" />
Sample connection code:
using (var client = new MySql.Data.MySqlClient.MySqlConnection(connStr))
{
client.Open();
var result = client.ExecuteScalar(someSqlStatement);
}
This is all running in .NET Framework 4.7.2 and MySQL.Data 8.0.19.
Any idea what's going wrong? The error seems deep inside the framework and it's not giving me helpful information.
You're encountering bug 95242, a known problem in Oracle's MySQL Connector/NET (aka MySql.Data).
I would recommend switching to MySqlConnector, an OSS MySQL and MariaDB client library. As well as fixing many bugs in Connector/NET and adding true async I/O support, it is independent of Oracle so it has support for MariaDB-specific features such as the GSSAPI authentication plugin and batch support.
Your Port must be seperated by semicolon.
Instead of
"server=myservername.rds.amazonaws.com,3306; database=mydb;uid=myuser; pwd=mypassword"
use this Connenction string
"Server=myservername.rds.amazonaws.com;Port=3306;Database=mydb;Uid=myuser;Pwd=mypassword;"
Related
I have a Xamarin.Forms UWP app (Xamarin.Forms v3.4.0.1008975, UWP target/min version 16299, VS 2017 15.9.11). When compiled without the .net native tool chain it builds and runs correctly. When compiled with the .net native tool chain it builds fine but at run time it fails. This is an issue because I cannot release the app to the windows store. This app has previously (~10 months ago) been released to the store and worked correctly. There has been an extensive overhaul since then with updated versions of XF, Prism, sqlite packages and the addition of a couple of other packages amongst many other changes so it's nearly impossible to work out what change might have caused it.
I managed to get past some initial problems with the Rg.Plugins.Popup and Xam.Plugin.Iconize.FontAwesome packages by getting a list of assemblies for them and passing them into Xamarin.Forms.Forms.Init(e, assemblies); in App.xaml.cs in the UWP project. This fixed crashes/display issues with popups and font icons in my app.
When the app starts up I am seeing several handled FileNotFoundException on the Xamarin.Forms.Forms.Init(...) call of the form Cannot load assembly 'clrcompression'. No metadata found for this assembly.. The missing assemblies are:
clrcompression
e_sqlite3
libEGL
libGLESv2
libSkiaSharp
SkiaSharp.Views.Interop.UWP
sqlite3
As said these errors are handled and only seen when debugging. I've not seen any definite evidence that these errors are a problem as the app is definitely reading some data from Sqlite without error and I'm seeing images drawn correctly with SkiaSharp.
However I am getting other run time errors when I perform a certain actions that are crashing the app. For example Unhandled exception at 0x05F8F74C (SharedLibrary.dll) in MyApp.UWP.exe: 0x00001007. occurred. If I look in the threads window I get a bit more information:
Not Flagged > 13884 0 Worker Thread <No Name>
System.Private.SharedLibrary.Interop.Generated.dll!__Interop.api_ms_win_core_kernel32_legacy_l1_1_0_dll.PInvoke_RaiseFailFastException
System.Private.SharedLibrary.Interop.Generated.dll!__Interop.api_ms_win_core_kernel32_legacy_l1_1_0_dll.PInvoke_RaiseFailFastException(Interop._EXCEPTION_RECORD* pExceptionRecord, System.IntPtr pContextRecord, uint dwFlags)
System.Private.CoreLib.dll!Interop.mincore.PInvoke_RaiseFailFastException(Interop._EXCEPTION_RECORD* pExceptionRecord, System.IntPtr pContextRecord, uint dwFlags)
System.Private.CoreLib.dll!Interop.mincore.RaiseFailFastException(uint faultCode, System.IntPtr pExAddress, System.IntPtr pExContext) Line 122
System.Private.CoreLib.dll!System.RuntimeExceptionHelpers.FailFast(string message, System.Exception exception, System.RuntimeExceptionHelpers.RhFailFastReason reason, System.IntPtr pExAddress, System.IntPtr pExContext) Line 237
System.Private.CoreLib.dll!System.RuntimeExceptionHelpers.RuntimeFailFast(System.RuntimeExceptionHelpers.RhFailFastReason reason, System.Exception exception, System.IntPtr pExAddress, System.IntPtr pExContext) Line 200
[External Code]
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBufferInternal<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context, ref System.Runtime.RuntimeImports.ConservativelyReportedRegionDesc regionDesc)
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBuffer<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context)
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.CallConversionThunk(System.IntPtr callerTransitionBlockParam, System.IntPtr callConversionId)
[External Code]
Prism.dll!Prism.Mvvm.BindableBase.SetProperty<int?>(ref int? storage, int? value, string propertyName)
[External Code]
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.CallDescrWorker(System.IntPtr callDescr) Line 970
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.InvokeTarget(void* allocatedStackBuffer, ref Internal.Runtime.TypeLoader.CallConversionParameters conversionParams)
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBufferInternal<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context, ref System.Runtime.RuntimeImports.ConservativelyReportedRegionDesc regionDesc)
System.Private.CoreLib.dll!Internal.Runtime.Augments.RuntimeAugments.RunFunctionWithConservativelyReportedBuffer<Internal.Runtime.TypeLoader.CallConversionParameters>(int cbBuffer, System.IntPtr pfnTargetToInvoke, ref Internal.Runtime.TypeLoader.CallConversionParameters context)
System.Private.TypeLoader.dll!Internal.Runtime.TypeLoader.CallConverterThunk.CallConversionThunk(System.IntPtr callerTransitionBlockParam, System.IntPtr callConversionId)
[External Code]
MyApp.dll!MyApp.ViewModels.AppLevel.AppStatusViewModel.CurrentSynchroniseJobTasksCount.set(int? value) Line 415
MyApp.dll!MyApp.ViewModels.AppLevel.AppStatusViewModel.HandleDataSyncStartEvent(string payload) Line 287
[External Code]
MyApp.dll!MyApp.Services.Synchronisation.DataSyncCoordinator.DoSynchronisationJob() Line 84
MyApp.dll!MyApp.Services.Synchronisation.DataSyncCoordinator.AttemptSynchronisationTask(MyApp.Services.Synchronisation.IDatabaseSyncJob job) Line 74
MyApp.dll!MyApp.Services.Synchronisation.DataSyncService.DeleteLocalData(string dbResetKey) Line 29
MyApp.dll!MyApp.ViewModels.ClearLocalDataPopupViewModel.Submit() Line 66
[Resuming Async Method]
[External Code]
Unfortunately while this tells me where the problem is happening it doesn't give me any clues as to why it's happening and how I might fix it. In this case it seems to be failing to set a property on a viewmodel but to even get to this point in the code it must have done this successfully in other places. I guess I'm really looking for guidance on how to investigate this/get more information as it's going to be hard to solve specific problems without some source code (which I cannot really provide). I have tried debugging with optimizations turned off which is often suggested but it's not provided any more information than I've posted here.
I'm also worried that even if I find out why this particular exception is happening and fix it that there might be many more issues in the app that only appear when .net native tool chain is used. Are there any tools I can use to help with this?
So this turned out to be an issue with Prism (7.0.0.396) and the .net native. It looks like binding properties with a nullable type (int? in this case) using BindableBase.SetProperty fail when compiled with the .net native tool chain. The following appears to fix this:
public class BindableBaseWithFix : BindableBase
{
protected virtual bool SetProperty<T>(ref T? storage, T? value, [CallerMemberName] string propertyName = null)
where T : struct
{
if (EqualityComparer<T?>.Default.Equals(storage, value))
return false;
storage = value;
RaisePropertyChanged(propertyName);
return true;
}
}
I'm working with SQLite. I am able to use entity framework 6.1.3 in my WPF application without problems, but when I update it to 6.2.0 I get the following error:
Test method DataAccessLayerTests.GenericDataRepositoryTests.CRUD_On_Pipe threw exception:
System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'SQLiteConnection'.
at System.Data.SQLite.SQLiteConnection.CheckDisposed()
at System.Data.SQLite.SQLiteConnection.get_State()
at System.Data.Entity.Internal.RepositoryBase.CreateConnection()
at System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(String contextKey)
at System.Data.Entity.Migrations.History.HistoryRepository.Exists(String contextKey)
at System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations)
at System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations()
at Core.DatabaseContext.CreateAndSeedIfNotExists`1.InitializeDatabase(T context) in C:\Users\roadrunner\propulsimcs\Propulsim\Core\DatabaseContext.cs:line 40
at System.Data.Entity.Internal.InternalContext.<>c__DisplayClassf`1.<CreateInitializationAction>b__e()
at System.Data.Entity.Internal.InternalContext.PerformInitializationAction(Action action)
at System.Data.Entity.Internal.InternalContext.PerformDatabaseInitialization()
at System.Data.Entity.Internal.LazyInternalContext.<InitializeDatabase>b__4(InternalContext c)
at System.Data.Entity.Internal.RetryAction`1.PerformAction(TInput input)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabaseAction(Action`1 action)
at System.Data.Entity.Internal.LazyInternalContext.InitializeDatabase()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Database.Initialize(Boolean force)
at Core.DatabaseContext..ctor() in C:\Users\roadrunner\propulsimcs\Propulsim\Core\DatabaseContext.cs:line 114
at DataAccessLayer.GenericDataRepository`1.GetAll(Expression`1[] navigationProperties) in C:\Users\roadrunner\propulsimcs\Propulsim\DataAccessLayer\GenericDataRepository.cs:line 16
at DataAccessLayerTests.GenericDataRepositoryTests.CRUD_On_Pipe() in C:\Users\roadrunner\propulsimcs\Propulsim\DataAccessLayerTests\GenericDataRepositoryTests.cs:line 34
Debug Trace:
Native library pre-loader is trying to load native SQLite library "C:\Users\roadrunner\propulsimcs\Propulsim\DataAccessLayerTests\bin\Debug\x86\SQLite.Interop.dll"...
Any ideas?
The problem is caused by a change in RepositoryBase class and incorrect (IMO) implementation of IDbConnection.State property by SQLiteConnection class (throwing ObjectDisposedException instead of returning ConnectionState.Closed when called on disposed object).
It's the same as reported in #398: NullReferenceException on Code First Migrations when Glimpse is installed. According to the status, it's already fixed in the EF6 repository, but unfortunately they decided to not provide patch, so you have to wait for v6.3. I've already reported the SQLite problem linking to this post, so hopefully they can change their mind.
Another option is to report the issue to SQLite development and wait a fix from there. In both cases, you have to wait for a fix in either SQLite or EF6 side. Note that the issue is reproducible even with the standard MigrateDatabaseToLatestVersion initializer.
I was able to workaround it by using the following ugly reflection hack:
public override void InitializeDatabase(T context)
{
base.InitializeDatabase(context);
var _historyRepository = migrator.GetType().GetField("_historyRepository", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(migrator);
var _existingConnection = _historyRepository.GetType().BaseType.GetField("_existingConnection", BindingFlags.Instance | BindingFlags.NonPublic);
_existingConnection.SetValue(_historyRepository, null);
var x = migrator.GetPendingMigrations();
if (x.Any())
{
migrator.Update();
Seed(context);
}
}
The original exception is gone, but now I'm getting another one saying 'No MigrationSqlGenerator found for provider 'System.Data.SQLite'. Use the SetSqlGenerator method in the target migrations configuration class to register additional SQL generators.' which I think is a different issue related to lack of MigrationSqlGenerator in SQLite EF services. It might or might not be a problem depending how did you solve that in 6.1.3.
Anyway, I would not recommend using the above hack. Either wait fox fix or downgrade to 6.1.3 for now.
The issue which also affected GlimpseDB is fixed: https://github.com/aspnet/EntityFramework6/pull/405
Waiting for a release now.
I have a long running i/o heavy (network/disk) multithreaded c# desktop application that sporadically crashes with "Stack cookie instrumentation code detected a stack-based buffer overrun."
A typical stack trace of the crashing thread is shown below.
The program runs for anywhere between 30 minutes and 6 hours before it typically crashes with a similar stack.
I have inspected the stack traces of the other application threads during a crash and haven't noticed any patterns.
I have considered that there may be a hardware issue, but there is much activity on the machine and no other signs of corruption (application crashes, event log errors, etc).
The C# application uses no unsafe blocks and no libraries that use unsafe blocks as far as I have determined.
Two questions:
Is it possible to get symbols for the System.ni.dll calls in the trace below?
How can I go about determining the cause of the crash? (My strongest suspicion is a framework bug.)
My system is i5-4790k (not overclocked), Windows 2012R2, targeting .net 4.6 x64, fully patched.
Visual studio 2015, fully patched.
Running the Debug build.
clr.dll!__report_gsfailure() Unknown
clr.dll!SafeHandle::Release(bool) Unknown
clr.dll!SafeHandle::Dispose(void) Unknown
clr.dll!SafeHandle::DisposeNative(class SafeHandle *) Unknown
System.ni.dll!00007ffa765ddc4b() Unknown
System.ni.dll!00007ffa765dda8a() Unknown
System.ni.dll!00007ffa765e7e0e() Unknown
System.ni.dll!00007ffa765c420f() Unknown
System.ni.dll!00007ffa765c41d4() Unknown
mscorlib.ni.dll!00007ffa7740f18a() Unknown
System.ni.dll!00007ffa76b19bbf() Unknown
System.ni.dll!00007ffa765e0d0b() Unknown
System.ni.dll!00007ffa7657ac4f() Unknown
System.ni.dll!00007ffa765e0508() Unknown
System.ni.dll!00007ffa765e0319() Unknown
System.ni.dll!00007ffa765e714d() Unknown
System.ni.dll!00007ffa765e6cdd() Unknown
System.ni.dll!00007ffa765e0157() Unknown
System.ni.dll!00007ffa765dfe48() Unknown
System.ni.dll!00007ffa765dfdb5() Unknown
System.ni.dll!00007ffa765dfa0d() Unknown
System.ni.dll!00007ffa765de83d() Unknown
System.ni.dll!00007ffa765de401() Unknown
System.ni.dll!00007ffa765de2e0() Unknown
System.ni.dll!00007ffa765dacac() Unknown
System.ni.dll!00007ffa765da9f0() Unknown
System.ni.dll!00007ffa765da22e() Unknown
System.ni.dll!00007ffa765d7fc7() Unknown
System.ni.dll!00007ffa765d743d() Unknown
System.ni.dll!00007ffa76579af6() Unknown
00007ffa19832eb7() Unknown
00007ffa1978eb0f() Unknown
00007ffa19844cfa() Unknown
00007ffa199e83d7() Unknown
00007ffa1978ce48() Unknown
00007ffa1978ccb5() Unknown
00007ffa199e810f() Unknown
mscorlib.ni.dll!00007ffa77d37116() Unknown
mscorlib.ni.dll!00007ffa77d22a90() Unknown
mscorlib.ni.dll!00007ffa77dfa795() Unknown
mscorlib.ni.dll!00007ffa773d2c97() Unknown
mscorlib.ni.dll!00007ffa773fa77e() Unknown
mscorlib.ni.dll!00007ffa773fa617() Unknown
mscorlib.ni.dll!00007ffa773d2f3d() Unknown
mscorlib.ni.dll!00007ffa773d2608() Unknown
mscorlib.ni.dll!00007ffa77386b50() Unknown
clr.dll!CallDescrWorkerInternal() Unknown
clr.dll!CallDescrWorkerWithHandler(struct CallDescrData *,int) Unknown
clr.dll!MethodDescCallSite::CallTargetWorker(unsigned __int64 const *) Unknown
clr.dll!QueueUserWorkItemManagedCallback(void *) Unknown
clr.dll!Frame::Push(void) Unknown
clr.dll!Frame::Push(void) Unknown
clr.dll!Frame::Push(void) Unknown
clr.dll!ManagedPerAppDomainTPCount::DispatchWorkItem(bool *,bool *) Unknown
clr.dll!ManagedPerAppDomainTPCount::DispatchWorkItem(bool *,bool *) Unknown
clr.dll!ThreadpoolMgr::ExecuteWorkRequest(bool *,bool *) Unknown
clr.dll!ThreadpoolMgr::WorkerThreadStart(void *) Unknown
clr.dll!Thread::intermediateThreadProc(void *) Unknown
kernel32.dll!BaseThreadInitThunk() Unknown
ntdll.dll!RtlUserThreadStart() Unknown
I faced a similar behavior. I suppose it is a bug in RyuJIT compiler. To avoid this you need to fallback to JIT64 using <useLegacyJit enabled="1" /> in app.config. Like this:
<runtime>
<useLegacyJit enabled="1" />
</runtime>
I've been hitting a wall over this for the last two days. In essence I have created UDT using Oracle tools for Visual Studio (ODAC 12c Release 3 and Oracle Developer Tools for Visual Studio (12.1.0.2.1)), added needed attributes.
The object I'm passing is an UDT object, having a collection of UDT which wraps around some properties.
As good as it works when pulling data from database it throws a fit when trying to pass UDT object as a parameter to stored procedure.
I checked all that came to mind:
- types;
- command configuration: type set to OracleType.Object (tried with array - no change);
And here is the error with the call stack:
"The invoked member is not supported in a dynamic assembly."
at System.Reflection.Emit.InternalAssemblyBuilder.get_Location()
at Oracle.DataAccess.Types.OracleUdt.GetAllReferencedAssemblies()
at
Oracle.DataAccess.Client.RegAndConfigRdr.setudtmapping(Hashtable&
s_mapUdtNameToMappingObj)
at Oracle.DataAccess.Types.OracleUdt.SetCustomTypeMappings()
at Oracle.DataAccess.Types.OracleUdt.GetUdtName(String
customTypeName, String dataSource)
at
Oracle.DataAccess.Client.OracleParameter.SetUDTFromCustomObject(OracleConnection
conn, IOracleCustomType customObj, Int32 i)
at
Oracle.DataAccess.Client.OracleParameter.PreBind_OracleObject(OracleConnection
conn)
at
Oracle.DataAccess.Client.OracleParameter.PreBind_Object(OracleConnection
conn)
at
Oracle.DataAccess.Client.OracleParameter.PreBind(OracleConnection
conn, IntPtr errCtx, Int32 arraySize)
at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
at OracleDatabaseHelper.OracleCommandEx.ExecuteNonQuery()
I want to read data into RSAParameters structure ( RSAParameters ) and did check twice, that the data is correct. But still, I get an error "invalid data" exception for this:
bei System.Security.Cryptography.CryptographicException.ThrowCryptogaphicException(Int32 hr)
bei System.Security.Cryptography.Utils._ImportKey(SafeProvHandle hCSP, Int32 keyNumber, CspProviderFlags flags, Object cspObject, SafeKeyHandle& hKey)
bei System.Security.Cryptography.RSACryptoServiceProvider.ImportParameters(RSAParameters parameters)
How can I take a look into the source code to check why _ImportKeys is throwing an exception? I have no experience with .dll 'decryption'..are there any symbols to reference somewhere for visual studio 8.0? Thank you.
Use .NET Reflector to disassemble the DLL you want to examine.
You can also use JetBrains dotPeek. It is 100% free.