Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ASP.NET dependency when develop custom OPC UA server #1949

Closed
3 of 5 tasks
2mik opened this issue Oct 10, 2022 · 8 comments · Fixed by #1963
Closed
3 of 5 tasks

Remove ASP.NET dependency when develop custom OPC UA server #1949

2mik opened this issue Oct 10, 2022 · 8 comments · Fixed by #1963
Assignees
Labels
bug A bug was identified and should be fixed. https Https transport server

Comments

@2mik
Copy link

2mik commented Oct 10, 2022

Type of issue

  • Bug
  • Enhancement
  • Compliance
  • Question
  • Help wanted

Current Behavior

Let's consider the NetCoreConsoleServer project. If we build it by default, the file NetCoreConsoleServer.runtimeconfig.json contains AspNetCore dependency:

    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "6.0.0"
      }
    ]

If I remove Microsoft.AspNetCore.App from NetCoreConsoleServer.runtimeconfig.json and run NetCoreConsoleServer.exe, I got the error:

Could not load file or assembly 'Microsoft.AspNetCore.Hosting...'

Then if I delete Opc.Ua.Bindings.Https.dll, the server starts successfully, but internally the application tries to load the dll. To check this, I added to Program.cs the following code

AppDomain.CurrentDomain.AssemblyResolve += (object sender, ResolveEventArgs args) =>
{
    Console.WriteLine("!!! Could not find assembly '{0}'{1}   requested by '{2}'",
        args.Name, Environment.NewLine, args.RequestingAssembly.FullName);
    return null;
};

and I got the error:

Could not find assembly 'Opc.Ua.Bindings.Https, Version=1.4.370.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8' requested by 'Opc.Ua.Core...'

In our project, a custom OPC UA server works as a service and should not require AspNetCore, only NETCore.
Is there a way to avoid dependency on ASP.NET and Opc.Ua.Bindings.Https?

Expected Behavior

A service that implements OPC UA server can be built and can work without dependency on ASP.NET and probably Opc.Ua.Bindings.Https.

Steps To Reproduce

Described above.

Environment

- OS: any
- Environment: any
- Runtime: .NET6
- Nuget Version: 1.4.370.0
- Component:
- Server:
- Client:

Anything else?

HTTPS connection to OPC UA server is not needed, TCP is enough.

@mregen
Copy link
Contributor

mregen commented Oct 11, 2022

Hi @2mik, the https dependency is by default not included if you only reference the OPCFoundation.NetStandard.Opc.Ua.Server package. For backward compatibility the OPCFoundation.NetStandard.Opc.Ua packages includes all client and server packages including GDS and https.

@2mik
Copy link
Author

2mik commented Oct 11, 2022

Hi,
In NetCoreConsoleServer.csproj I've changed references to

    <When Condition="'$(Configuration)'=='Release'">
      <ItemGroup>
        <PackageReference Include="OPCFoundation.NetStandard.Opc.Ua.Server" Version="1.4.370.12" />
      </ItemGroup>
    </When>

After build NetCoreConsoleServer.runtimeconfig.json does not contain AspNetCore. And there is no Opc.Ua.Bindings.Https.dll in the Release folder. That's good.
NetCoreConsoleServer.exe works, but writes to the console (because of the AppDomain.CurrentDomain.AssemblyResolve handler)

Could not find assembly 'Opc.Ua.Bindings.Https, Version=1.4.370.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8' requested by 'Opc.Ua.Core, Version=1.4.370.0, Culture=neutral, PublicKeyToken=bfa7a73c5cf4b6e8'

So the application tries to load Opc.Ua.Bindings.Https anyway. Is it possible to avoid it?

@mregen
Copy link
Contributor

mregen commented Oct 11, 2022

Should not be loaded if you don't specify a https endpoint...

 <ServerConfiguration>
    <BaseAddresses>
remove -->      <ua:String>https://localhost:62540/Quickstarts/ReferenceServer</ua:String>
      <ua:String>opc.tcp://localhost:62541/Quickstarts/ReferenceServer</ua:String>

@2mik
Copy link
Author

2mik commented Oct 11, 2022

I removed the specified string from Opc.Ua.SampleServer.Config.xml, but Opc.Ua.Bindings.Https.dll still requested.
May be some additional configuration changes are needed?

Note: the file Opc.Ua.SampleServer.Config.xml is definitely in use, because I can change server TCP port, and changes are applied, for example.

@mregen
Copy link
Contributor

mregen commented Oct 26, 2022

@2mik thats a bug, I have a fix.

@mregen mregen self-assigned this Oct 26, 2022
@mregen mregen added the bug A bug was identified and should be fixed. label Oct 26, 2022
@mregen mregen added server https Https transport labels Oct 26, 2022
@2mik
Copy link
Author

2mik commented Oct 26, 2022

@2mik thats a bug, I have a fix.

Cool! I will test the new version with the fix when it is available.

@2mik
Copy link
Author

2mik commented Nov 1, 2022

Could you tell when the next release is going to be available?

@2mik
Copy link
Author

2mik commented Nov 22, 2022

Works in OPC UA 1.4.371.41
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug was identified and should be fixed. https Https transport server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants