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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

CLR Exceptions in Dynamics AX X++ code

(0) ShareShare
ReportReport
Posted on by

Hello,
Your help Please.

I have a 3-layer application that I want to use in X ++ 2009, AxLocalizationPT (Presentation), AxLocalizationBT (Logical) and AxLocalizationDT (Data).

It throws the following error with the exception (Exception :: Internal):

System.Reflection.TargetInvocationException: Se produjo una excepción en el destino de la invocación. ---> System.IO.FileNotFoundException: No se puede cargar el archivo o ensamblado 'AxLocalizationBT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ni una de sus dependencias. El sistema no puede encontrar el archivo especificado.
Nombre de archivo: 'AxLocalizationBT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
   en AxLocalizationPT.AddDataFormManager..ctor()

=== Información de estado anterior al enlace ===
LOG: Usuario = Certitech\Administrador
LOG: DisplayName = AxLocalizationBT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
 (Fully-specified)
LOG: Appbase = file:///D:/Program Files (x86)/Microsoft Dynamics AX/50/Client/Bin/
LOG: PrivatePath inicial = NULL
Ensamblado de llamada : AxLocalizationPT, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
===
LOG: Este enlace empieza en el contexto de carga default.
LOG: No se encontró ningún archivo de configuración de la aplicación.
LOG: Utilizando el archivo de configuración del equipo en C:\Windows\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: La directiva no se está aplicando a la referencia en este momento (enlace de ensamblado privado, personalizado, parcial o basado en la ubicación).
LOG: Ya se detectó el mismo enlace, que generó un error hr = 0x80070002.

   --- Fin del seguimiento de la pila de la excepción interna ---
   en System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandle& ctor, Boolean& bNeedSecurityCheck)
   en System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean fillCache)
   en System.RuntimeType.CreateInstanceImpl(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean fillCache)
   en System.Activator.CreateInstance(Type type, Boolean nonPublic)
   en System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   en System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
   en ClrBridgeImpl.NewClrObject(ClrBridgeImpl* , Char* pszClassName, Char* assemblyName, Int32 argsLength, ObjectWrapper** arguments, Boolean* isException)

Here the method that compiles without errors:

public void dataSourceInfo(TableId _tableId, RecId _recId, DataAreaId _dataAreaId)
{
    CompanyInfo companyInfo;
    ExchRate exchRate;
    System.Decimal val;
    VendInvoiceJour vendInvoiceJour;
    str svrErp;
    AxLocalizationPT.AddDataFormManager addDataFormManager;
    CodeAccessPermission permission;
    System.Exception ex;
    ;
    svrErp = SysSQLSystemInfo::construct().getLoginServer();
    companyInfo = CompanyInfo::find();
    if ( _tableId == 491 )
    {
        select vendInvoiceJour where vendInvoiceJour.RecId == _recId && vendInvoiceJour.dataAreaId == _dataAreaId;
        exchRate = ExchRates::displayExchRate(vendInvoiceJour.ExchRate);
        val = new System.Decimal(exchRate);
    }

    new InteropPermission(InteropKind::CLRInterop).assert();
    try
    {
        addDataFormManager = new AxLocalizationPT.AddDataFormManager();
    }
    catch(Exception::CLRError)
    {
        ex = CLRInterop::getLastException();
        info(ex.ToString());
    }
    catch (Exception::CodeAccessSecurity)
    {
        info("Code Access Security Error");
    }
    catch (Exception::Internal)  // This exception handler was the Magic Sauce!!
    {
        ex = CLRInterop::getLastException();
        if (ex)
        {
            info(ex.ToString());
        }
        else
        {
            info("Internal Error");
        }
    }
    catch (Exception::Error)
    {
        info("None of it worked (generic Exception)");
    }
    addDataFormManager.initAddDataManager(_tableId, _recId, tableId2name(_tableId), _dataAreaId, val, svrErp);
}


*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Brandon Wiese Profile Picture
    17,788 on at

    It looks like a simple "file not found" error looking for AxLocalizationBT in the Global Assembly Cache or the client/server Bin directory.

    To troubleshoot, put those .NET DLL files in the client and server Bin directory, and make sure they are properly added in the References node of the AOT.

  • Community Member Profile Picture
    on at

    Yes I made sure that it was so, I copied the files in the Bin folder and added the three DLL files of my three layers in the references.

  • Community Member Profile Picture
    on at

    Thank you Brandon for your interest in helping me.

    I restarted the AOS and it no longer gives the error, but now it happens that it does not execute the AxLocalizationBT project code.

    I explain: When I perform debugging associated with the process, the .Net code stops in the first line in which it calls a method of the AxLocalizationBT project but it no longer enters the method but returns the control to the AX form that called it.

  • Verified answer
    Community Member Profile Picture
    on at

    Geez, I realize that debugging of unmanaged code must be enabled in each of the projects. Now I can debug and I found the problem in my .Net code.

    Thank you very much Brandon!

  • Brandon Wiese Profile Picture
    17,788 on at

    Good catch.  Very useful tidbit for someone else in the future.  You should mark your own post as an answer here.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans