We are having a problem with the Sage 200c Extra 2018 SDK when used in Web Forms.
We have created solution with library, win forms and web forms project. We have noticed that when using the 'Win Forms project' it works, but the same example in 'Web Forms project' crashes. Sage 200c SDK documentation does not exclusively talk about Win or Web forms and what configuration each may need.
Could you please help us to get this working in web forms? We have an older version of the SDK working on an older version of Sage 200 v8.
We have upgraded Sage 200 v8 to Sage 200c Extra 2018 Summer Enhancements and tested it with the new client and all is working.
I have noticed on sage City similar questions but no answer.
Here
Here is our code sample:
Private Shared Sub FindCore200()
' get registry info for Sage 200 server path
Dim path As String = String.Empty
Dim root As RegistryKey = Registry.CurrentUser
Dim key As RegistryKey = root.OpenSubKey(REG_PATH)
If key IsNot Nothing Then
Dim value As Object = key.GetValue(REGKEY_VALUE)
If value IsNot Nothing Then
path = TryCast(value, String)
End If
End If
' refer to all installed assemblies based on location of default one
If String.IsNullOrEmpty(path) = False Then
Dim commonDllAssemblyName As String = System.IO.Path.Combine(path, DEFAULT_ASSEMBLY)
If (System.IO.File.Exists(commonDllAssemblyName)) Then
Dim defaultAssembly As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom(commonDllAssemblyName)
Dim type As Type = defaultAssembly.[GetType](ASSEMBLY_RESOLVER)
Dim method As MethodInfo = type.GetMethod(RESOLVER_METHOD)
Dim x = method.Invoke(Nothing, Nothing)
Dim ok = 1
End If
End If
End Sub
when running the application, it always crashes on
application = New Sage.Accounting.Application
Exception Type: System.TypeInitializationException
Message: The type initializer for 'Sage.Accounting.Application' threw an exception.
Inner Exception:
Exception Type: System.IO.FileNotFoundException
Message: Could not load file or assembly 'Sage.MMSAdmin.Util, Version=19.0.0.0, Culture=neutral, PublicKeyToken=b2daa66d74953d11' or one of its dependencies. The system cannot find the file specified.
Are your application pools targeted to the correct version of .net and bit architecture?
If you can physically see the assembly in the path but the app can't, it's usually down to having the wrong version of .net configured. Going from such an old version to a new one, likely requires a .net version change (2.0 to 4.5 for example). It may just be that your winforms solution is targeted to the correct config and it's definitely worth comparing your build and application settings. Check that your targeting the correct CPU architecture in your build too.
Related
I have the libsodium-net NuGet loaded into my PoC solution and have the 32-bit and 64-bit libsodium.dll files in their respective directories (System32 and SysWOW64). Whenever I go to run the program in debug mode, I get the BadImageFormatException error. Is it enough to have the libsodium.dll files in their respective System directories and I'm just missing something else, or do I need to have copies of those dll files in my solution as well?
I have tried compiling using both x86 and x64 build configurations since I read here: BadImageFormatException during .Net assembly load issue that, that could be the cause of this error but I still got the same error in both areas.
I also tried the answer I found here: How to include libsodium.net on ASP.NET for incorporating libsodium-net into VS, where it said to install Visual C++ Redistributable 2015 as well, but the problem there is when I tried that, I got an error from the installer stating that it was already installed on my computer. When I checked though, all I had were the 2008, 2013 and 2017 versions, not 2015, so I'm still at a loss on why I couldn't install the 2015 Redistributable but that's for another time.
Here's my procedure and at least according to intellisense, everything here's hooked up correctly.
Option Explicit On
Imports Sodium
Imports System.Text
Public Class Form1
Dim textToEncrypt, decrypted As String
Shared encoder As New UTF8Encoding
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim key, hashedBytes, salt As Byte()
textToEncrypt = TextBox1.Text
Dim textBytes As Byte() = encoder.GetBytes(textToEncrypt)
hashedBytes = CryptoHash.Sha512(textToEncrypt)
salt = PasswordHash.ScryptGenerateSalt()
key = SecretBox.GenerateKey()
Dim passEnc As Byte() = PasswordHash.ScryptHashBinary(textBytes, salt, PasswordHash.Strength.Medium)
TextBox2.Text = Convert.ToBase64String(passEnc)
TextBox6S.Text = Convert.ToBase64String(salt)
TextBox3PBK.Text = Convert.ToBase64String(key)
TextBox5H.Text = Convert.ToBase64String(hashedBytes)
End Sub
End Class
As you can see in the above procedure, this program's fairly straight forward and should just take an input, run it through a couple of Sodium functions, then convert to Base 64 strings and print the results to some text boxes but I get the BadImageFormatException error on each Sodium function the procedure calls.
Alright so i am pretty new to really anything in memory execution. I usually just write the bytes from the embedded resource into the file on the hard drive but for the program i am making for a work project it cannot write the exe to the disk.
So i took the code from Load a .NET assembly from the application's resources and run It from memory, but without terminating the main/host application
I modified the code a little bit in what i would think would work for running it with an argument and it does nothing but crash, not really listing any crash details though besides the windows error reporting.
here is the code:
Dim ass As Assembly = Assembly.Load(My.Resources.bbinst)
Dim method As MethodInfo = ass.EntryPoint
Dim parametersArray As Object() = New Object() {"/q /SERIAL=xxx-xxx"}
If (method IsNot Nothing) Then
Dim instance As Object = ass.CreateInstance(method.Name)
method.Invoke(instance, parametersArray)
If (instance IsNot Nothing) AndAlso (instance.GetType().GetInterfaces.Contains(GetType(IDisposable))) Then
DirectCast(instance, IDisposable).Dispose()
End If
instance = Nothing
method = Nothing
ass = Nothing
Else
Throw New EntryPointNotFoundException("Entrypoint not found in the specified resource. Are you sure it is a .NET assembly?")
End If
bbinst is the exe name that is embedded as bbinst.exe
The parametersArray is the argument i want to run which i converted from a C# sample i found else where.
Can someone help me as to why the program just crashes and error reporting pops up second after, i'm not to good as debugging. I also tried to run it without the arguments and it as well crashed the same way.
Any help is awesome, sometimes i have these random projects at work i don't know why they give me lol
A BadImageFormatException is thrown either when you attempt to load an assembly of the wrong bitness, or when you try to load an assembly that cannot be read, run or compiled by the current runtime.
Regarding bitness: 32-bit (x86) applications cannot load 64-bit code, and 64-bit (x64) applications cannot load 32-bit code. It's that simple.
As for not being able to read, run or compile the assembly: If the assembly that you're trying to load was programmed in a completely different language (more precisely: a language without .NET support) then it would also cause the above exception to be thrown.
Your method of executing an embedded application will only work with assemblies that were coded in a .NET language (C#, VB.NET, F#, C++/CLR, etc.). This is because that doesn't only run the application, it tries to load it like a .NET app linked to an Assembly, and/or AppDomain, class so that you can have some control over it and invoke methods inside it.
Your issue: My bet that your problem is caused by your embedded application not being of the same bitness as the host. Make sure both applications are compiled either as x86, x64 or AnyCPU.
However if it turns out that your embedded program isn't even written in a .NET language then that is the cause of your problem. That code of yours can only run .NET programs/DLLs.
You can invoke the EntryPoint by loading it in the assembly :
Public Shared Sub RunSearch(ByVal pPath As String, ByVal pText As String)
'Get assembly
Dim assembly As Reflection.Assembly = Reflection.Assembly.GetExecutingAssembly()
'Get the resource stream
Dim resourceStream As Stream = assembly.GetManifestResourceStream("path.executable name")
If resourceStream Is Nothing Then
MsgBox("Unexisting Path","Error")
End If
'Read the raw bytes of the resource
Dim resourcesBuffer(CInt(resourceStream.Length) - 1) As Byte
resourceStream.Read(resourcesBuffer, 0, resourcesBuffer.Length)
resourceStream.Close()
'Load the assembly
Dim exeAssembly As Reflection.Assembly = Reflection.Assembly.Load(resourcesBuffer)
Dim args() As String = {pPath, pText}
Dim parameters = New Object() {args}
Try
exeAssembly.EntryPoint.Invoke(Nothing, parameters)
Catch
MsgBox("Error during assembly executing","Error")
End Try
End Sub
I am working on Silverlight Application and trying to create SignalR Client Code in my application but getting error as below when trying to start Hub Connection .
I have instlaled all packages like "Microsoft.Aspnet.SignalR.client", "Microsoft.Bcl" but getting error
ERROR
Could not load file or assembly 'System.Threading.Tasks, Version=1.5.11.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The
system cannot find the file specified.
Below is sample code from my application.
Public Sub New()
InitializeComponent()
Dim myHubConnections As HubConnection
Dim myHubProxy As IHubProxy
Dim CurrentContext As SynchronizationContext = SynchronizationContext.Current
Dim message As String = ""
myHubConnections = New HubConnection("http://gcrmdev0.goldcrm2.com/GSPWebServices-DAK/signalr/hubs")
myHubProxy = myHubConnections.CreateHubProxy("signalRHub")
'myHubProxy.On("NotifyAgent",
txtCaseNotes1.Text = "Notifications Received from Server"
myHubConnections.Start().Wait()
End Sub
It may because of the wrong app.config entries. Clean up the app.config file by removing the wrong entries. When adding the NuGet package to a project that is consumed by another project with a different target framework you might see this kinds of errors.
Check here the Issue number 6 and 9.
I'm still learning VB.net and I'm now at a stage where I want to write an auto-update function, now I wrote this simple function myself, nothing fancy but I'd just like to check to see that there's no major flaws in my logic? Short of human error I think this is a nice simple way to do this.
Note: it all works flawlessly from my testing.
My Function
Public Function updateCheck()
Dim CurrentVersion As String = My.Settings.currentVersion
Dim updateURL As String = My.Settings.updateURL
Dim WebRequest As WebClient = New WebClient
Dim Version As String = WebRequest.DownloadString(updateURL)
If Version = CurrentVersion Then
MessageBox.Show("no updates available")
Else
MessageBox.Show("An new version is available: " & Version)
End If
End Function
updatecheck.html file simply contains "vx.x.x" which sites on a web-server and the currentVersion string is again "vx.x.x"
I can't see this failing short of forgetting to change the currentVersion string upon an application update and it looping.
In terms of simplistic and clean code, is there anyway I can improve this? - I plan on adding some download and execute code to download an updater which un-installs and re-installs the latest version. - I'm currently using InstallShield to deploy the application.
Thanks for any suggestions/comments.
Instead of trying to code this yourself - you should have a look at ClickOnce deployment.
This has all the functionality you are trying to code and handles all the error cases when there is no connection, etc. It also allows for install without admin rights.
I am working on a vb.net project. I am trying to convert the content of a pdf file to string using acrobat dlls (cannot use other 3 rd party dlls). Below is my code, when I run the program I am getting the following error: "Retrieving the COM class factory for component with CLSID, failed due to the following error: 80040154 Class not registered". I did some research and found out that I have to install the full version of acrobat standard or professional version. Not only that the full version of acrobat must also be installed in all the user machines that the program runs.
Can anyone tell me if this is true and suggest how to fix the class not registered error?
Sub Main()
Dim s As String
Dim sSourceFile As String
sSourceFile = "P:\Report images\DevReports\New Folder\UM-STD-Approval_154.pdf"
Dim oSourceFileInfo As New System.IO.FileInfo(sSourceFile)
Dim st As New AcroPDDoc
st.Open(sSourceFile)
s = GetText(st)
Dim oAcroApp As Acrobat.CAcroApp = New Acrobat.AcroApp
Dim oAcroAvDoc As Acrobat.CAcroAVDoc = New Acrobat.AcroAVDoc
Dim oAcroPDDoc As Object = Nothing
If oAcroAvDoc.Open(sSourceFile, "") Then
'Set PDDoc object and save the file.
oAcroPDDoc = oAcroAvDoc.GetPDDoc()
' oAcroPDDoc.Save(1, sOutputFile)
Else ' Document FAILED to open.
MsgBox("Cannot open ")
End If
oSourceFileInfo = Nothing
oAcroApp.CloseAllDocs()
oAcroPDDoc = Nothing
oAcroAvDoc = Nothing
oAcroApp.Exit()
oAcroApp = Nothing
End Sub
Apologies for the obvious answer but you've kind of answered your own question already.
Adobe Reader is a free application with a very limited interface allowing automation; in practice it's limited to the point where you can display a PDF file and navigate through it (to some extent).
For full features automation (like what I think you are looking for) you will need to install the full Adobe Acrobat. And yes, any system you run this on will also need to have Adobe Acrobat installed.
Now, there are probably libraries out there (including libraries from Adobe or containing Adobe technology inside) that will allow you to embed the functionality you are looking for in your application, but those too will not be free...