Resize Function Not working in an external library

Oct 9, 2012 at 3:11 PM

Hey,

 

User of ExcelDNA since now 4 years to have my C# Library available in Excel, I'm using the first version of the "resized" function from the google group to display an array in Excel as bloomberg.

Following few problem for a new function, I updated my version of ExcelDNA for the last one (0.29).

And here is my problem, If I use the example of resize which is in samples section (so I use diretcly the dna file), it works. If I create a C# library with exactly the same code, add a reference to ExcelDna.integration and compile it, the MakeArray function is working but not the resize function.

Obviously, I changed the dna to put my path (instead of the code of the example) and I don't have any error when I load the addin.

DNA file:

<DnaLibrary><ExternalLibrary Path="S:\Applications\Dev\Test_Resize\Test_Resize\bin\Debug\Test_Resize.dll" /></DnaLibrary>

 

So I wonder if I do something wrong or if there is a conflict somewhere in the case you use "resize" from an external library.

 

I precise that it was working fine before today since few years now.

 

Tks

 

Coordinator
Oct 9, 2012 at 5:57 PM

Hi,

I had a quick look , and can't reproduce a problem.

I take the code from the Excel-DNA v 0.29 release, in the Distribution\Samples\ArrayResizer.dna file, and put into a compiled C# library, and all runs fine.

I'm not sure what might be different in your case.

  • Do you see the Resize function in Excel?
  • Can you debug the library, to see whether any errors pop up?
  • You could make a minimal library that just has that code in, and if that does not work you can send it to me to have a look.

You might also be brave and try the latest download - a test version for Excel-DNA v 0.30. There the ArrayResizer is simplifies a bit by using the ExcelAsyncUtil class. But anyway, the v 0.29 code seems to work for my.

-Govert

Oct 10, 2012 at 7:50 AM

Hey,

 

Thanks for the answer, I just found the issue.

You can only make it working if the C# external library is in the C drive. I was compiling my project in a shared drive and linking it via the dna file. If you do that, all the function are available in excel but the resize is crashing (showing NA).

BTW I now use the last version 0.30 so will give you a feedback if I encounter any issue.

 

Tks,

 

Santino

Coordinator
Oct 10, 2012 at 1:57 PM
Edited Oct 10, 2012 at 1:57 PM

Hi Santino,

I can't really think of a reason why, when loading from a network share, the functions would be available, but the resize macro would fail. Under .NET 2.0 there used to be some permissions issues for libraries over the network, but that should make the whole library load or fail, not parts of the functionality.

I wonder if you might have different add-ins loaded, and the functions are either coming from a different add-in, or at least not from the same .dll as the resizer?

Do you mean this is the case also with the latest version 0.30?

Thanks,

Govert

Oct 10, 2012 at 2:34 PM
Edited Oct 10, 2012 at 2:36 PM

To avoid any potential conflict, I:

-Unloaded both production and dev Exceldna Addin

-Deleted every Excel addin file on the C drive

-Restarted the computer

-Created a simple Addin with just the resize code

-Compiled the addin and put it on the share drive

-Changed the dna file to point to the addin location

=>then I can see the functions and the function MakeArray is working but the resize is crashing (NA).

-I relocated the addin to the C drive and changed the dna file to point out to the new location

=> I can see the functions and the resize is working

 

All that with the 0.29 and the 0.30, whatever the version and I think I had the same problem in the past (but not sure about it).

So for sure, nothing else loaded, and now I got the same trouble with my RTD contribution system. The RTD function (to retrieve data) isn't working if I link the dna file to a library on the share drive but it works with a local library.

I use .NET 2.0 for my addin (as I think the 4.0 wasn't working with exceldna, at least in the past).

 

I hope that give a better idea of the problem, I tried the debug and it was crashing at the first line without any error msg (ExcelReference caller = XlCall.Excel(XlCall.xlfCaller) as ExcelReference;).

 

So I'm a bit blind here, not a huge deal by itself for the production addin but for the dev addin.......I will have to transfer each time the addin compiled to the C drive to test...not fun.

Coordinator
Oct 10, 2012 at 3:08 PM

Hi Santino,

Thanks for checking so carefully. I'll try to recreate the problem on this side. The RTD issue might well be related.

1. Make sure you don't have a copy of ExcelDna.Integration.dll in your add-in directory. It never needs to be present in the output directory (best is to mark the reference as "Copy Local=false" in your project), and if a mismatched version is present there can be all kinds of trouble.

2. I'd be interested to know whether .NET 4.0 has the same problem - it has been supported by Excel-DNA since August 2010. If this is related to .NET Code-Access Security (CAS) then it should behave different in .NET 4.0. You just change the .dna file like this:

<DnaLibrary RuntimeVersion="v4.0" >
...
</DnaLibrary>

3. Try to change your external library to load 'as bytes' This might circumvent some security issues by loading the assembly in a different way. For this you change the .dna file to:

<DnaLibrary>
  <ExternalLibrary Path="..." LoadFromBytes="true" />
</DnaLibrary>

Let me know if these changes make any difference.

Regards,

Govert

Oct 10, 2012 at 3:34 PM

1. I just copy it as I use other external library like Mysql so by laziness, I just put everything with the library but will exclude in the future

 

2. I've done exactly the same as above and reproduce the same problem, resize is only working with a library on the C drive. Then I changed the dna file to add RuntimeVersion="v4.0" and it works!! The resize function is then working (even if the Basic library created for the occasion was using .Net 2.0)

 

3. It work as well, If I reproduce the problem and only change to load "as bytes" then resize is working.

 

So both solution fixed the problem, will make my life much easier, thank you

 

Santino

Coordinator
Oct 10, 2012 at 3:58 PM

Hi Santino,

Does 1., without doing 2. or 3., also fix the problem, i.e. if you just delete the copy of ExcelDna.Integration.dll on the share?

-Govert

Oct 10, 2012 at 4:08 PM
Edited Oct 10, 2012 at 4:08 PM

Just tried and no, with the basic dna file without 2 and 3, if I just delete ExcelDna.Integration.dll from the share drive then I can see the functions but resize isn't working.

 

Only 2 or 3 fix the problem.

 

Santino