Tag: IT

C# – Memory stream is not expandable

This COMPLETELY blew my mind!

I had the following code:-

using (MemoryStream contentStream = new MemoryStream(mydata))

      using (WordprocessingDocument myDoc = WordprocessingDocument.Open(contentStream, true))

           MainDocumentPart mainPart = myDoc.MainDocumentPart;

           // Do some stuff




On mainPart.Document.Save I received the error “memory stream is not expandable”.

I was really confused until I found this post


If you include your buffer into the constructor then the stream is not extendable. See below:-

// This CANNOT be extended
MemoryStream stream = new MemoryStream(data);

// This CAN be extended
MemoryStream stream = MemoryStream();
stream.Write(data, 0, data.Length);

So in my case I needed to do the following:-

using (MemoryStream contentStream = new MemoryStream())
   contentStream.Write(mydata, 0, mydata.Length);

Then everything was fine. So beware!

Dynamics 365 – Site Map Custom Titles

I am currently working on update of a Site Map and have Reports listed twice in an Area.

When they display Dynamics is showing a (1) at the end of the second item.

To add custom titles to Areas, Groups, or Sub Areas you use

    <Title LCID="1033" Title="Cool Report Title" />

LCID is the language code.

Full SubArea XML shown below

<SubArea Entity="report" Id="nav_reports" DescriptionResourceId="Reports_Description" AvailableOffline="false" PassParams="false">
  <Privilege Entity="report" Privilege="Read" />
    <Title LCID="1033" Title="Report" />

