Select to view content in your preferred language

ArcGIS Pro SDK for .NET Add-In Module - Is there a way to implement Dependency Injection using Microsoft.Extensions.Hosting HostBuilder?

2319
9
03-29-2023 07:15 PM
diegom_geoowl
Emerging Contributor

I’ve been trying to implement proper Dependency Injection using Microsoft.Extensions.DependecyInjection and Microsoft.Extensions.Hosting but I keep running into this error whenever I try build my HostBuilder  “Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified”. I would appreciate any help, thank you. 

0 Kudos
9 Replies
Wolf
by Esri Regular Contributor
Esri Regular Contributor

I haven't used Microsoft.Extensions.Hosting, however, it looks like your app seems to look for .NET 7.   ArcGIS Pro is built on .NET 6. 

0 Kudos
diegom_geoowl
Emerging Contributor

The issue is that I do not have that version of 'System.Diagnostics.DiagnosticSource' installed.

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

System.Diagnostics.DiagnosticSource is part of the .NETCore app framework, so i am pretty sure if you install the .NET 7 runtime you have the desired assembly version.  

0 Kudos
diegom_geoowl
Emerging Contributor

I downloaded and installed the runtime, still the the same error. Super weird. I apologize for the inconvenience.

0 Kudos
diegom_geoowl
Emerging Contributor

I figured it out! I had change the installation directory for ArcGIS Pro! 😁

 

0 Kudos
Wolf
by Esri Regular Contributor
Esri Regular Contributor

Not sure how the installation directory for ArcGIS Pro would fix the “Could not load file or assembly 'System.Diagnostics.DiagnosticSource, Version=7.0.0.0, C..." issue.   Can you elaborate?   Where did you install ArcGIS Pro?

0 Kudos
diegom_geoowl
Emerging Contributor

By default it installed  in the AppData. When I installed it in ProgramFiles the error was resolved. I'm assuming there was a possible permissions issue?

Also, the Microsoft.Extensions.Configuration.Abstractions dll (Version 2.0.0.0) located in the ArcGIS Pro folder is interfering with the Microsoft.Extensions.Configuration.Abstractions Version 6.0.0 package installed in the AddIn project.

0 Kudos
KarlKemp
Occasional Contributor

I'm looking to do something similar.  Where in your module code/how did you set up your container? I'd love to see any sample code you're willing to share!

0 Kudos
thejuskambi
Frequent Contributor

I know it been some time, but can you share you implementation how or where you added the Host initialization code. There was a bug in earlier version of the Pro, which was dependent of .Net Core 2.1 version libraries which has been fixed in Pro3.2 and higher. Have you tried this in the latest version?

0 Kudos