-1

I am programming a ArcGIS Pro 3.1 AddIn with C#.

The following line

var pipeFactory = new ChannelFactory<IWCFStarter>(new NetNamedPipeBinding(),
                                                  new EndpointAddress("net.pipe://localhost/SomeAdress"));

throws this exception:

Exceptioninfo: 
Type: System.TypeLoadException 
ExceptionMessage: 
Could not load type 'System.ServiceModel.ExceptionHelper' from assembly 'System.ServiceModel.Primitives, Version=4.9.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Source: System.ServiceModel.NetNamedPipe 
Stack: 
   at System.ServiceModel.NetNamedPipeBinding..ctor() 
   at ARCBAR.InfoWindow.updateAddin_Click(Object sender, RoutedEventArgs e) in C:\ARCBAR\ARCBAR\InfoWindow.xaml.cs:line 35

But the project has the NuGetPagages added:

<ItemGroup>
    <PackageReference Include="System.Drawing.Common" Version="7.0.0" />
    <PackageReference Include="System.ServiceModel.NetNamedPipe" Version="6.0.0" />
    <PackageReference Include="System.ServiceModel.Primitives" Version="6.0.0" />
</ItemGroup>

In another project the same thing works perfectly fine. And I cant find any meaningful differences in the dependencies and nuGet-Packages.

Updates:

  • I searched all my code for "<PackageReference Include="System.ServiceMode" and found only references to: "". No other mentions.
  • .I started ArcGIS Pro 3.1 without loading my addIn and used "Debug/Attach to process" + "debug/Windows/modules" to see which assamblies are loaded by ArcGIS itself without my AddIn. And there are 2 dlls with "serviceModel" in the name:
  • System.ServiceModel.Primitives.dll C:\Program Files\ArcGIS\Pro\bin\System.ServiceModel.Primitives.dll Yes No Skipped loading symbols. 115 4.900.21.52002
  • System.Private.ServiceModel.dll System.Private.ServiceModel.dll C:\Program Files\ArcGIS\Pro\bin\System.Private.ServiceModel.dll
Gener4tor
  • 414
  • 3
  • 12
  • 40
  • 1
    Something somewhere loads `System.ServiceModel.Primitives` assembly version 4.9 before your code is executed. Are you able to troubleshoot that? – Zdeněk Jelínek Aug 07 '23 at 10:41
  • .NET 6.0 is .NET *Core* 6.0. You can't use .NET Core classes in a .NET Framework application or plugin. The packages you list are .NET 6 and 7 packages. – Panagiotis Kanavos Aug 07 '23 at 10:46
  • I searched all my code for "". No other mentions. – Gener4tor Aug 07 '23 at 10:47
  • The `System.ServiceModel` namespace is part of WCF which was included in the .NET *Framework* runtime, so didn't have to be added through NuGet. You *don't* have to use the low level WCF classes to call a SOAP service either. You can create a client proxy directly in Visual Studio through `Add Service Reference` or the `svcutil` cli tool – Panagiotis Kanavos Aug 07 '23 at 10:49
  • 1
    Does your project reference some *other* old `System.ServiceModel.*` package? Perhaps indirectly through some other custom project? `*.NetNamedPipe` 6 depends on `*.Primitives` 6. Something in `ARCBAR.InfoWindow` is trying to use an *older* version. Support for `NetNamedPipe` was only added in [May 2023](https://devblogs.microsoft.com/dotnet/wcf-client-60-has-been-released/) so *any* older project you use is referencing 4.x – Panagiotis Kanavos Aug 07 '23 at 10:58
  • 1
    Use _process monitor_ to check which files are searched at which locations by your application and check if it matches your expectations. If you have another working project maybe check also its loading log and compare it to your failing one. – Oliver Aug 07 '23 at 12:45
  • @Panagiotis Kanavos: As it is a "ArcGIS Pro 3.1 AddIn"-Project, im not 100% sure if its .NET Core. But I think it is. How can I be sure? – Gener4tor Aug 07 '23 at 14:15
  • @Panagiotis Kanavos: "Does your project reference some other old System.ServiceModel.* package?" I dont find any. – Gener4tor Aug 07 '23 at 14:21
  • @Oliver: As this is an AddIn. ArcGIS Pro itself maybe loads some older dll's. Could this be the problem? – Gener4tor Aug 07 '23 at 14:26
  • ok...I started ArcGIS Pro 3.1 without loading my addIn and used "Debug/Attach to process" + "debug/Windows/modules" to see which assamblies are loaded by ArcGIS itself without my AddIn. And there are 2 dlls with "serviceModel" in the name. Ill edit the question. – Gener4tor Aug 07 '23 at 14:44
  • Ok. I found a possible solution (unfortunately a bad one). Details see answer. – Gener4tor Aug 07 '23 at 15:21

1 Answers1

-1

With the help of Oliver, Zdeněk Jelínek and Panagiotis Kanavos I found a solution (unfortunately a bad one):

I started ArcGIS Pro 3.1 without loading my addIn and used "Debug/Attach to process" + "debug/Windows/modules" to see which assamblies are loaded by ArcGIS itself without my AddIn.

So I found out that ArcGIS itself loads "System.ServiceModel.Primitives.dll" in version 4.900.21.52002 from "C:\Program Files\ArcGIS\Pro\bin\System.ServiceModel.Primitives.dll"

I need System.ServiceModel.NetNamedPipe and this needs System.ServiceModel.Primitives in Version 6.0.0.

So I replaced "C:\Program Files\ArcGIS\Pro\bin\System.ServiceModel.Primitives.dll" with the 6.0.0 Version from my bin/release-folder.

This seems to work at first glance.

But for obvious reasons this is not a very good solution. I prefere not to change any installed files from ArcGIS-Pro.

Gener4tor
  • 414
  • 3
  • 12
  • 40
  • 1
    There are ways to load multiple versions of the same assembly. .NET Framework has application domains and .NET 5+ (aka .NET Core) has assembly load contexts. Neither of those is exactly simple. However, if you need sharing state represented using either of those assemblies, such as passing along non-trivial object instances, with the ArcGIS software hosting your plug-in, you're out of luck and will have to use the same version it does. As a plugin author, you are at the mercy of the hosting application. – Zdeněk Jelínek Aug 07 '23 at 19:03