我正在创建一个控制台.NET 5.0应用程序来与KUKA机器人进行通信,使用其WorkVisual软件中提供的dll。这些dll是用.NET Framework4.6构建的。在Windows上,一切都如预期的那样工作。
最棘手的部分是我需要将它移植到Linux。由于.NET 5.0似乎是跨平台的,所以我决定使用.NET 5.0构建我的应用程序,并添加Kuka (.NET 4.6)作为参考。虽然它在Windows上运行良好,但问题从Linux开始。这个应用程序本身是使用.NET 5.0运行时运行的(dotnet MyApp从终端运行),但是仅仅这么长时间,我就尝试调用一个连接到机器人的函数。然后我得到一个例外:
Unhandled exception. System.TypeLoadException: Could not load type 'System.Management.Instrumentation.InstrumentationClassAttribute' from assembly 'System.Management, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
at System.ModuleHandle.ResolveTypeHandleInternal(RuntimeModule module, Int32 typeToken, RuntimeTypeHandle[] typeInstantiationContext, RuntimeTypeHandle[] methodInstantiationContext)
at System.Reflection.RuntimeModule.ResolveType(Int32 metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
at System.Reflection.CustomAttribute.FilterCustomAttributeRecord(MetadataToken caCtorToken, MetadataImport& scope, RuntimeModule decoratedModule, MetadataToken decoratedToken, RuntimeType attributeFilterType, Boolean mustBeInheritable, ListBuilder`1& derivedAttributes, RuntimeType& attributeType, IRuntimeMethodInfo& ctorWithParameters, Boolean& isVarArg)
at System.Reflection.CustomAttribute.IsCustomAttributeDefined(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, RuntimeType attributeFilterType, Int32 attributeCtorToken, Boolean mustBeInheritable)
at System.Reflection.CustomAttribute.IsDefined(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.IsDefined(Type attributeType, Boolean inherit)
at System.Diagnostics.StackTrace.ShowInStackTrace(MethodBase mb)
at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat, StringBuilder sb)
at System.Diagnostics.StackTrace.ToString(TraceFormat traceFormat)
at System.Exception.get_StackTrace()
at System.Exception.ToString()
...我已经将NuGet包添加到我的项目中:
但他们都帮不上忙。我很好奇是否可以在Linux上使用这些dll来运行这个应用程序,如果是的话,我还需要做些什么才能让它工作呢?
我对dll没有影响,因为它们是编译的,我没有源代码,只能使用它们。
发布于 2021-08-18 12:41:43
这个Microsoft.Windows.Compatibility nuget是nuget包,它提供对.NET框架中API的访问,这些API主要运行在.NET上(因此“.NET”是nuget名称的一部分)。
Microsoft.Windows.Compatibility nuget包实际上也是一个元包,它提供了.NET框架中可用的相关API列表。这还包括System.Management nuget包和其他仅限Windows的软件包,如Microsoft.Win32.Registry。
因此,它不能保证在Windows之外的其他操作系统上运行,特别是那些需要与Windows互操作的包,例如System.Management和Microsoft.Win32.Registry。
https://stackoverflow.com/questions/68829942
复制相似问题