Warning XLL function designer

Add-in Express™ Support Service
That's what is more important than anything else

Warning XLL function designer
Warning after XLL UDF function designer use 
Michael Kaden




Posts: 113
Joined: 2017-11-15
Hello,

I have introduces a simple function into the XLL Container. After I open the Designer and add the category "AdxExcelFunctionCategory1" and without going any further, I get a warning on build:

(alterations only through the designer not code)


Severity Code Description Project File Line Suppression State
Warning CA2214 'XLLModule.New()' contains a call chain that results in a call to a virtual method defined by the class. Review the following call stack for unintended consequences:

XLLModule..ctor()
XLLModule.InitializeComponent():Void
XLLModule.get_AdxExcelFunctionCategory1():ADXExcelFunctionCategory aleraXLL002 C:\aleraSoft\aleraXLL02\aleraXLL002\aleraXLL002\XLLModule.Designer.vb 4 Active

this refers to line 4 = Public Sub New()

of the XLL Module


Partial Public Class XLLModule

<System.Diagnostics.DebuggerNonUserCode()>
Public Sub New()
MyBase.New()

'This call is required by the Component Designer
InitializeComponent()

'Please add any initialization code to the AddinInitialize event handler

End Sub

'Component overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()>
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub

'Required by the Component Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Component Designer
'It can be modified using the Component Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()>
Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container()
Me.AdxExcelFunctionCategory1 = New AddinExpress.MSO.ADXExcelFunctionCategory(Me.components)
'
'AdxExcelFunctionCategory1
'
Me.AdxExcelFunctionCategory1.CategoryName = \"AdxExcelFunctionCategory1\"
'
'XLLModule
'
Me.AddinName = \"aleraXLL002\"

End Sub

Friend WithEvents AdxExcelFunctionCategory1 As AddinExpress.MSO.ADXExcelFunctionCategory
End Class


Any idea what causes this, and how it can be prevented/fixed.

Than you very much for your help

regards

Michael
Posted 26 Nov, 2017 13:50:03 Top
Michael Kaden




Posts: 113
Joined: 2017-11-15
I tried to come closer to a solution, i.e. wanted to make absolutely sure that the problem is not because of any code I added, So I tried from "scratch"

I took the “native” sample as download from:

http://temp.add-in-express.com/support/MyXLLAddin23-GetCallerAddressVb.zip.

Then I unzipped and loaded the project.

I selected “enable Code Analysis on build”

Then I build the MyXLLAddin23
No Problem
Then I opened XLL Module View designer
Then I added AdxExcelFunctionCategory1
Build = no problem
Then I added function Get CallerAddress
Build = 2 x warning CA2214

pleaee advise

Michael
Posted 27 Nov, 2017 08:00:09 Top
Andrei Smolin


Add-in Express team


Posts: 14889
Joined: 2006-05-11
Hello Michael,

I've reproduced the issue. We look into it.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Nov, 2017 08:17:15 Top
Andrei Smolin


Add-in Express team


Posts: 14889
Joined: 2006-05-11
Hello Michael,

We recommend that you suppress getting this warning.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 27 Nov, 2017 09:55:46 Top
Michael Kaden




Posts: 113
Joined: 2017-11-15
Dear Andrei

thank you for the info.

MS strongly advises not to suppress this Warning. Is there any possibility not to call a type's virtual methods from within the type's constructors. See:

https://docs.microsoft.com/de-de/visualstudio/code-quality/ca2214-do-not-call-overridable-methods-in-constructors

For the time being we will ignore the warning, but please advise if and when there is a fix available.

thank you

regards

Michael
Posted 27 Nov, 2017 10:21:05 Top
Andrei Smolin


Add-in Express team


Posts: 14889
Joined: 2006-05-11
Hello Michael,

We regard this as an issue in Code Analysis.

To create a test project, I followed your instruction:

