Description:
After upgrading to XXX version, I get the NullReferenceException exception ("Object reference is not set to an instance of an object") when using custom skins. Why does this problem occur, and how to overcome it?
Answer:
This problem can occur after the upgrade if we add or change elements in our skins. After upgrading our components to a new major version, you need to rebuild your custom skin libraries via the SkinEditor utility:
- Open your project.
- Remove references to your custom skin libraries.
- Remove corresponding skin DLLs from the project folder (and from GAC, if you installed them here).
- Open the custom skin's sources via SkinEditor and create a new assembly.
- Add a reference to this assembly in your project.
Another problem is that the error message can be shown if you try to open a skin created with a previous version in the Skin Editor. We constantly improve our skins by adding new elements to them. When you are opening a skin via the Skin Editor, it tries to obtain all necessary elements. If a specific element is not found in the skin, the Skin Editor tries to find it in the parent skin and updates your skin accordingly. That's why if you make your custom skin a descendant of our skin, it will be opened without any problem, because newly introduced elements will be found in the base class. However, if your skin has no parent, the Skin Editor can't find some necessary elements, and the exception is thrown. To solve the problem, it's necessary to specify a parent for your custom skin (the *.skin file):
XML<SkinItems version="1.0" application="SkinEditor" assembly="MyAssembly" class="" extranamespace="">
<Item>
<ItemName>MyCustomSkin1</ItemName>
<TemplateName>Caramel</TemplateName> <------------------ Parent exists
</Item>
<Item>
<ItemName>MyCustomSkin2</ItemName>
<TemplateName>Caramel</TemplateName> <------------------ Parent exists
</Item>
<Item>
<ItemName>MyCustomSkin3</ItemName>
<TemplateName>Caramel</TemplateName> <------------------ Parent exists
</Item>
<Item>
<ItemName>MyCustomSkin4</ItemName>
<TemplateName>MyCustomSkin4</TemplateName> <-------------------- No parent. Needed to be changed : <TemplateName>Caramel</TemplateName>
</Item>
<Item>
<ItemName>MyCustomSkin5</ItemName>
<TemplateName>MyCustomSkin5</TemplateName>
</Item>
</SkinItems>
See also:
Troubleshooting - Skins and Skin Editor