I have a problem with the dll Oracle.DataAccess : on my workstation I have a client installed and on some server I have an other one. At the runTime I catch a
System.TypeInitializationException: The type initializer for
'Oracle.DataAccess.Client.OracleConnection' threw an exception. --->
Oracle.DataAccess.Client.OracleException: The provider is not compatible with the version of Oracle client
at Oracle.DataAccess.Client.OracleInit.Initialize()
at Oracle.DataAccess.Client.OracleConnection..cctor()
--- End of inner exception stack trace ---
at Oracle.DataAccess.Client.OracleConnection..ctor(String connectionString)
In the catch clause, I would like to unload the current dll and load an other location (set in the config file).
Is it possible? And more than that, is it the good way of solving this problem?
One of the way to deal with it - abstract your oracle data access. Create two assemblies, each has reference to specific ODP. Determine which client installed or attempt to loading assemblies one by one until success and work trough your interface. But the key is, your client software must know only the interface, but the implementation of your ODP communication will be abstracted.
And there are patterns for this - proxy, decorator... you choose
Related
I wrote a simple .net framework library that exposed itself to COM in the appropriate way and I could then create and use the library from VB6. This library did some calculation and read databases rows through Entity Framework.
I have written a .net 7 (Core) version of this library, which still uses EF (not EF Core) and when the library is used through a .net console app, does the same job as the original (i.e. the code is fundamentally working).
I have exposed this to COM by:
a. Adding the following to the .csproj
<EnableComHosting>true</EnableComHosting>
<PlatformTarget>x86</PlatformTarget>
b. Registering the resulting comhost dll
regsvr32 my-library.comhost.dll
c. Creating an instance of the object in VB6
Set obj = CreateObject("new:{C3BBD3C1-FED4-43B0-A9CE-38C356D2BA8E}")
The object is successfully created and when I call one of the exposed functions in the object the code starts executing within the .net library (I can attach and step through using Visual Studio) but when it gets to the point where the DbContext is being created, I get the following:
System.TypeInitializationException: 'The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.'
ConfigurationErrorsException: Configuration system failed to initialize
PlatformNotSupportedException: Operation is not supported on this platform.
I understand it is trying to say that in the current environment it is executing, it doesn't know what the target platform is supposed to be? I'm not sure what I should/could do about this to allow this issue to be resolved.
Edit 1:
Full exception details:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
Source=EntityFramework
StackTrace:
at System.Data.Entity.Internal.AppConfig.get_DefaultInstance()
at System.Data.Entity.Internal.LazyInternalConnection..ctor(DbContext context, String nameOrConnectionString)
at System.Data.Entity.DbContext..ctor()
at LibTest.Domain.Infrastructure.ConfigurationDbContext..ctor() in X:\SOURCE\WEBSERVE\1\LibTestCore\LibTestCore.Domain\Infrastructure\ConfigurationDbContext.cs:line 27
at LibTest.Domain.Configuration.Concrete.DbConfigurationRepository..ctor() in X:\SOURCE\WEBSERVE\1\LibTestCore\LibTestCore.Domain\Concrete\Configuration\DbConfigurationRepository.cs:line 12
at LibTest.Domain.Concrete.Configuration.LegacyConfigurationRepository..ctor()
at LibTest.Domain.Concrete.Legacy.ComInterface..ctor() in X:\SOURCE\WEBSERVE\1\LibTestCore\LibTestCore.Domain\Concrete\Legacy\ComInterface.cs:line 16
at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExceptions)
This exception was originally thrown at this call stack:
System.Configuration.ClientConfigPaths.ClientConfigPaths(string, bool)
System.Configuration.ClientConfigPaths.GetPaths(string, bool)
System.Configuration.ClientConfigurationHost.ConfigPaths.get()
System.Configuration.ClientConfigurationHost.GetStreamName(string)
System.Configuration.ClientConfigurationHost.IsAppConfigHttp.get()
System.Configuration.Internal.DelegatingConfigHost.IsAppConfigHttp.get()
System.Configuration.ClientConfigurationSystem.ClientConfigurationSystem()
System.Configuration.ConfigurationManager.EnsureConfigurationSystem()
Inner Exception 1:
ConfigurationErrorsException: Configuration system failed to initialize
Inner Exception 2:
PlatformNotSupportedException: Operation is not supported on this platform.
I am running a C# WinForms app. The goal of this small section of code is to copy the contents of a .JMP file into a .csv file for data manipulation. Easy enough right? I do not want to do this all in JMP or using a .jsl. The code for parsing and reformatting the data is already there for .csv files and has been working flawlessly.
The app that runs fine unless I have this one specific line that accesses the System.Windows.Clipboard class in my code:
Clipboard.SetDataObject(my data);
When I run the code with the line commented out all is well, but when I run them with the line included the app immediately goes into breakmode with these exceptions:
System.TypeInitializationException
HResult=0x80131534
Message=The type initializer for '<Module>' threw an exception.
Source=<Cannot evaluate the exception source>
StackTrace: Cannot evaluate the exception stack trace
Inner Exception 1:
ModuleLoadException: The C++ module failed to load during appdomain initialization.
Inner Exception 2:
TypeLoadException: Could not load type 'System.Windows.Media.DisableDpiAwarenessAttribute' from assembly 'WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
For Inner Exception 1, I am confused because this is a C# app in WinForms with no C++, don't know what the deal is here.
For Inner Exception 2, I am confused because the Assembly WindowsBase is for WPF and not WinForms. I am unable to even add a project reference to this WindowsBase assembly. Again, these errors only happen when I try to do anything with the System.Windows.Clipboard class.
I have downloaded, installed, and ensured the proper location of the following DLLs:
1. PresentationCore.dll
2. System.Windows.Forms.dll
Am I still missing some DLLs? Any help is appreciated.
You should use System.Windows.Forms.Clipboard instead of System.Windows.Clipboard, for the latter one is from WPF. You should remove the reference to PresentationCore.dll, because it's from WPF and not needed in WinForm.
tl;dr Q. "how do we successfully deploy [unmanaged library] libzmq to load dynamically to support 'ZeroMQ CLR namespace' being used in a C# program?"
C# code with NuGet pkg ZeroMQ 4.1.0.17 (Runtime version v4.0.30319; Version 4.1.0.42169) installed. Works just fine running in the Visual Studio workspace but when deployed with the .exe in the same directory as the ZeroMQ.dll and with an amd64 subdirectory containing both libzmq.dll and libsodium.dll -- and even with copies of both those copied up into the same exec directory as program and ZeroMQ.dll -- we get:
Connect System.TypeInitializationException: The type initializer for 'ZeroMQ.lib.zmq' threw an exception. ---> System.IO.FileNotFoundException: UnmanagedLibrary[libzmq] Unable to load library "libzmq" from "C:\Windows\TEMP\libzmq.dll". Inspect Trace output for details. ---> System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
--- End of inner exception stack trace ---
at ZeroMQ.lib.Platform.Win32.LoadUnmanagedLibrary(String libraryName)
at ZeroMQ.lib.zmq..cctor()
--- End of inner exception stack trace ---
at ZeroMQ.ZContext..ctor()
at Core.Adapter.ZeroMQ.ZeroMQMessagingService.Connect(String connection_string) in \ZeroMQMessagingService.cs:line 201
Note that is says it is looking in C:\Windows\TEMP but maybe that is only the last place in a chain.
We're getting this after upgrading to ZeroMQ 4.1.0.21 and failing to load the libzmq.dll as an "embedded resource", so we removed .21 completely and returned to .17. It had been working fine in .17 before we upgraded to .21.
Copy If Newer is checked on the amd64\libzmq.dll and libsodium.dll and, yes, this is an x64 build attempting to run on an x64 machine. The failing host is 2012 Server running .NET 4.5.
This turned out to be very simple. We are moving to a new machine still being configured and installing the C++ 2010 redistributable solved the problem for us.
I'm trying to use an external library with my code. I have added it as a reference from within Visual Studio and things like auto-complete works fine, I can see all the available methods while typing code. It also compiles without any warning or errors.
The DLL is within the same directory as the executable.
However, I get this error:
"Unhandled Exception: System.TypeInitializationException: The type initializer fo
r '<Module>' threw an exception. ---> System.DllNotFoundException: Unable to loa
d DLL 'yeppp': The specified module could not be found. (Exception from HRESULT:
0x8007007E)
at Yeppp.Library.yepLibrary_Init()
at Yeppp.Library.Init()
at .cctor()
--- End of inner exception stack trace ---"
What am I doing wrong?
http://docs.yeppp.info/cs/index.html#GettingStarted
You also need to deploy yeppp.dll as the article says.
We have over 1000 unit tests. A while ago 18 of them started to fail when they were run together with the other tests. These tests run a windows workflow.
If they are run alone they pass.
The error appears to be that it cannot find the connection string.
It cannot find the connection string because it does not know which config file to look in.
It does not know which config file to look in because it cannot find the application context
And it cannot find the application context due to a compilation lock.
Anybody have any idea what could be wrong, and how to fix this? The error I am getting is:
Message: Exception message: The
supplied connection string is not
valid, because it contains
insufficient mapping or metadata
information. Parameter name:
connectionString Inner exception :
System.InvalidOperationException:
Unable to determine application
context. The ASP.NET application path
could not be resolved. --->
System.Reflection.TargetInvocationException:
Exception has been thrown by the
target of an invocation. --->
System.Web.HttpException: The type
initializer for
'System.Web.Compilation.CompilationLock'
threw an exception. --->
System.TypeInitializationException:
The type initializer for
'System.Web.Compilation.CompilationLock'
threw an exception. --->
System.NullReferenceException: Object
reference not set to an instance of an
object. at
System.Web.Compilation.CompilationLock..cctor()
--- End of inner exception stack trace --- at System.Web.Compilation.CompilationLock.GetLock(Boolean&
gotLock) at
System.Web.Compilation.BuildManager.EnsureTopLevelFilesCompiled()
Thanks
Shiraz
Since you mention that your tests run a WF workflow, I would guess that a previous test run has one or more workflow instances that still run on a thread somewhere, thus locking the compiler because the assemblies are still loaded in a process somewhere.
Can you open Task Manager and investigate whether there's a running process that still uses the workflow somewhere? If so, kill it and see if you can't compile.