1) create an add-in project from scratch, set the Enable Code Analysis on Build flag - building the project doesn't produce the issue
2) put an ADXExcelFunctionCategory component on the module - building the project doesn't produce the issue
3) add an ADXExcelFunctionDescriptor component to the ADXExcelFunctionCategory - building the project produces two warnings

Now, if I remove the ADXExcelFunctionDescriptor just added and rebuild the project, I get a single warning; there was no warning on step 2. This difference is fact #1.

On this step my code is this:

    Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container()
        Me.AdxExcelFunctionCategory1 = New AddinExpress.MSO.ADXExcelFunctionCategory(Me.components)
        '
        'AdxExcelFunctionCategory1
        '
        Me.AdxExcelFunctionCategory1.CategoryName = "AdxExcelFunctionCategory1"
        '
        'XLLModule
        '
        Me.AddinName = "MyXLLAddin26"

    End Sub


The warning suggests that the call stack below "results in a call to a virtual method defined by the class":

XLLModule..ctor()
XLLModule.InitializeComponent():Void
XLLModule.get_AdxExcelFunctionCategory1():ADXExcelFunctionCategory

Note that on step #2, we got the very same code but it didn't produce the issue (this is another mention of fact #1).

Back to the message. XLLModule doesn't define a virtual method. There are three virtual methods that ADXXLLModule declares:

Protected Overridable Sub OnHostApplicationInitialized()
Public Overridable Function GetContainer() As IContainer
Protected Overridable Function GetXLLContainerType() As Type

Also, there are four virtual members declared by the Component class (ADXXllModule descends from it):

Public Overridable Property Site As ISite
Protected Overridable ReadOnly Property CanRaiseEvents As Boolean
Protected Overridable Sub Dispose(disposing As Boolean)
Protected Overridable Function GetService(service As Type) As Object

None of these are invoked from the constructor. So fact #2 is: the warning message contradicts to what we have in code.

Fact #3: we can't reproduce the issue using a similar C# project.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Nov, 2017 06:26:11 Top
Andrei Smolin


Add-in Express team


Posts: 14889
Joined: 2006-05-11
Ha! The issue goes away if you delete WithEvents from declarations of the corresponding variables! And you may delete it if you don't use the Disposed event.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Nov, 2017 06:34:24 Top
Michael Kaden




Posts: 113
Joined: 2017-11-15
Thank you Andrei this works,

I only use the designer so I can set the hidden=true properties in the UDF. Is there another method to set the hidden = true property without using the designer?

regards

Michael
Posted 29 Nov, 2017 05:35:02 Top
Andrei Smolin


Add-in Express team


Posts: 14889
Joined: 2006-05-11
Hello Michael,

Michael Kaden writes:
I only use the designer so I can set the hidden=true properties in the UDF. Is there another method to set the hidden = true property without using the designer?


I assume this question doesn't relate to getting a warning when having the "Code Analysis on build" check box selected. If this isn't the case, please correct me.

Do you hide a function? If so, setting the IsHidden property on the corresponding function descriptor is the only way to achieve this; using the designer is the a convenient way to set that property. Why would you need to avoid using the designer?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 29 Nov, 2017 06:47:02 Top
Michael Kaden




Posts: 113
Joined: 2017-11-15
Dear Andrei,

The first idea was to solve the Warning we had. This is now solved in another way (take WithEvents out).

I assumed one can set the function descriptor by code without the designer.

I still have in the back of my head that I might have to go back to a ComAddIn later in the development of this project to use Excel.Object.Model. I only will know that when I have transferred more components of the VSTO project to ADX. In case that I need the ComAddIn, I am searching for a work around to make ComAddIn UDF's hidden. Yes, I know that you said it is not possible by design. But I do not take "No" for an answer easily.

During the work with Vb.net & VSTO I got many "Not possible" including from MS & MSDN but often found a reliable possibility to reach my goals.

Thank you very much for the continued support, very much appreciated

regards

Michael
Posted 29 Nov, 2017 08:47:55 Top