web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Can't use BusinessConnector in ASP.Net app

(0) ShareShare
ReportReport
Posted on by

Hello, I have an ASP.Net web app. I use there self written library that references Microsoft.Dynamics.BusinessConnectorNet.dll version x64. When I try to start my app I always get this error page with an exception: 

Server Error in '/' Application.


Не удалось загрузить файл или сборку "Microsoft.Dynamics.BusinessConnectorNet" либо одну из их зависимостей. Была сделана попытка загрузить программу, имеющую неверный формат.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.BadImageFormatException: Не удалось загрузить файл или сборку "Microsoft.Dynamics.BusinessConnectorNet" либо одну из их зависимостей. Была сделана попытка загрузить программу, имеющую неверный формат.

 

It's mostly in russian, but basically it says that file or assemly can't be loaded and there was attempt to load program of wrong format.

It happens only in web app, in console app, for example, BC works just fine.

I've tried switching references differently, I created new project for that, but it's always the same...

How can I fix this? I can show you config files and cone if needed.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at
    RE: Can't use BusinessConnector in ASP.Net app

    Problem solved. I had to include Microsoft.Dynamics.BusinessConnectorNet.dll reference in my project and sep prop for it - Copy Local to False

  • Community Member Profile Picture
    on at
    RE: Can't use BusinessConnector in ASP.Net app

    That whould mean that my code never works. And you don't sugget an answer. AS I WROTE: "It happens only in web app, in console app, for example, BC works just fine."

    I use legacy binding for that:

    using System;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    
    namespace MyNamespace
    {
        public static class RuntimePolicyHelper
        {
            public static bool LegacyV2RuntimeEnabledSuccessfully { get; private set; }
    
            static RuntimePolicyHelper()
            {
                var clrRuntimeInfo =
                    (ICLRRuntimeInfo)RuntimeEnvironment.GetRuntimeInterfaceAsObject(
                        Guid.Empty,
                        typeof(ICLRRuntimeInfo).GUID);
                try
                {
                    clrRuntimeInfo.BindAsLegacyV2Runtime();
                    LegacyV2RuntimeEnabledSuccessfully = true;
                }
                catch (COMException)
                {
                    LegacyV2RuntimeEnabledSuccessfully = false;
                }
            }
    
            [ComImport]
            [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
            [Guid("BD39D1D2-BA2F-486A-89B0-B4B0CB466891")]
            private interface ICLRRuntimeInfo
            {
                void xGetVersionString();
                void xGetRuntimeDirectory();
                void xIsLoaded();
                void xIsLoadable();
                void xLoadErrorString();
                void xLoadLibrary();
                void xGetProcAddress();
                void xGetInterface();
                void xSetDefaultStartupFlags();
                void xGetDefaultStartupFlags();
    
                [MethodImpl(MethodImplOptions.InternalCall, MethodCodeType = MethodCodeType.Runtime)]
                void BindAsLegacyV2Runtime();
            }
        }
    }


    This wasn't related to my question.

  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: Can't use BusinessConnector in ASP.Net app

    AX 2009 uses .NET Framework 3.5 (CLR 2.0).

  • Community Member Profile Picture
    on at
    RE: Can't use BusinessConnector in ASP.Net app

    .NET framework 4.5.2, platform is Any CPU

  • Martin Dráb Profile Picture
    235,876 Most Valuable Professional on at
    RE: Can't use BusinessConnector in ASP.Net app

    Which version of .NET framework is the application using and what's its target processor architecture?

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Syed Haris Shah Profile Picture

Syed Haris Shah 9

#2
Mea_ Profile Picture

Mea_ 4

#3
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans