AutoOpen() not being called

669 views
Skip to first unread message

Farhan Ahmed

unread,
Jul 25, 2012, 10:57:39 AM7/25/12
to exce...@googlegroups.com
After the fiasco with installing the Office 15 Beta alongside 2010, I had to pave my machine and re-install VS2010 and Office 2010. 

For some reason, now when I run my code, the AutoOpen() function doesn't get called. The add-in definitely gets loaded since I see my UDFs in Excel. Anyone seen this before?

Thanks!
--

Govert van Drimmelen

unread,
Jul 25, 2012, 11:22:35 AM7/25/12
to Excel-DNA
Hi Farhan,

I'm glad you do these silly things, so that we don't have to!

I'm guessing you have an extra copy of ExcelDna.Integration.dll in
your output directory. You never need this file in the output - a copy
is embedded inside the ExcelDna.xll - so you can just delete it from
the output and then restart your Excel to check. In the Visual Studio
project you can mark the reference as "Copy Local = false" to prevent
it being copied to the output.

Otherwise - is it possible that there is some error when loading the
type implementing AutoOpen, e.g. that type depends on some assembly
that was in your GAC before, but with the reinstallation is not there.

You can also attach a debugger to the Excel before you load the .xll,
then look at the debug output for anything suspicious.

Regards,
Govert

Farhan Ahmed

unread,
Jul 25, 2012, 12:07:55 PM7/25/12
to exce...@googlegroups.com
Ah, this one's for the books :).

In my main class (that extends IExcelAddin), I had a static initializer for a Dictionary that listed the same key twice. This was causing an exception to be thrown while creating an instance of my class and hence the AutoOpen wasn't being called. Removed the duplicate and everything is fine and dandy now.

Cheers.

On Wed, Jul 25, 2012 at 10:56 AM, Farhan Ahmed <far...@ycharts.com> wrote:
Hey Govert,

I don't think it's the extra copy issue. I actually added the ExcelDna.Integration project to my solution and set some breakpoints. Looks like this piece of code is throwing an exception when it tries to create an instance of my addin class:


 static public void GetExcelAddIns(ExportedAssembly assembly, Type t, bool loadRibbons, List<ExcelAddInInfo> addIns)
 {
            try
            {
                Type addInType = t.GetInterface("ExcelDna.Integration.IExcelAddIn");
                bool isRibbon = (t.BaseType == typeof(ExcelRibbon));
                if (addInType != null || (isRibbon && loadRibbons) )
                {
                    ExcelAddInInfo info = new ExcelAddInInfo();
                    if (addInType != null)
                    {
                        info.AutoOpenMethod = addInType.GetMethod("AutoOpen");
                        info.AutoCloseMethod = addInType.GetMethod("AutoClose");
                    }
                    info.IsCustomUI = isRibbon;
                    info.Instance = Activator.CreateInstance(t);
                    info.ParentDnaLibrary = assembly.ParentDnaLibrary;
                    addIns.Add(info);
                }
            }
            catch (Exception e) // I think only CreateInstance can throw an exception here...
            {
                Debug.Print("GetExcelAddIns CreateInstance problem for type: {0} - exception: {1}", t.FullName, e);
            }
}




Here's the exception detail:

System.Reflection.TargetInvocationException was caught
  HResult=-2146232828
  Message=Exception has been thrown by the target of an invocation.
  Source=mscorlib
  StackTrace:
       at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
       at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
       at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
       at System.Activator.CreateInstance(Type type, Boolean nonPublic)
       at System.Activator.CreateInstance(Type type)
       at ExcelDna.Integration.AssemblyLoader.GetExcelAddIns(ExportedAssembly assembly, Type t, Boolean loadRibbons, List`1 addIns) in C:\code\ExcelDNA\Source\ExcelDna.Integration\AssemblyLoader.cs:line 159
  InnerException: System.TypeInitializationException
       HResult=-2146233036
       Message=The type initializer for 'YChartsExcelAddin.YChartsMain' threw an exception.
       Source=YChartsExcelAddin
       TypeName=YChartsExcelAddin.YChartsMain
       StackTrace:
            at YChartsExcelAddin.YChartsMain..ctor()
       InnerException: System.ArgumentException
            HResult=-2147024809
            Message=An item with the same key has already been added.
            Source=mscorlib
            StackTrace:
                 at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
                 at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
                 at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
                 at YChartsExcelAddin.YChartsMain..cctor() in C:\code\ycharts_excel\YChartsExcelAddin\YChartsExcelAddin\Class1.cs:line 119
            InnerException: 

Do you think it's something in the constructor or static initializers for my class?

Thanks,
Farhan

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To post to this group, send email to exce...@googlegroups.com.
To unsubscribe from this group, send email to exceldna+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.




--
Farhan Ahmed




--
Farhan Ahmed

Farhan Ahmed

unread,
Jul 25, 2012, 11:56:30 AM7/25/12
to exce...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To post to this group, send email to exce...@googlegroups.com.
To unsubscribe from this group, send email to exceldna+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.

Farhan Ahmed

unread,
Jul 30, 2012, 12:13:55 PM7/30/12
to exce...@googlegroups.com
It gets called by ProcessAssemblies in AssemblyLoader.cs.

On Fri, Jul 27, 2012 at 2:22 PM, Nikee <ocean....@gmail.com> wrote:
Farhan

I am just curious...

How does  "GetExcelAddIns" method gets invoked ? 

Thanks
Cheers.

To unsubscribe from this group, send email to exceldna+unsubscribe@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To view this discussion on the web visit https://groups.google.com/d/msg/exceldna/-/XLJ7wXnIyFQJ.

To post to this group, send email to exce...@googlegroups.com.
To unsubscribe from this group, send email to exceldna+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/exceldna?hl=en.
Reply all
Reply to author
Forward
0 new messages