【发布时间】:2021-08-18 09:37:47
【问题描述】:
我正在创建一个控制台 .NET 5.0 应用程序,以使用其 WorkVisual 软件中提供的 dll 与 KUKA 机器人通信。这些 dll 是使用 .NET Framework 4.6 构建的。在 Windows 上一切正常。
棘手的部分是我需要将它移植到 Linux。由于 .NET 5.0 似乎是跨平台的,我决定使用 .NET 5.0 构建我的应用程序并添加 Kuka dll (.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 包添加到我的项目中:
- 系统管理
- Microsoft.Windows.Compatibility
但他们都没有帮助。我很好奇是否可以在 Linux 上使用这些 dll 运行应用程序,如果可以,我还需要做些什么才能使其正常工作。
我对 dll 的编译没有影响,我没有源代码,只能按原样使用它们。
【问题讨论】:
-
也许这会帮助stackoverflow.com/questions/45508989/can-net-4-6-run-on-linux。但我不抱太大希望.. 那些外部 dll 很可能依赖于 linux 不支持的某些功能(
-
@Driven-it 谢谢,我已经按照其中一个 cmets 中的建议尝试了 .NET Portability Analyzer,但尽管我的解决方案在所有 .NET Core/Standard 以及Mono,它还显示Kuka的workvisual提供的dll是“未解析的程序集”,根本没有检查......所以没有完全解决问题
标签: .net linux wmi .net-5 .net-4.6