If you’re not using XrmToolbox (http://www.xrmtoolbox.com/) then why not? Here’s how to select it in Xrm Toolbox.

2017-07-26 11_05_43-XrmToolBox for Microsoft Dynamics CRM _ 365 CE (v1.2017.6.16)

Dynamics 365 – Open entity form using Javascript (with Parameters)

I had a function in a CRM upgrade that was nice and small.


It would open up a copy of the entity I was on with some lookups populated, great right? Well it was. Back in CRM 4 days but not much use now.

Instead you now need to use Xrm.Utility.openEntityForm as below:-

    var parameters = {};
    var childEntityName = Xrm.Page.data.entity.getEntityName();

    //Provide parent record guid
    parameters["_CreateFromId"] = Xrm.Page.data.entity.getId().replace("{", "").replace("}", "");

    //Provide parent record entity type code
    parameters["_CreateFromType"] = Xrm.Page.context.getQueryStringParameters().etc;

    if (Xrm.Page.getAttribute("sampleLookup").getValue() != null) {
        parameters["sampleLookupFieldName"] = Xrm.Page.getAttribute("sampleLookupFieldName").getValue()[0].id.replace("{", "").replace("}", "");

// Note the name on the end
        parameters["sampleLookupFieldNamename"] = Xrm.Page.getAttribute("sampleLookupFieldName").getValue()[0].name;

// Not the type on the end
        parameters["sampleLookupFieldNametype"] = Xrm.Page.getAttribute("sampleLookupFieldName").getValue()[0].entityType;
    if (Xrm.Page.getAttribute("sampleFieldName").getValue() != null) {
        parameters["sampleFieldName"] = Xrm.Page.getAttribute("sampleFieldName").getValue();

Xrm.Utility.openEntityForm(childEntityName, null, parameters);

This opens a new form BUT throws an error. You then need to go into your Customizations, find the form, go to Parameters and make sure that all parameters are listed like so.


Then the form should display with fields pre-populated.

Angular – Class initializers in TypeScript

One thing that is great in C# is the ability to initialise values on create like so: –

MyObject test = new MyObject { Name="Test", Description="This is a description" };

With the release of TypeScript 2.1 you can now do something similar: –

export class MyObject{
    public Name: string;
    public Description: string;

    public constructor(
        fields?: {
            Name?: string,
            Description?: string
        }) {
        if (fields) Object.assign(this, fields);

Then you can use is like so:-

new MyObject({ Name:"Test", Description="This is a description" });

Just make sure that in your package.json that devDependencies has typescript 2.1 or higher.

Dynamics CRM – Going, going, gone

If you or your clients have been using Dynamics CRM it’s time to embrace the future.  Microsoft has combined their Dynamics offerings into a single solution now called Dynamics 365.

If you’re using Dynamics CRM Online you would have already noticed this change and if you’re using On Premise then it’s time to start planning your upgrade.  Dynamics 365 is now setup as follows: –


Sales, and Customer Service leverage heavily on Dynamics CRM functionality, while Operations is based on Dynamic AX, Finance is based on Dynamics NAV/Project Madeira, marketing is a cooperation with Adobe and their marketing cloud offering (build in progress) and the others use a bit of functionality from various other Microsoft projects including some Dynamics.

The issue with the Dynamics family has always been they have been siloed products that have been hard to integrate.  With Dynamics 365 Microsoft have created an end to end solution for your whole customer lifecycle.  Long term the products will be merged together however at the moment it’s just a tightened coupling of the Dynamics suite of product. Short term there is a few awesome features in Dynamics 365 (or in the last release of Dynamics CRM 2016) which you should be using: –

Editable Grids

People have been screaming out for this for a long time.  You can select Editable grids for controls or leave them as the standard Read Only type that users are familiar with.  The ability to allow it only on Web is also a nice feature.


Simple one click to edit


Validation inbuilt.



Power BI integration

Organisation’s love Power BI and now you can imbed it directly into Dynamics 365.  Power BI is a powerful tool that is surprisingly easy to use.  Allowing for key information to be displayed on the dashboard.

Integration with all your Microsoft products

Dynamics 365 is designed to out of the box work with all Microsoft’s suite of products so you can extend it in some amazing ways.

Some of the tools 365 integrates with: –

  • Azure Machine Learning
  • Cortana
  • Microsoft Flow
  • Office 365
  • PowerApps
  • PowerBI
  • SharePoint

Updated SDK code. Upgrading the End Points

If you have old Integration points I strongly suggest you start investigating Microsoft.Xrm.Tooling.  The old OData endpoint is now deprecated and Web API is the way to go.

You can get the SDK from Microsoft’s website (however I had issues with that code) or you can get the NuGet package


Have a look at the following pages to get up to speed quickly on the Xrm Tooling functionality.



Why I love Angular

Having recently started at SSW (https://www.ssw.com.au) I had to learn Angular.  I had heard a bit about it however being firmly in the .Net space I had never learnt anything in detail.

I jumped online and found an course on Udemy by Mosh Hamedani (http://programmingwithmosh.com/) Angular 2 with TypeScript for Beginners: The Pragmatic Guide (https://www.udemy.com/angular-2-tutorial-for-beginners/) and started on my way. NOTE:- Use the Angular CLI for cleaner projects!

Below is a few reasons why I love Angular!


I found the setup and starting processes quite straight forward.  Angular is based on Components which allows us to break up our code into small chunks.  For example lets look at a basic page layout.


We have 3 top level Components (Header, Content, and Footer) and then within Header we have two other components. Each component has its own HTML markup and can interact with the user in different ways.  We can create all of our pages as components that will be displayed in the content space making single page applications easy.

Once we are setup and running the main driver of our site is the app.component.ts file. This TypeScript file is the initial component rendered by our site by default and by adding in some Angular tags we can declare our components.


Above is the base component with our header, router-outlet (where our content goes), and our pagefooter.  Then we can create a header component and add in our children.


Now obviously we need to add in some CSS to control location however as you can see our components can be added easily by including a tag (You also need to include them in your app.module.ts however that’s a discussion for a different day!) and we can then go to work on the individual components.

Without even trying using components has forced us to use the DRY (Don’t repeat yourself) and KISS (Keep it simple stupid) principals.  You obviously could put all your code in one component however if you’re doing that you have bigger issues than worrying about principals!  By using components we ensure reuse is simple to achieve. An example would be if you want to have a page showing cars for sale, create a car component and then repeat it for your data set!

Dependency Injection out of the box!

As someone who understands Dependency Injection but found it harder than it should have been I love how it is built into Angular.

So in Angular I need to use the http object when making service calls so its best if I just inject it.  Here’s my code:-


See what I did there? NOTHING!! I just called it in my constructor and set it to private so its accessible within my whole Component.  I didn’t have to do anything else (although the http or other objects do need to be set to Injectable) and it just works! If you’ve been annoyed with Dependency Injection in the past like me then I’m sure you understand how awesomely simple this is!

Separation of concerns

Ok this might actually be a cheat as any client framework has the same ability however I love it.  In the past I have always had issues with separation of concerns.  So many Developers put all their code into one Project which makes maintenance/deployments REALLY annoying.

With client side frameworks like Angular? You can’t do it.  Your data context is firmly tucked away server side while your connection to it is done at the client.  It clearly separates the UI from the data layer forcibly.

In Summary

If you are a superstar developer you’re probably looking at the above thinking “Big deal I do that anyway” however that isn’t the point.  In Development like anything in life you are only as strong as your weakest link.  There is no point creating amazing code that only you can maintain, instead you want something maintainable by the whole team without you having to explain every detail to them.

That is why I love Angular, it forces even the weakest of coders to follow the basic principals of development which means better code and better applications.  Yes there are a lot more technical reasons why it is awesome that I haven’t mentioned however whenever I look at frameworks I always want to know “How will it help me” and Angular helps me by ensuring that I and my whole team follows the basic standards which while this should always be done sadly isn’t always the case!