简体   繁体   中英

Use Omron libraries in .NET Core 2.0

I'm trying to use Omron libraries (ie 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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM