Tags

, , , ,

.NET Gadgeteer now supports v4.2 of NetMF, which means that you can now code in VB! For those of you that use the Resources feature you may notice that there is a slight bug.

For example importing and using an image as a resource does not work as expected (if you come from C# land).

Step 1

image

Create a project and go to the project properties. Use the ‘Add Resource’ option at the top to add an image (or text, icon, text file). I have added two images here.

Step 2

Normally you would just be able to use the the resource by calling the resources object:

Resources.GetBitmap(Resources.BitmapResources.Image1)

However as you type ‘Resources’ intelisense lets you know something is up.. You want the object not the namespace?? Ok so what is up here.

image

Debug

If you look at the code that is generated behind (when you import a resource) you can see that a Namespace has been added to the code. The Namespace is the name of the project, in my case ‘Resource Check’  – ok it is just my debug naming.

image

TIP: Resources.Designer.vb is not listed as a project file (it is auto generated and changes will be discarded) but you can see it if you look in the file system.

Workaround

Since your resources are in a Namespace the easiest way to use them is to reference them using the full name. For example, intelisense helps at this stage showing that I have two resources:

image

The resulting code is as follows:

Resource_check.Resources.GetBitmap(

Resource_check.Resources.BitmapResources.Image1)

(‘Resource_check’ is my project name – make sure you use your project name)

Other info

Since I started this article I noticed this post:

http://blog.vbmagic.net/2012/06/24/net-micro-framework-and-vb-net-on-fez-spider-a-couple-of-gotchas/

The post recommends removing the Namespace declaration from the auto generated Resource.Designer.vb file but this will just get over written every time you add a resource.

James has added a comment regarding a fix which is to declare the namespace in the Project.vb file. Such as:

image

If you do this then you will also need to add it to the Program.generated.vb file as well. (This file is auto generated, changes will get overwritten)

 

Hope that helps!