none
External Assembly Call in BizTalk Map RRS feed

  • Question

  • Hello All,

    I am trying to call an external assembly as below from a scripting Functoid:

    public static string dblookup()
            {
    
                string eaidbconnection = null;
                eaidbconnection = System.Convert.ToString(BizTalk.CE.Eai.Common.EaiSettings.GetSetting("ForecastFileExclusions"));
                return eaidbconnection;
            }

    But when I do so and test the map am getting the below error: Exception has been thrown by the target of an invocation.Object reference not set to an instance of an object.

    When I deploy the application and then use the map as inbound map in the receive port I get the error as : Exception has been thrown by the target of an invocation.

    The external assembly is gaced in assembly too.

    What is wrong with the code?

    Monday, November 17, 2014 12:54 PM

Answers

  • The best way to imply simple coding/recoding is to hard-code all n0-x00 codes in C# method. It is simple, fast and easy to manage. Actually this works fine for hundreds or thousands codes, it depends of the memory footprint. Usually memory footprint is small.

    If you need to change codes frequently, upload them from the file.


    Leonid Ganeline [BizTalk MVP]


    Thursday, November 20, 2014 4:24 PM
    Moderator

All replies

  • It seems there is some error in the assembly you are calling, which is throwing the  Object Reference error.

    Can you share the code for EaiSettings.GetSetting() function.

    Or I would suggest to create a temporary console application try to call this function by passing "ForecastFileExclusion".

    You can put a breakpoint and do line by line debugging to reach to the issue.

    Let us know if you are facing any issue


    Thanks,
    Prashant
    ----------------------------------------
    Please mark this post accordingly if it answers your query or is helpful.

    Monday, November 17, 2014 3:03 PM
  • If you debug the map you can find that custom extension object is not available to construct the destination response.     You need to define custom extension xml within map properties .

    something like below

    <ExtensionObjects> 
      <ExtensionObject Namespace="http://schemas.microsoft.com/BizTalk/2003/ScriptNS0" AssemblyName="MapperExtensionsFunctions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cdbffba4cc751306" ClassName="MapperExtensionsFunctions.MappingFunctions" /> 
    </ExtensionObjects> 

    Sandro has documented it very well here

    Calling-an-external Assembly

    Thanks

    Abhishek

    Monday, November 17, 2014 5:38 PM
  • The code for EaiSettings.GetSetting() function is working fine as it is being used at other places. it seems that the scripting functoid is not able to call the external assembly.
    Tuesday, November 18, 2014 11:16 AM
  • It seems that the scripting functoid is not able to call the external assembly and hence getting an null value for the same.
    Tuesday, November 18, 2014 11:16 AM
  • It seems that the scripting functoid is not able to call the external assembly and hence getting an null value for the same.

    Well, no.  A Map can call a method in an external Assembly just fine.  Did you follow Abhishek0127[Abhishek kumar]'s advice?

    Is the setting in the correct .config file if that's where it's supposed to be?

    Tuesday, November 18, 2014 12:51 PM
    Moderator
  • It seems that the scripting functoid is not able to call the external assembly and hence getting an null value for the same.

    You need to define extension object as been mentioned in my previous post . You can analyze the same by just trying to debug the generated xslt  which will give you "extension object" error

    Thanks

    Abhishek

    Tuesday, November 18, 2014 2:53 PM
  • hi,

    You can follow the link to what Abhishek wrote.. You can even use the sample that comes with BizTalk. You can find it in C:\Program Files\Microsoft BizTalk Server 2013\SDK\Samples\XmlTools\ExtendingMapper


    Praveen Behara
    MCST : BizTalk Server 2006 R2, 2010

    Tuesday, November 18, 2014 10:18 PM
  • Seems this method of the external assembly is the wrapper to call AppSettings section in config file.

    Please, make sure the correspondent section with your parameter is included in the BTSNTSvc64.exe.config or BTSNTSvc.exe.config file. It depends of the host where you run your map (is it the 64bit host or 32bit host). This parameter also could be in the machine.config file (there are four(!) such files for .NET 2 and 3.5 * 32 / 64bit ).

    BTW In most cases this wrapper doesn't add any bonuses but adds unnecessary dependency. It makes sense to use System.ConfigurationManager.AppSettings["key"]; directly.


    Leonid Ganeline [BizTalk MVP]

    Tuesday, November 18, 2014 11:24 PM
    Moderator
  • Hi Abhi,

    Are you doing Test Map? If yes then the values configured in BTSNTSvc.exe.config won't be called because test map is not happening in BTSNTSvc.exe process.

    You will have to give this configuration in Devenv.exe.config(Visual Studio config file).

    Let us know if you have any further question 


    Thanks,
    Prashant
    ----------------------------------------
    Please mark this post accordingly if it answers your query or is helpful.

    Wednesday, November 19, 2014 10:49 AM
  • Hello All,

    Even when I change the code of the method to just return a string it is not working :

    public static string dblookup()
            {
    
                string eaidbconnection = null;
                eaidbconnection = "Provider=SQLOLEDB;Server=ServerName\SQL02;Database=EAI_Main;Integrated Security=SSPI;";
                return eaidbconnection;
            }

    I am using a databaselookup functoid and want to keep the database name input as configurable. so want to fetch it from a table.. but that is not working so in the above code am simply returning the connection string from the method and that is also not working. But, when use this connection string directly in the db functoid it works. There seems to be something wrong when I am calling the external assembly from sricting functoid. I think this is a server issue ?  so is there anythign I can check to confirm the same ?


    Thursday, November 20, 2014 1:25 PM
  • If this is the error message: "Exception has been thrown by the target of an invocation.Object reference not set to an instance of an object."

    Again, 90%, the external assembly call is working just fine.  Most likely the item is not in the .config file.  All the .Net rules apply.

    Now, can we help you to not use the Database Functoids?

    Thursday, November 20, 2014 2:02 PM
    Moderator
  • Sure,

    What my requirement is that there is a node lets say name and there is a possiility of 10 values like A to J coming from source so, for each value corresponding values 1 to 10 are to be mapped to the destination schema. what other way to do this better than database lookup functoid.?

    Thursday, November 20, 2014 2:09 PM
  • Sure,

    What my requirement is that there is a node lets say name and there is a possiility of 10 values like A to J coming from source so, for each value corresponding values 1 to 10 are to be mapped to the destination schema. what other way to do this better than database lookup functoid.?

    Why not create a stored procedure which you can call from the orchestration and it will return the result set (say 10 values ) . Then you have always option to map the result set from stored procedure to destination schema.

    Thanks

    Abhishek

    Thursday, November 20, 2014 3:04 PM
  • The best way to imply simple coding/recoding is to hard-code all n0-x00 codes in C# method. It is simple, fast and easy to manage. Actually this works fine for hundreds or thousands codes, it depends of the memory footprint. Usually memory footprint is small.

    If you need to change codes frequently, upload them from the file.


    Leonid Ganeline [BizTalk MVP]


    Thursday, November 20, 2014 4:24 PM
    Moderator