You'll find a list of tips and tricks to help in the migration. There is no specific order in this list.
The project conversion, transformation os Span<byte>
to SpanByte
and other associated elements are done automatically.
- Issue: .NET nanoFramework supports a limited version of enum, so
GetValues
,IsDefined
are not available. - Resolution: just remove the
IsDefined
, this is used for check only. If you need the nice names with theGetValues
use either a switch or string or anything like this depending on the scenario.
- Issue: multidimensional
Arrays [,]
are not supported in .NET nanoFramework - Resolution:
- Replace them with
Array [][]
- Initialization is different, example:
// byte[,] array = new byte[42,15]; byte[][] array = new byte[42][]; for(int i = 0, i < 15; i++) { array[i] = new byte[15]; }
- If you have something lile
public int this[int x, int y]
, you'll need to create a class, example:
class Point { public Point(int X, int y) { X = x; Y = y; } public int X { get; set; } public int Y { get; set; } } public int this[Point pt] // and get access to pt.X and pt.Y // ... // Access is then like: Somthing[new Point(12,34)];
- Replace them with
- Issue: There is no generic (yet) and no Queue in nanoFramework. Most of the time, the usage of those elements are simple.
- Resolution: Replace the Queue by a
ArrayList
and useAdd
andRemove
with a cast to read the data.
- Issue:
Console
is not available in .NET nanoFramework. It does only appear on the sample side. - Resolution: can be replaced by
Debug
. And theConsole.Read
and other elements like this from the samples can be replaced by hard coded data or constants.
You may have to compile some of the projects in unsafe mode. This is needed if you are using unsafe blocks or unsafe instructions into your project.
Add <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
in the nfproj in the property group PropertyGroup
right after then language version.
When converting, you may move some code, change some properties or functions a bit, that may need adjustment in README and other documentation, don't forget to adjust those! This does include as well replacing schema from Raspberry Pi to our lovely MCU. Any ESP32 or any STM32 or any supported MCU will be enough.
It is recommended to update the nugets with a dotnet restore
before opening the solution.
You may be stuck sometimes because some references may be corrupted and you won't be able to update or add a new nuget. In this case, you can try to downgrade by one version all the nugets and then update them again, this will pull potential missing references.