Search code examples
vb.netwinformswebformssage-erp

Sage200c SDK crashing in webforms


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.


Solution

  • 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.