Migrating .net 2.0 console application on win 2008 r2 - c#

I have some old 32bit console .NET 2.0 applications that should be migrated to win2008 r2 server.
Note 1: I have one old 32bit application that doesn't load any assembly and is working correctly.
Note 2: When I start one of the applications I get
System.BadImageFormatException Could not load file or assembly error
Note 3:
Each of them are using NLog version 0.9.0.0. When I start these applications on our new server, I get following exception in nLOG.txt:
Error Could not load platform specific extensions: System.NullReferenceException: Object reference not set to an instance of an object.
at NLog.FilterFactory.AddFiltersFromAssembly(Assembly theAssembly, String prefix)
at NLog.Config.XmlLoggingConfiguration.LoadExtensionsFromAssembly(Assembly asm, String prefix)
at NLog.Config.XmlLoggingConfiguration.RegisterPlatformSpecificExtensions(String name)
Can you please help us how to solve this problem? Thank you in advance.
Deveti Putnik

Go to your project settings, and make sure you build your target to 32-bit (x86), and "All Platforms".
The problem you're seeing is a 64-bit executable trying to access a 32-bit DLL. .NET executables by default run as 64-bit on 64-bit OSes.

For point 3:Why not Upgrade NLog to 2.0, For point 2: "System.BadImageFormatException Could not load file or assembly for which assembly" can you find out assemby name causing this problem,it should be there in error message

Related

The type initializer for 'Sap.Data.Hana.HanaConnection' threw an exception. ---> System.IO.FileNotFoundException: Cannot find libADONETHDB.dll

