Could not load file or assembly 32 bit assembly - vb.net

I have been searching and trying for many hours. I am having 'System.BadImageFormatException' when running my WCF service hosted on IIS 10.0 from 64-bit client application.
- I tried to set Enable 32 bit applications = true .
- I checked that target CPU = Any CPU .
- I double checked on the applicationHost.config file on the <ApplicationPools> section and make sure that Enable 32 bit applications = true .
All these attempts with same result, the same error message:
Could not load file or assembly 'DBConnNET4, Version=1.0.34.0,
Culture=neutral, PublicKeyToken=60d47e8c3d6f39e7' or one of its
dependencies. An attempt was made to load a program with an incorrect
format.
When debugging, I am getting the exception inside class from the referenced library, exactly here:
Public Class BusinessObject
Private Function Invoke()
Dim obj As new BusinessObject()
obj.ctrlQueryRun()
End Function
Private Function ctrlQueryRun() As Short
Try
'*** the exception occurs at this line, GetAllItems() is function in the same class
If Me.GetAllItems() = cERROR Then Return cERROR
'' Some code Here
Catch ex As Exception
Return cERROR
End Try
Return cSUCCESS
End Function
End Class
All the solutions I found on the Internet were telling to do the previous attempts, any other suggestions? Is there any thing I forgot to check? Many thanks in advance for anyone helping or trying to help.

Related

Error - An Item with the same key has already been added

Upon opening a macro enabled Excel file, I get the following:
Run-Time Error '-2147024809 (80070057)': An Item with the same key has already been added.
I've seen lots of similar questions for other languages, but nothing for VBA. I did find one thing online for VBA, but it says it has something to do with the Scripting.Dictionary library.
However, I have no reference to MS Scripting Runtime, nor do I ever bind to it, and I have no Dictionaries or Arrays or anything of the sort in this file. The only thing I can think of is I have a small Userform that is only a Progress bar. Every item on that Userform is uniquely named, and none of them are words that should be reserved or used by the system.
Has anyone run into this or have any ideas?
Edit:
Ok, strange thing just happened...I closed the 2 other VBA Projects (Add-Ins) that were opened in the VBE, before opening my file, and the error didn't come up. Those 2 other files have been open the whole time I've been working on this file...
Then I closed Excel altogether...left the other 2 files open, and opened my file with no error. I have no idea...
Update:
Just got the same error opening a different file. In case my question wasn't already clear enough...Does anyone know what this error might have to with, or how to stop it?
This looks like a Scripting.Dictionary error but in facts the following code throws an error of code 457 which is different from yours and the error message for dictionaries is different too 'This key is already associated with an element of this collection' This can be verified with the code
Option Explicit
Sub Tst()
On Error Resume Next
Dim dic As New Scripting.Dictionary
dic.Add 1, 0
dic.Add 1, 0
Debug.Print Err.Number, Err.Description
End Sub
So it is not your VBA code IMHO, but it looks rather like a C# error and we can verify this with some code, opening a Windows Forms C# project in Visual Studio and then edit Form1_Load to the following
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
Dictionary<long, long> dicTest = new Dictionary<long, long>();
dicTest.Add(1, 0);
dicTest.Add(1, 0);
}
catch (Exception ex) {
System.Windows.Forms.MessageBox.Show(string.Format("{0} {1}", ex.HResult, ex.Message));
}
}
}
}
and this throws the message box with the error number and message that you reported. Thus it is a C# Dictionary error IMHO, and note how we trapped it with a try catch block whereas I think you have code C# that is not catching the error.
So next question is which workbook is responsible. I would suggest in your experiments using Application.EnableEvents = False which turns off event handling, such that event handlers written in any language VBA, C# , VB,NET do not run. Then you can run your workbook's initialisation routines manually, if no error occurs your workbook is not guilty whereas the other workbooks/addins must be guilty at which you report the bug to their author.
I hope you make progress with this. It is difficult to take this further without feedback.

How to programmatically detect VB.NET obfuscation?

