dotnet / wcf

This repo contains the client-oriented WCF libraries that enable applications built on .NET Core to communicate with WCF services.
MIT License
1.71k stars 558 forks source link

System.MissingMethodException: Method not found: 'Void System.ServiceModel.EndpointAddress..ctor(System.Uri, System.ServiceModel.EndpointIdentity, System.ServiceModel.Channels.AddressHeaderCollection)' #4996

Closed janPORG closed 1 year ago

janPORG commented 1 year ago

Hi,

I am porting a project from .NET 4.8 to dotnet core 6/7. I need to use the SCOM 2022 SDK

Microsoft.EnterpriseManagement.Core.dll
Microsoft.EnterpriseManagement.OperationsManager.dll
Microsoft.EnterpriseManagement.Runtime.dll

I also installed latest nuget packages

    <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.0" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="7.0.0" />
    <PackageReference Include="System.ServiceModel.Duplex" Version="4.10.0" />
    <PackageReference Include="System.ServiceModel.Primitives" Version="4.10.0" />
    <PackageReference Include="System.ServiceModel.Security" Version="4.10.0" />

Starting with an exception in ManagementGroup _MGCon = new ManagementGroup("localhost"); which lead me to Microsoft.EnterpriseManagement.Core.dll

Microsoft.EnterpriseManagement.Common.Internal.SdkChannelObject`1.CreateChannelFactoryForKerb(String endpointUri, String spn)

which contains a call to

EndpointAddress remoteAddress = new EndpointAddress(new Uri(string.Format(CultureInfo.InvariantCulture, endpointUri, connectionSettings.ServerName)), EndpointIdentity.CreateSpnIdentity(string.Format(CultureInfo.InvariantCulture, spn, connectionSettings.ServerName)), new AddressHeaderCollection());

and this is failing with

System.MissingMethodException
  Message=Method not found: 'Void System.ServiceModel.EndpointAddress..ctor(System.Uri, System.ServiceModel.EndpointIdentity, System.ServiceModel.Channels.AddressHeaderCollection)'.
  Source=Microsoft.EnterpriseManagement.Core

In dotnet core I can not find an implementation for EndpointIdentity.CreateSpnIdentity(""); nor an EndpointAddress constructor which takes new AddressHeaderCollection()

Is there a possibility to get around that issue?

Thanks in advance, Br, Jan

danield72 commented 1 year ago

I believe I'm running into the same thing.

I have the SCOM console from 2022 installed on my dev system, and have imported the same Microsoft.EnterpriseManagement.*.dlls into my .NET Core 7 app (brand new project), and I'm encountering the same error as shown in the subject line.

A simple ManagementGroup.Connect() failed with a FileNotFoundException for System.ServiceModel, which led me to install System.ServiceModel.Primitives from NuGet, then System.ServiceModel.Duplex. Now I'm the same MissingMethodException.

mconnew commented 1 year ago

I finally got a chance to download the SCOM 2022 SDK and took a look at the implementation. Those assemblies are targeting .NET Framework and are only able to even start trying to run because of a compatibility shim we have in the 4.x packages. Unfortunately, it's not good news. There's a lot missing which it depends on. Here's a few of the problems:

Custom BindingElement

Rather than use the built in compression support for BinaryMessageEncodingBindingElement, they built their own GZipMessageEncodingBindingElement. This won't work as it overrides methods in BindingElement which don't exist in these packages, e.g. public override IChannelListener<TChannel> BuildChannelListener<TChannel>(BindingContext context). As soon as you try to instantiate an instance of that, it will throw a CLR runtime exception as the type isn't compatible with the base type.

Distributed Transactions

The custom binding constructed uses TransactionFlowBindingElement which we haven't ported yet. Distributed transaction support wasn't even added until .NET 7.

Unsupported SecurityBindingElement method

The custom binding uses SecurityBindingElement.CreateSspiNegotiationOverTransportBindingElement(). We don't yet have support for this method as we didn't have a public cross platform way to implement this until .NET 7.

That was what I found with looking at the code for about 2 minutes. I'm sure there's more than that missing. Basically, they used all the features in WCF and many of them haven't even been possible to implement until just recently.

Starting with the next soon to be released packages, we won't be supporting the compatibility shim as we can no longer support netstandard2.0. This means even once these features are implemented, the SCOM SDK assemblies still won't be usable as there is no longer a System.ServiceModel.dll shim shipped with the packages.

MikeSargent commented 1 year ago

Does this release of WCF support for .NET 6.0 and above help?

https://devblogs.microsoft.com/dotnet/wcf-client-60-has-been-released/

mconnew commented 10 months ago

@MikeSargent, it won't help. The SCOM SDK needs to be modified slightly (to remove server api usage) and recompiled, but also there's still at least a couple of feature dependencies missing in WCF.