04-19-2023 07:50 AM
Hello Forum,
I am facing a strange issue about teststand and the .Net adaptor.
I have build a library in C#, export it as DLL. The main class is public, and i call the constructor in TestStand.
In this contrustor I use a NuGet lib to parse Json File.
I chose the lib from Microsoft to avoid any compatibility issue...
But… I got issue with TestStand.
When i call with TestStand, i got error that it need an old lib:
An exception occurred inside the call to .NET member 'MachineBinding':
System.IO.FileNotFoundException: Impossible de charger le fichier ou l'assembly 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' ou une de ses dépendances. Le fichier spécifié est introuvable.
Nom de fichier : 'System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
à System.ReadOnlySpan`1..ctor(T[] array)
à System.Text.Json.Serialization.Metadata.JsonPropertyInfo.CacheNameAsUtf8BytesAndEscapedNameSection()
à System.Text.Json.Serialization.Metadata.JsonPropertyInfo.Configure()
à System.Text.Json.Serialization.Metadata.JsonTypeInfo.InitializePropertyCache()
à System.Text.Json.Serialization.Metadata.JsonTypeInfo.Configure()
à System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureLocked|143_0()
--- Fin de la trace de la pile à partir de l'emplacement précédent au niveau duquel l'exception a été levée ---
à System.Text.Json.Serialization.Metadata.JsonTypeInfo.<EnsureConfigured>g__ConfigureLocked|143_0()
à System.Text.Json.JsonSerializerOptions.GetTypeInfoInternal(Type type, Boolean ensureConfigured, Boolean resolveIfMutable)
à System.Text.Json.JsonSerializer.GetTypeInfo(JsonSerializerOptions options, Type inputType)
à System.Text.Json.JsonSerializer.Deserialize[TValue](String json, JsonSerializerOptions options)
à PLC_Automation.CoreGeneric.Config..ctor(Int32 instanceNb, String pathToPlcConfFile)
à PLC_Automation.CoreGeneric.MachineBinding..ctor(Int32 instanceNb, String pathToPlcConfFolder)
=== Informations d'état de liaison préalable ===
JRN : DisplayName = System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
(Fully-specified)
JRN : Appbase = file:///C:/Program Files (x86)/National Instruments/TestStand 2022/Bin/
JRN : PrivatePath initial = NULL
Assembly appelant : System.Memory, Version=4.0.1.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51.
===
JRN : cette liaison démarre dans le contexte de chargement de LoadFrom.
AVT : l'image native ne sera pas détectée dans le contexte LoadFrom. Elle sera détectée uniquement dans le contexte de chargement par défaut, comme pour Assembly.Load().
JRN : utilisation du fichier de configuration de l'application : C:\Program Files (x86)\National Instruments\TestStand 2022\Bin\SeqEdit.exe.Config
JRN : utilisation du fichier de configuration d'hôte :
JRN : utilisation du fichier de configuration de l'ordinateur à partir de C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
JRN : référence post-stratégie : System.Runtime.CompilerServices.Unsafe, Version=4.0.4.1, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
JRN : la même liaison a été vue avant et a échoué avec hr = 0x80070002.
ERROR CODE -2147024894
-2147024894; Code Module/User-defined error code.
Possible System Error: Le fichier spécifié est introuvable.
LOCATION
Step 'Init/load' of sequence 'Init' in 'PLC_PC_CoreGeneric.seq'
The error message want the assembly System.Runtime.CompilerServices.Unsafe in version 4.0.4.1 with is related to .NetFrameWork 4.5. as the internet tend to aggree (cf this StackOverFlow: https://stackoverflow.com/questions/62764744/could-not-load-file-or-assembly-system-runtime-compiler... )
But, my code is .net Standard 2.0, and the Json lib from MS use the assembly in version 6.0.x.
Of course all the runtime and Sdk of all the Framework version are installed...
I don't find anything in the .Net Adapter to ditch framework and use .net standard or 6.0
When I made a .exe which call my lib, no error at all.
i let the troll question for the end, but it bother me a lot during the debug, taht something works fine until you use it with NI :
Who still use .Net Framework in 2023 as standard starting point for new app???
Why NI is allways stuck in the past when delaing with anything else than Labview ?
12-18-2023 05:56 AM
I am facing the same problem.
Seems like there is no solution for this issue.
These dependencies are required when working with an AspNet Core Web Application.
12-19-2023 08:49 AM
@jungledede wrote:
Why NI is allways stuck in the past when delaing with anything else than Labview ?
If you want to imply that LabVIEW is a step ahead, I have to disappoint you.... same problem on that side
06-03-2024 10:20 AM
I don't know if you finally solve it, but on my side, I found a solution bay loading Nugget Version of System.Runtime.CompilerServices.Unsage 4.5.3. If you chosse another Nugget version it crashed in Labview 2022 (but not when building a C# executable...).
I don't know why exactly.
06-25-2024 08:27 AM
Sorry, i have forgotten this issue, as i have shift to NewtonSoft for the json parsing.
But on another assembly, this time in .Net 8 i got again issue from teststand complaining about not found lib... system lib...