.NET 4.6.1 or 4.6.2 seem to break IsInRole()

Upgraded application using IsInRole(), now only returns false (vb.net)

Read to the end before making code changes as there is a more obvious thing to check!
 
To support TLS1.2 for PCI requirements I was upgrading one of the applications to 4.6.1, after deployment behaviour controlled by our active directory groups was broken. It was like no one was a member of any AD groups anymore. First I thought it must be a coincidental screw up by someone in AD. It turns out it was something else…
 
The following code is used to check against a list of security groups to see if the current user belongs to any of them.
 
Public Shared Function IsInAdSecurityRole(RoleName() As String) As Boolean
Dim aName As String = Principal.WindowsIdentity.GetCurrent.Name
Dim aDomain As String = aName.Substring(0, aName.IndexOf("\") + 1)
AppDomain.CurrentDomain.SetPrincipalPolicy(
Principal.PrincipalPolicy.WindowsPrincipal)
For index = 0 To RoleName.Count - 1
If Thread.CurrentPrincipal.IsInRole(aDomain & RoleName(index)) Then
Return True
End If
Next
Return False
End Function

The code is ancient, has been in our applications for a very long time but on upgrading to .NET framework 4.6.1 it returns false for all roles. Checked casing and ran in debug inspection and yet failed to see why it stopped behaving as it always had before.
 
Unable to figure out what had happened and with a need to get systems running again I imported the namespace System.Security.Principal
then using the following method all seems well again.
 
Public Shared Function IsInAdSecurityRole(RoleName() As String) As Boolean
Dim currPrincipal As New WindowsPrincipal(New WindowsIdentity(Environment.UserName))
For index = 0 To RoleName.Count - 1
If currPrincipal.IsInRole(RoleName(index)) Then
Return True
End If
Next
Return False
End Function

I used this reference:

My.User.IsInRole() is not working after migrating to 4.6.2 framework in vb.net

 

Authentication mode in project settings Application-defined vs Windows

VB.NET has a setting in the project to say you wish to use application provided authentication method or use the default windows one. This was something that I had totally forgotten existed. It looks like the Authentication mode of the project got changed during the migration. Check the properties of the project, Authentication mode, see if changing it from Application-defined to Windows helps, it did in my case, bringing behaviour back to that which is expected.

 

2018-06-14_12-14-50

Change the drop down combo box to “Windows”

2018-06-14_12-23-38

 

Reference: https://social.msdn.microsoft.com/Forums/en-US/d00b65dd-61d8-4368-b2d2-eaedfc66af40/myusername-is-now-returning-empty-string?forum=vbgeneral

Microsoft Dynamics GP–United Kingdom, Making Tax Digital (VAT) for business MTD / MTSfb

Update: 3rd Aug 2018

Steven MacDonald @SteMac_mhance kindly pointed out on twitter in July that this requirement was being reviewed for inclusion in Dynamics GP2018 R2. 

 

Today, Ian in a post over on his blog, points out a status change on the MTD suggestion Microsoft Dynamics GP and Making Tax Digital

This certainly sounds promising from the MS Suggestion Site https://experience.dynamics.com/ideas/idea/?ideaid=366ea083-6029-e811-bbd3-0003ff68ba15

We are in the process of implementing the changes needed for the Making Tax Digital initiative in the UK. Stay tuned for updates as to when this will be released. 

Original post:

Making Tax Digital is a Her Majesty's Revenue and Customs (HMRC) introducing a mandatory electronic filing of VAT (tax) returns by business by using an application that supports their application programming interface (API). VAT records must be maintained and submitted digitally after April 2019. HMRC are encouraging software developers to engage with them to create applications to interoperate with their APIs HMRC Blog - Digital Relationship Management – A new era in 3rd party software collaboration. Xero and other software companies have been working on the private Beta of the APIs for some time, but what about Microsoft?

HRMC - Overview of Making Tax Digital

HMRC Overview of Making Tax Digital

 

Dynamics GP, SMB products and Making Tax Digital VAT submission MTD

Microsoft Dynamics products AX, NAV, 365 Finance & Operations will all enable customers to be compliant,  the details of how is yet to become clear, perhaps bridging software?

Microsoft Dynamics community- Are you using our accounting software Dynamics NAV or Dynamics 365 Business Central and worried about compliance with Making Tax Digital?

Did you know the Microsoft SMB ERP products also include Dynamics GP too? -Dynamics GP already allows VAT to be recorded electronically and even has the VAT daybook functionally. You would think it not too great a leap to create a little helper application that could pluck the records from the database and submit them via the HMRC web API. It is disappointing that in April 2018 all we have from Microsoft is this page for users of GP.

VAT 2019 digital regulations for Microsoft Dynamics GP

that points to the suggestion list for new features for GP…

Suggestion: GP needs VAT electronic filing to be compliant with Making Tax Digital initiative

So one may think from this that there are no plans in action at the moment for it to be supported, on the other hand you could take the view this is Microsoft acknowledging the requirement, perhaps Terry may well have had her ear bent by the UK Dynamics partners thus creating this page? Admittedly it is a year away and the MS developers can work quite quickly when they need to. Also to be fair this product suggestion site is the funnel through which new features/requirements should be captured, so perhaps it is in hand?

However it would be nice to know soon if UK customers need to find another 3rd party bridging software to the HMRC APIs soon so we can start answering our Finance Directors and Controllers questions about what the plan is for 2019 (and yes that question sparked this blog post).

 

Spreadsheets

What is amusing is that HMRC have announced that spreadsheets are acceptable when used with bridging software to the APIs – heaven knows what accountants would do without them!

“Businesses will be able to continue to use spreadsheets for record keeping, but they must ensure that their spreadsheet meets the necessary requirements of Making Tax Digital for Businesses. This is likely to involve combining the spreadsheet with software.”

Accounting web- Spreadsheets for Making Tax Digital – The universal language of accounting

 

I will update this post if there are further developments over the year.

Setting multi-line text box control in a Microsoft Dynamics GP add-in to be empty or blank

When working with multi-line text boxes (Text Tool), rather than single line edit boxes, it is easy to introduce a bug to your application.

Blank edit box in Dynamics GP Addin

The text box contents can be set with the the example code below:

ItemMaint.LocalTxtExtraInfo.Value = result.ExtraInfoDescription

…where the value of the right hand side is written to the control’s value and is thus displayed.

As the record set is scrolled, by for example, the user using the form’s scroll buttons, then this code may be called repeatedly to show this field’s value for each record in turn.

The problem I experienced, occurs when after displaying a value for the first record in the field, a subsequent record happens to be empty. In this case  the empty string is assigned to the control’s value, but the control does not blank itself in the user interface. In fact in debug, looking at the control’s value immediately after setting it to string.empty, it is found that the value has not changed from the previous record. 

So we have found that the field is not updated if an empty string is assigned to it. This seems to be a design decision in the  way the objects have been designed to behave. Hence the field will retain the previous record’s value until the next non-blank value in encountered in the record set.

This not only misleads the user as the incorrect field data is displayed for what should be an empty field, but it also, if the record is “saveable” of writing that wrong value back to the database, thus corrupting the field’s value “permanently” in the database (this is what brought my attention to the issue).

So if this control is used in your addin- always remember to use the following pattern, or equivalent to check for empty values. This uses the fields clear method to correctly empty the field on empty strings.

If result.ExtraInfoDescription.Length = 0 Then
ItemMaint.LocalTxtExtraInfo.Clear()
Else
ItemMaint.LocalTxtExtraInfo.Value = result.ExtraInfoDescription
End If

Note:
This behaviour is not followed by the normal edit boxes, they will blank when string.empty is assigned to them.

 

If you found this helpful, feel free to comment, it helps motivate me to write more!

WCF Registered base address schemes are []

Moved WCF service from old server to 2012 server to find the WCF service would not run. It complained that

"Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are []"

Stack overflow post below was the lead as to how to resolve it:

WCF Registered base address schemes are [] error with https

With a fake IP address for purposes of this post, the WCF config section had the follow lines, removing the <add prefix… line from the .config brought the service to life.

<baseAddressPrefixFilters>
<add prefix="http://127.0.0.1/DataService/"/>
</baseAddressPrefixFilters>
 
So what is the baseAddressPrefix? –it is for dealing with where there are multiple IIS bindings for a site providing a listening filter for the service.

To quote MS documents:

“A prefix filter provides a way for shared hosting providers to specify which URIs are to be used by the service. It enables shared hosts to host multiple applications with different base addresses for the same scheme on the same site.+

IIS Web sites are containers for virtual applications which contain virtual directories. The application in a site can be accessed through one or more IIS bindings. IIS bindings provide two pieces of information: binding protocol and binding information. Binding protocol (for example, HTTP) defines the scheme over which communication occurs, and binding information (for example, IP Address, Port, Hostheader) contains data used to access the site.

IIS supports specifying multiple IIS bindings for each site, which results in multiple base addresses for each scheme. Because a WCF service hosted under a site allows binding to only one base address for each scheme, you can use the prefix filter feature to pick the required base address of the hosted service. The incoming base addresses, supplied by IIS, are filtered based on the optional prefix list filter.”