I am using ConfuserEx to obfuscate my program before release, I want the program to show a warning if it is being run without obfuscation. So as to reduce the chance of a non obfuscated executable being shipped.
So at runtime I want a function which returns true/false depending if obfuscation has been applied.
I can see two ways of doing it.
If the obfuscation process you use is part of the release build and therefore your release build has embedded instructions for the obfuscation part, you could do something like that.
AppValidator.Validate()
The validation will validate it is a release version or if not, that the application is run for allowed users (dev. team for instance).
I also added a way to validate by commandline calling Myapp.exe validate
However. this does not validated obfuscation per see, it validates the application is in Release mode.
Your obfuscator, if embedded with the release build, should fails if he cannot obfuscate release version or the premise for this validation is not good.
Public Class AppValidator
#If DEBUG Then
Private Shared ReadOnly IsDebugVersion As Boolean = True
#Else
private Shared ReadOnly IsDebugVersion As Boolean = False
#End If
Private Shared ReadOnly ISValidUser As Boolean = ValidateDevUser()
''' <summary>
''' Validate the user is authorized to run the program as
''' </summary>
''' <returns></returns>
Private Shared Function ValidateDevUser() As Boolean
Try
' Custom validation to determine if used in dev. environment such
'as validating username and domain name or checking agains Dev. Registry key
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Shared Function Validate() As Boolean
Dim Args = Environment.GetCommandLineArgs
Dim ConsoleValidate As Boolean = Args.Count = 2 AndAlso String.Compare(Args(1), "validate") = 0
If IsDebugVersion Then
If ConsoleValidate Then
Console.WriteLine(Not IsDebugVersion)
Application.Current.Shutdown()
Return False
End If
If Not ValidateDevUser() Then
MessageBox.Show("Access Denied")
Application.Current.Shutdown()
Return False
End If
End If
Return True
End Function
End Class
The first solution is best if you can be sure that build will fails if release version produced and obfuscator steps fails.
If you cannot be sure of that, you can maybe take a look at
Obfuscation checker, from Red-gate, which is free and has a command-line and do exactly what you seek in a direct approach.
You could use something like ILSpy and have it run automatically after build with WM_COPYDATA API arguments, like so:
https://github.com/icsharpcode/ILSpy/blob/master/doc/Command%20Line.txt
Have it navigate to a type name that should be obfuscated; if it fails, you know obfuscation succeeded.

How to do a non-recurring timeout in Gtk#?

I'm trying to do a thing a second in the future, but only once. The docs for GLib.Timeout.Add say that the "delegate is invoked repeatedly until it returns false", so I'm returning false and then I get an error from glib.
Example code:
using System;
class foo {
static void Main() {
Gtk.Application.Init();
uint t = GLib.Timeout.Add(1000, () => {
Console.WriteLine("returning false from timeout");
Gtk.Application.Quit();
return false;
});
Console.WriteLine("timeout added with source id = {0}", t);
Gtk.Application.Run();
}
}
Sample output:
$ mono foo.exe
timeout added with source id = 6
returning false from timeout
(foo:19030): GLib-CRITICAL **: Source ID 6 was not found when attempting to remove it
How do I stop my timeout from repeating after it times out without getting errors?
$ pkg-config --modversion gtk-sharp-3.0
2.99.3
Note that the error message apparently appears at program exit, and in my real program it does not seem to appear until the gc runs (I can get it immediately after the timeout if I manually call the gc and wait for finalizers).
Short answer, you can't. The timeout won't repeat because it has been properly removed. That's what the "error" is from because the gtk runtime is trying to dispose the timeout twice. This issue isn't just the C# gtk implementation, it's a bug in the C gtk+ library. There is a way to disable gtk from reporting errors, but I'm not sure how to do that.

MyBase initialize() in Membership Provider

In my code I use this line to Initialize my Base:
MyBase.Initialize(name, config)
Everything goes fine in the first time pass... but when it passes second time then throws me an error The Base Is already Initialized and that is something I don't want to happen.
Is there any way to catch this event?
Finally the Base initialized only in the Default.aspx page, putting these lines in the Page_Load:
Dim myNewAsp As New AspNetSqlProvider
If MyAspNetSqlMembershipProvider.SQLconnectionString = Nothing Then
myNewAsp.InitializeSite(sender, e)
Return
End If
Doing this the system always knows when if the Base is initialized or not.

XAML - Runtime Exception after Creating a Dependency Property in WinRT

I am working with the Windows 8 developer build. I am attempting to create a basic dependency property. I've used them before in WPF and Silverlight. However, I'm not trying to create one in WinRT without any luck.
public static DependencyProperty GPAProperty = DependencyProperty.Register("GPA", "double", "MyNamespace.MyClass", new PropertyMetadata(0));
public double GPA
{
get { return (double)GetValue(GPAProperty); }
set { SetValue(GPAProperty, value); }
}
When I run my code, I get a runtime exception when the app first starts that says:
A first chance exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
My question is, does this look right? I keep thinking I'm overlooking something. But it all looks correct to me.
You need to change double to Double...