I have a problem only on a specific machine.
I have two programs with a reference to Sap.Data.Hana.v4.5.dll, the ADO.NET Provider for .NET 4.5 for HANA database.
When my programs instantiates a connection object with
dbConnection = new HanaConnection(...);
I get this error:
System.TypeInitializationException: The type initializer for 'Sap.Data.Hana.HanaConnection' threw an exception. ---> System.IO.FileNotFoundException: Cannot find libADONETHDB.dll.
at Sap.Data.Hana.HanaUnmanagedDll.SearchNativeDlls(String regKeyName)
at Sap.Data.Hana.HanaUnmanagedDll..ctor()
at Sap.Data.Hana.HanaUnmanagedDll.get_Instance()
at Sap.Data.Hana.HanaConnection..cctor()
--- End of inner exception stack trace ---
at [...my program calls...]
Why can't it find libADONETHDB.dll?
My applications are build one in 32-bit, the other in 64-bit.
On this machine I installed SAP HANA client 2.8.20.23662 (latest version) both 32-bit and 64-bit.
The file that cannot be found seems to exist:
You could use Process Monitor while running the relevant part of the program to see, which file is missing and the path it should be in. Exclude all other events than file events and filter out all SUCCESS messages.
Perhaps it is referenced relative to the calling DLL (where Sap.Data.Hana.HanaUnmanagedDll.SearchNativeDlls is defined).
My hipotesis is that GAC had been corrupted with version 1 of Sap.Data.Hana.v4.5.dll:
Probably in the past HANA Client version 1 had been installed and removed and uninstallation hadn't cleaned the GAC.
My program uses HANA Client of any version, works both with version 1 and 2. For some reason when they start they seem to take version 1 of Sap.Data.Hana.v4.5.dll in the GAC. Process Monitor (thanks #sc911) confirms it:
This .NET DLL then looks for some unmanaged DLLs in C:\Program Files (x86)\hdbclient. Version 1 seems to look for libADONETHDB.dll in root folder.
But currently in this machine in that folder we have HANA Client 2.x and its folder structure is quite different from that of version 1 (there is no libADONETHDB.dll in root folder).
Hence the error in this question.
All this is valid both for 32-bit and 64-bit HANA Client.
I solved renaming or deleting version 1 folder in C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Sap.Data.Hana.v4.5 (probably there are better ways for performing this cleanup).

C# Class Library throws FileNotFoundException while trying to load another library

I try to connect to a fiscal device with a C#.
I use this documentation to do so: http://integration.atol.ru/api-en/#connection-to-project
So basically I have a driver of the device installed on my PC (fprt10.dll) and there is a "wrapper" assembly that allows me to work with this driver from C# (Atol.Drivers10.Fptr.dll). I import this wrapper into my project as a reference.
I have the following constructor in my class:
public MyClass()
{
IFptr fiscalPrinter = new Fptr();
// Here comes several settings to configure connection
fiscalPrinter.applySingleSettings();
fiscalPrinter.open();
fiscalPrinter.beep();
fiscalPrinter.close();
}
To test the solution I use another application, that loads my Class Library as a dependency.
When I call a constructor of MyClass I get an exception:
System.IO.FileNotFoundException: Driver not installed
at Atol.Drivers10.Fptr.Fptr.loadDriver(String path)
at Atol.Drivers10.Fptr.Fptr..ctor()
at MySolution.MyClass.MyClass()
...
If I create instance of Fptr with a path to the driver
IFptr fiscalPrinter = new Fptr(#"C:\path\fptr10.dll")
I get the slightly different exception, but I believe the problem is the same:
System.IO.FileNotFoundException: Can`t load driver library "C:\path\fptr10.dll"
at Atol.Drivers10.Fptr.Fptr.raiseNotFoundError(String path, Exception reason)
at Atol.Drivers10.Fptr.Fptr.loadDriver(String path)
at Atol.Drivers10.Fptr.Fptr..ctor(String libraryPath)
at MySolution.MyClass.MyClass()
...
But when I create a Console Application and put in there exact same code (both versions with path and without), everything works: the device beeps, there are no exceptions.
What could be the reason for that behavior and how to fix this?
The issue may be one of the following
The test application is using 'target platform' different than the console application which works fine. The device driver folders expected for each platform could be different. e.g. Changing the targeted platform from 'any CPU' to 'x64' / 'x86' (depending on the type of OS where you are running it) will help
Try running the test application from admin command prompt. Permissions issue may reflect as 'file not found' (instead of 'file could not be loaded').
Use an assembly binding viewer tool to debug the issue further
Refer to Could not load file or assembly or one of its dependencies for more discussion and inputs on the assembly loading issues.
Thank you samiksc.
The issue was in the test app. The driver and OS that I use are both x64, but the test application is x86. With x86 driver everything works.

Could not load file or assembly 'LinqToExcel, Version

I am trying to read an xlsx file.
I got exception that
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine. c#
then I installed it from here
http://www.microsoft.com/en-us/download/details.aspx?id=13255
then I changed the platform target to x64
now i got this exception:
BadImageFormatException was unhandeled
{"Could not load file or assembly 'LinqToExcel, Version=1.9.0.0, Culture=neutral, PublicKeyToken=9c8ea65a58f03f1f' or one of its dependencies. An attempt was made to load a program with an incorrect format."}
Update 1
I already installed the linq_to_excel
using
Install-Package LinqToExcel
and then add the lib files to references
You have two options to solve
Enable IIS to run 32 bits app
Install LinqToExcel_x64
if change 32 bit app in iis From false to true,all conflicts about exteltolinq version solve
Please install Microsoft office in your machine it will automatically solve your problem. It worked for me as well.

C# .Net App On Windows XP Fails Shell32 Code for Renaming Shortcut

I have a situation where I have a windows Desktop APP in .Net C# that must on both Windows 7 and Windows XP rename a shortcut. I have it working in Windows 7 but on XP this fails.
.Net 4.0 Client Profile and Extended is installed on XP and all other parts of the applciation are functioning on XP. The project has a reference Interop.Shell32 (MIcrosoft Shell Controls and Automation through COM Interop rahter than pinvoke) and the code is simply the following:
var shl = new Shell32.Shell();
argStrLnkPath = System.IO.Path.GetFullPath(argStrLnkPath);
var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(argStrLnkPath));
var itm = dir.Items().Item(System.IO.Path.GetFileName(argStrLnkPath));
itm.Name = "My Shortcut Name";
The above works in 7 but not XP. The following versions of the Shell32.dll exist:
Win7 Shell32.dll version 6.1.7601
WinXP Shell32.dll version 6.00.29.6242
When I spy the XP shell32dll in the object browser, the same objects exist, so the functionalty should be there (unless I'm not seeing something important).
My project is set to build as x86 platform for both machines. For the reference, I have tried the Embed Interop Types as True and also copy local as False.
I have an msi installer but is there something I need to do on the target XP machine? And should I copy Local? Any ideas on the propper way to get this working?
I have run the code on that XP Machine and receive the following from teh Event Viewer:
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidCastException
Embed Interop Types for Reference = True: The stackTrace for this error is:
Unable to cast COM object of type 'System.__ComObject' to interface type 'Shell3
2.Shell'. This operation failed because the QueryInterface call on the COM compo
nent for the interface with IID '{866738B9-6CF2-4DE8-8767-F794EBE74F4E}' failed
due to the following error: No such interface supported (Exception from HRESULT:
0x80004002 (E_NOINTERFACE)).
Embed Interop Types for Reference = False: The stackTrace for this error is:
Framework Version: v4.0.30319 Description: The process was terminated due to an unhandled exception. Exception Info: System.IO.FileNotFoundException
Issue Solved! I hadn't realized that when you make those types of COM Interop inclusions, they must have a Setup Project (msi installer if going on another system). Also, another caveat is that if you have already created a setup project, you must Add > project Output again. This will automatically pull all of those interop inclusions in under the Detected Dependencies folder. This solved my issue.

Unable to load DLL VistaDb20.dll because of an invalid access to memory location (HRESULT: 0x800703E6)

I have a project that was built in Visual Studio 2005 in C#. I created an installer for the Windows application (in VS2010) and it installs and works fine on Windows XP SP3. I tried installing it on Windows 7 32-bit and it says installation is successful but when I try to open the application I receive this error message:
A fatal error has occurred. Unable to load DLL 'VistaDb20.dll': Invalid
access to memory location. (Exception from HRESULT: 0x800703E6)
People suggested I run this in the command line:
regsvr32 VistaDb20.dll
I get the error message:
The module "VistaDb20.dll" was loaded but the
entry-point DllRegisterServer was not found.
Make sure that "VistaDb20.dll" is a valid DLL or OCX
file and then try again.
So then I tried regasm VistaDb20.dll /tlb:VistaDb20.tlb using the .NET Framework Assembly Registration Utility 2.0.50727.4927 and get error:
RegAsm : error RA0000 : Failed to load 'VistaDb20.dll' because it is not a valid .NET assembly.
I am not sure how to get my application running on Windows 7 with this .dll problem. Any help would be appreciated. This application and the database was created using VistaDB 2.1
I guess I can't change the actual dll since I did not create it but maybe I have to change some properties of the dll in Visual Studio?
I had this error while trying to registering my VB .NET assembly using RegAsm command:
RegAsm : error RA0000 : Failed to load 'VistaDb20.dll' because it is not a valid .NET assembly.
I solved the problem buy executing RegAsm of the right .NET Framework.
I mean you should use the tools of the same Framework that you make as target in your advanced options of compilation (VS2010).
According to this your problem is that this DLL is not compatible with DEP. You'll need to disable DEP to workaround this but in the long term you should try to wean yourself off this particular dependency.

Categories

Resources