Initialization [Error] DnaLibrary AutoOpen Error : TargetInvocationException

765 views
Skip to first unread message

alexs...@gmail.com

unread,
May 11, 2018, 9:53:10 AM5/11/18
to Excel-DNA
Hello, 

My add-in works perfectly on all excel versions (32 or 64 excel versions), but on one machine (Office 13 32 bit) it throws exception:

Initialization [Error] DnaLibrary AutoOpen Error : TargetInvocationException -

The problem is in: GetParameterConversionConfig

If i don't use this method, then I got exception in  excel: !!! ERROR: System.MissingMethodException: Method not found: "!!0[] System.Array.Empty()".

 

   в MyFunc.MyFunctions.PrimeDataCBRates(DateTime date1, Boolean head, String size)

 

   в PrimeDataCBRates(Closure , DateTime , Boolean , String )

 

   в WrapperType.Wrapped_f1_Invoke(Object , Object , Object , String )



Where can be the problem???


 public void AutoOpen()
        {
          ExcelIntegration.RegisterUnhandledExceptionHandler(ex => "!!! ERROR: " + ex.ToString());
       
          var conversionConfig = GetParameterConversionConfig();
         
          var postAsyncReturnConfig = GetPostAsyncReturnConversionConfig();
            var functionHandlerConfig = GetFunctionExecutionHandlerConfig();
         
            // Get all the ExcelFunction functions, process and register
            // Since the .dna file has ExplicitExports="true", these explicit registrations are the only ones - there is no default processing
            ExcelRegistration.GetExcelFunctions().ProcessMapArrayFunctions(conversionConfig);

            ExcelRegistration.GetExcelFunctions().ProcessParameterConversions(conversionConfig);

            ExcelRegistration.GetExcelFunctions().ProcessAsyncRegistrations(nativeAsyncIfAvailable: false);

            ExcelRegistration.GetExcelFunctions().ProcessParameterConversions(postAsyncReturnConfig);

            ExcelRegistration.GetExcelFunctions().ProcessParamsRegistrations();
            ExcelRegistration.GetExcelFunctions().ProcessFunctionExecutionHandlers(functionHandlerConfig);
            ExcelRegistration.GetExcelFunctions().RegisterFunctions();
  // First example if Instance -> Static conversion
            //InstanceMemberRegistration.TestInstanceRegistration();
        }


static ParameterConversionConfiguration GetParameterConversionConfig()
        {
            // NOTE: The parameter conversion list is processed once per parameter.
            // Parameter conversions will apply from most inside, to most outside.
            // So to apply a conversion chain like
            // string -> Type1 -> Type2
            // we need to register in the (reverse) order
            // Type1 -> Type2
            // string -> Type1
            //
            // (If the registration were in the order
            // string -> Type1
            // Type1 -> Type2
            // the parameter (starting as Type2) would not match the first conversion,
            // then the second conversion (Type1 -> Type2) would be applied, and no more,
            // leaving the parameter having Type1 (and probably not eligible for Excel registration.)
            // 
            //
            // Return conversions are also applied from most inside to most outside.
            // So to apply a return conversion chain like
            // Type1 -> Type2 -> string
            // we need to register the ReturnConversions as
            // Type1 -> Type2 
            // Type2 -> string
            //

            var paramConversionConfig = new ParameterConversionConfiguration()

            // Register the Standard Parameter Conversions (with the optional switch on how to treat references to empty cells)
            .AddParameterConversion(ParameterConversions.GetOptionalConversion(treatEmptyAsMissing: true))

            // Register some type conversions (note the ordering discussed above) 
            // .AddParameterConversion((TestType1 value) => new TestType2(value))
            //.AddParameterConversion((string value) => new TestType1(value))

            // This is a conversion applied to the return value of the function
            //.AddReturnConversion((TestType1 value) => value.ToString())
            .AddReturnConversion((Complex value) => new double[2] { value.Real, value.Imaginary })

            // .AddParameterConversion((string value) => convert2(convert1(value)));

            // This parameter conversion adds support for string[] parameters (by accepting object[] instead).
            // It uses the TypeConversion utility class defined in ExcelDna.Registration to get an object->string
            // conversion that is consist with Excel (in this case, Excel is called to do the conversion).
            .AddParameterConversion((object[] inputs) => inputs.Select(TypeConversion.ConvertToString).ToArray())

            // This is a pair of very generic conversions for Enum types
            .AddReturnConversion((Enum value) => value.ToString(), handleSubTypes: true)
            .AddParameterConversion(ParameterConversions.GetEnumStringConversion())

            .AddParameterConversion((object[] input) => new Complex(TypeConversion.ConvertToDouble(input[0]), TypeConversion.ConvertToDouble(input[1])))
            .AddNullableConversion(treatEmptyAsMissing: true, treatNAErrorAsMissing: true);

            return paramConversionConfig;
        }

Govert van Drimmelen

unread,
May 11, 2018, 10:39:45 AM5/11/18
to exce...@googlegroups.com
Hi Alex,

I think you might have some code in your add-in that calls Array.Empty(), ( https://msdn.microsoft.com/en-us/library/dn906179(v=vs.110).aspx ) which is only supported in .NET Framework 4.6. You can look for such code, or help the user to update their .NET version.

-Govert



From: exce...@googlegroups.com [exce...@googlegroups.com] on behalf of alexs...@gmail.com [alexs...@gmail.com]
Sent: 11 May 2018 03:53 PM
To: Excel-DNA
Subject: [ExcelDna] Initialization [Error] DnaLibrary AutoOpen Error : TargetInvocationException

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To post to this group, send email to exce...@googlegroups.com.
Visit this group at https://groups.google.com/group/exceldna.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages