Can't and reference to System.Devices.dll

Glenn T. Kitchen 0 Reputation points
2024-08-27T19:29:06.7566667+00:00

Trying to Browse Windows Libraries and Add a Reference

I'm trying to add a reference that isn't listed in the selection box by browsing for Windows dll"s. When I find what I'm looking for and try to add it, I get an error stating it isn't COM compatible. Does this mean I have to use the defining Function method? Why aren't some dll's possible to reference? When I look at the help documentation at this library it even gives VB documentation for it.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
5,033 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 53,726 Reputation points
    2024-08-27T20:07:18.7733333+00:00

    There are several different ways to reference third party code in a .NET app:

    • NuGet package (preferred)
    • Assembly reference from GAC (for NET Framework assemblies and legacy code)
    • Binary reference (for assemblies not in the GAC)
    • COM reference (for COM components only)
    • DllImport (for native binaries only)

    So the first question is what is system.devices? Can you provide a reference to what this binary is? The only references I can find relate to Mono.

    The second question is what type of app are you building and what framework version are you targeting? In general you can only reference binaries that are compatible with your framework. For example you cannot reference an assembly from the GAC with a NET 6 app.

    If the binary is a native DLL and not a NET assembly then DllImport is the only option and you won't be adding a reference to it in your project. If it is exposed as a COM object then you would add a reference using the Add COM Reference option and you would then have to select it from the type library selector. The COM component has to be installed on your machine and bitness (x86 or x64) compatible with your project.

    For NET assemblies look in NuGet first. I don't see any system.devices package but there are packages with that in the name.

    If you cannot find a NuGet package AND you have the assembly available then you'll be stuck with using a binary reference. That means you need to put the binary someplace in your solution (not the output directory) and then add a binary reference to it using the Browse button.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.