Update C Sharp Module authored by Daniel Kluge's avatar Daniel Kluge
To show that AAS can be implemented in any programming language, one component had to be created in another language.
## Choosing the language
Because we are already familiar with it, using the BaSyx framework seemed to be a good start.
On [GitHub](https://github.com/eclipse-basyx), not only a Java implementation but also implementations in C++, Rust, Python, and C#, can be found.
### BaSyx Python SDK
Because it is arguably one of the easiest languages I chose the [BaSyx Python SDK](https://github.com/eclipse-basyx/basyx-python-sdk) formerly known as "PyI40AAS".
It was straightforward to create an AAS and a submodel.
The last step is to publish that model on a server.
And that is where it got complicated.
The Java SDK, which is used in all other components of this project, provides an easy way to host an AAS and the submodel descriptions.
The Python SDK does not seem to have any of this functionality.
Even implementing a webserver manually seems like a huge project, as the [`Submodel`](https://github.com/eclipse-basyx/basyx-python-sdk/blob/main/basyx/aas/model/submodel.py) class has no method to output a description of itself in JSON.
The Python SDK is more suited for operations on AASX packages on the disk and can not be used to show interoperability.
### BaSyx .NET SDK
Because C# is similar to Java in some ways, the [BaSyx .NET SDK](https://github.com/eclipse-basyx/basyx-dotnet) was the next candidate for this implementation.
I never used C#, so for me, it was a difficult task.
The documentation on this SDK is not great, but there are [examples](https://github.com/eclipse-basyx/basyx-dotnet-examples) I can use for my sake.
The example [HelloAssetAdministrationShell](https://github.com/eclipse-basyx/basyx-dotnet-examples/tree/main/HelloAssetAdministrationShell) was a good starting point.
Using it, I implemented the [GreenLight asset](https://gitlab.hrz.tu-chemnitz.de/vws-demo/vws-spielwiese/-/blob/main/basyx.lichterkette/src/main/java/de/olipar/basyx/lichterkette/GreenLight.java) from the existing project.
One could think that both SDKs are "Eclipse BaSyx" so the implementations should be pretty much the same, but that's not the case.
This is way I also created [a walkthrough](follow-up/C%23-Module-walkthrough) for the implementation.
One of the best things about this SDK is that the webserver which hosts the AAS has a great UI for experimenting.
You can test calls and update properties as you wish.
Even without any prior knowledge of C#, it took not long to implement the asset.
The hardest challenge was to register the asset and submodels to the registry.
No example used an external registry so no documentation was given.
After a lot of trial and error (mostly error), I found out that the dependencies of this project not only use packages from the [BaSyx .NET SDK](https://github.com/eclipse-basyx/basyx-dotnet-sdk) but also the [BaSyx .NET components](https://github.com/eclipse-basyx/basyx-dotnet-components) which is similar to the Java implementation.
In the components repository I found what I was looking for: `BaSyx.Registry.Client.Http`.
By only using this package the AAS service acquired a new method called `RegisterAssetAdministrationShell`.
But it has no way to unregister the AAS so I still needed the `RegistryHttpClient` nonetheless.
After that everything worked flawlessly.
As the existing project operates normally which blinking lights, the new implementation logs when the light turns on or off.
## Additional hints
### Missing NuGet source
When I installed Visual Studio and opened any example project or the SDK it couldn't resolve the dependencies.
When opening _Extras > NuGet package manager > Manage NuGet packages for this project_, I noticed in the top right that "Microsoft Visual Studio Offline Packaged" was the only source available.
To fix that, add the default [nuget.org registry](https://nuget.org) by doing the following:
- Click on the settings icon right next to it.
- Press on the "+" icon on the top right.
- A new entry should now be shown in the list.
- On the bottom, you can set the name and source for the entry.
- Put anything as the name and `https://api.nuget.org/v3/index.json` as the source.
- Click "Refresh" and "OK".
Now the dependencies can be resolved.
### Licensing
While the [BaSyx .NET Examples repository](https://github.com/eclipse-basyx/basyx-dotnet-examples) uses the [Eclipse Public License - v 2.0](https://www.eclipse.org/legal/epl-v20.html), the two C# code files are licensed under the [Eclipse Distribution License - v 1.0](https://www.eclipse.org/org/documents/edl-v10.html) (as shown [here](https://github.com/eclipse-basyx/basyx-dotnet-examples/blob/df541b0352209f78c3e6a0d00109573689ffb739/HelloAssetAdministrationShell/HelloAssetAdministrationShellService.cs) for example).
Because this module uses code and other resource files from the example repository, the licenses apply to the respective parts.
\ No newline at end of file