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

1140
8
03-29-2023 07:15 PM
diegom_geoowl
New Contributor III

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
8 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
New Contributor III

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
New Contributor III

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

0 Kudos
diegom_geoowl
New Contributor III

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
New Contributor III

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
New Contributor II

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