Use Omron libraries in .NET Core 2.0

0

I'm trying to use Omron libraries (i.e. Compolet) in an ASP.NET Core 2.0 application. I added the assembly reference for those classes, but at run-time they try to locate the System.Windows.Forms assembly - obviously not available in ASP.NET Core.

The exact error is:

FileNotFoundException: Could not load file or assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e096'. OMRON.Compolet.CIP.CIPPIcCompolet..ctor()

I guess "..ctor()" is "constructor". In fact this happens when I try to create a new object:

NJCompolet nj = new NJCompolet()
{
    LocalPort = 2,
    PeerAddress = "192.168.2.10",
};

I tried to add a reference to "System.Windows.Forms.dll" but it says:

BadImageFormatException: Could not load file or assembly 'System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (Exception from HRESULT: 0x80131058)

I also tried to use Reflection-only way but is again says that this mode is unsupported in this framework.

I'm aware I can create a separate Windows.Forms project just to instantiate the libraries but then I have to setup an IPC channel to exchange data with my main ASP project. I'm trying to avoid that - if possible.

Is there something other I should try?

c#
asp.net
.net
libraries
asked on Stack Overflow Nov 30, 2017 by Mark • edited Nov 30, 2017 by Mark

1 Answer

1

Your issue is you are trying to add a .NET 2.0 Framework DLL to a .NET Core 2.0 project. These DLLs leverage two different run time environments which means they are not compatible with each other. You will need to switch your web application to a different run time that supports loading a 2.0 Framework DLL, like an ASP.NET 3.5 Framework project.

answered on Stack Overflow Nov 30, 2017 by tj-cappelletti

User contributions licensed under CC BY-SA 3.0