.NET core 3.1 to .NET 6.0 Azure Function Upgrade error

I was recently updating a .NET core 3.1 project to .NET 6.0 when I received the following error.

System.TypeLoadException: 'Could not load type 'System.Environment' from assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.'

I had already updated the project properties to point to .NET 6.0

Updated project properties to .NET 6.0

I had also updated all the packages to ensure they were on their latest releases.

The issue was caused by the projects Azures Functions Version not being correctly updated to the latest version that .NET 6.0 requires. It requires v4 whereas .NET 3.1 uses v3

To Update the Project File in Visual Studio 2022 you need select the Edit Project File Option.

Right click the project that needs updating and select Edit Project File

Then update the version within the AzureFunctionVersion tags

Change the version from v3 to v4

Clean the project and rebuild and you should be good to go.

Published article on 3D printing lithophanes

In last months issue of HackSpace (Issue 5) I have an article published on 3D Printing Lithophanes.

My article can be found on page 110 of the magazine and you can view the digital copy of the magazine at HackSpace Magazine for free!

I should have posted this up sooner but things have been a little hectic of late.

Upgrading the AIY Project from MagPi issue 57 Part 2

Further to my previous post about making an update to the AIY Project (found here) I have further extended the functionality of the Read RSS Feed.

Read RSS Feed contains the update project file. I have now converted it to be its own standalone class. Along with this there are a couple of other enhancements

  • Allowed for the passing of properties to read out as an array so it will dynamically create the spoken message.
  • The GPIO pin 23 (the main button with the AIY kit) allows you to cancel to speech. It will finish saying what it is saying but will exit after.
  • Added some unit tests at the end so you can see usage examples.

If you find any issues let me know on the github repo by leaving an issue and I will take a look at it. Any updates will go into that repo so keep an eye on it.

Thanks for reading

Mark

Upgrading the AIY Project from MagPi issue 57 Part 1

So with the release of MagPi issue 57 it came equipped with some hardware provided in partnership with Google to aid in creating a Google Home type device.

Obviously a bit more basic but with the ability to update it and make it your own.

Out the box what is provided is fine, but you get thinking about what you want it to do, and what I wanted was a way for it to tell me the top 10 news headlines from the BBC for the UK.

So by updating the action.py file I created a new class called ReadRssFeed, so instead of only reading the headlines of bbc I can now have it to read any rss feed.

The code is early stages and needs some changing to make it a bit more dynamic but it will give you an idea of what to do.

The Code



# Feedparser is used to parse the rss feeds (for more information view this for a good intro http://www.pythonforbeginners.com/feedparser/using-feedparser-in-python)
# Use pip to install feedparser (sudo pip install feedparser)
# include this at the top of the action.py
import feedparser

#this is the class to read rss feeds (add under the section of "Makers! Implement your own actions here")
class ReadRssFeed(object):
# This is the bbc rss feed for top news in the uk
# http://feeds.bbci.co.uk/news/rss.xml?edition=uk#

#######################################################################################
# constructor
# url - rss feed url to read
# feedCount - number of records to read
# -(for example bbc rss returns around 62 items and you may not want all of
# them read out so this allows limiting
#######################################################################################
def __init__(self, say, url, feedCount):
self.say = say
self.rssFeedUrl = url
self.feedCount = feedCount

def run(self, voice_command):
res = self.getNewsFeed()

# If res is empty then let user know
if res == "":
self.say('Cannot get the feed')

# loop res and speak the title of the rss feed
# here you could add further fields to read out
for item in res:
self.say(item.title_detail.value)

def getNewsFeed(self):
# parse the feed and get the result in res
res = feedparser.parse(self.rssFeedUrl)

# get the total number of entries returned
resCount = len(res.entries)

# exit out if empty
if resCount == 0:
return ""

# if the resCount is less than the feedCount specified cap the feedCount to the resCount
if resCount < self.feedCount:
self.feedCount = resCount

# create empty array
resultList = []

# loop from 0 to feedCount so we append the right number of entries to the return list
for x in range(0,self.feedCount):
resultList.append(res.entries[x])

return resultList

#Under the "Makers! Add your own voice commands here" you can use the following to add a news reader from the bbc
#by saying 'the news' you will be told of the top 10 news headlines from within the uk
actor.add_keyword(_('the news'), ReadRssFeed(say, "http://feeds.bbci.co.uk/news/rss.xml?edition=uk#",10))

Hopefully this is of some use to someone else as well. Any updates I do I will post back up here so everyone is aware.

Touching the Pi

This is my insight into setting up a Pi Zero with a little 3.5″ touch TFT screen that I got from eBay.

The screen I got at the time of purchase was £8.35 (http://ebay.eu/2cpeW8s). There are various listings on eBay for them and they all boil down to pretty much the same screen.

TFT screen

The back of the screen has some helpful information, My screen was the advertised Kedei, however, I had version 6.2. Obviously I can only speak from my  own experience of setting the screen up so for Kedei.

For Kedei device use the following link to get the correct version driver for your screen.

http://en.kedei.net/raspberry/raspberry.html

You can either download the driver for your system or you can get a new image for a full system with the drivers baked in. I did not try the image route but from what I have read online it does work out of the box. The download process is a little slow as it does not offer the best download rate.

The first step is to attach the screen to the device. To connect it to the Pi Zero you need to solder on the 2 x 20 GPIO header pins (not covered in here, but you can find it on the net elsewhere). The screen plugs onto the GPIO pins so that the screen covers the Pi (the cluster of 4 connector sockets go onto the pins that are next to the SD card socket).

After you have connected the screen boot up the Pi and download the needed driver from the location stated above. Once you have the driver downloaded on the Pi you need to unzip it, so navigate to the download location. This is typically done by

cd /home/pi/Downloads

Once there use the following command to unzip the file (replace LCD_Show.tar.gz with the filename of what you downloaded)

tar -xzvf LCD_Show.tar.gz

once it is unzipped navigate to the extracted contents.

cd LCD_Show

Then update your system

sudo apt-get update

After updating the system you can install the driver (the install run name – LCD35_v – may differ in your download but it will look similar, possibly with a number after the v)

sudo ./LCD35_v

Once the install has run the system will reboot.

After the device reboots you should now see that your screen is working and you can use a stylus to touch and navigate. NOTE – the hdmi will no longer work when connected so you will need the TFT screen connected to view an image – at time of writing I have not looked at how to get both working at the same time so you can switch between them, once I have worked it out I will update the post.

To finalise the TFT install, you need to perform the following command

sudo apt-mark hold raspberrypi-bootloader

The above command stops the kernal from updating when performing apt-get update and upgrade commands.

After you have done the above you then need to run

sudo apt-get update

Then finally

sudo apt-get upgrade

To make the device a bit more friendly to use you can install a virtual keyboard so you can have a fairly disconnected device (no keyboard or mouse needed)

open a terminal and run the following command

sudo apt-get install matchbox-keyboard

It is then recommended to reboot the Pi

sudo reboot

To access the keyboard navigate to

MENU -> ACCESSORIES -> KEYBOARD

(these are not my images but give you an idea of whats what)

 

That’s it, hopefully it is all working for you. If you have any issues leave a comment and I will try to help you out.