Select to view content in your preferred language

How to interact with System.Drawing

462
4
Jump to solution
08-07-2024 09:39 AM
Vidar
by
Frequent Contributor

Hi,

From my add-in I have always had this code that could save a graph (Bitmap) from a WPF form to a png file. Now I have moved my codebase to a 3.0.36057, now any code that has anything to with System.Drawing throws an exception, saying that the dll for System.Drawing is missing. It's not its there - it compiles and everything is fine - just like it was for earlier versions of my add-in.

So, I believe this dll is not thread-safe so I tried to implement the code: 

 

 

FrameworkApplication.Current.Dispatcher.Invoke(() =>
{
    Bitmap myBitmap = null;
});

 

 

 

I can't get it to work at all. Can any help me out to understand how I can get this to run.  I've spent 2 days on this now and I'm getting pretty frustrated.

 

and the exception is thrown:

"Could not load file or assembly 'System.Drawing.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.":"System.Drawing.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51"

 

Tags (3)
0 Kudos
1 Solution

Accepted Solutions
UmaHarano
Esri Regular Contributor

@Vidar 

Can you please check the version of System.Configuration.ConfigurationManager that ArcGIS Pro is loading while running your addin?  You can see this version from within Visual Studio while you are debugging the addin.  See screenshot below. Sort on the Name column.

The version of the System.Configuration.ConfigurationsManager NuGet you are referencing in your addin should match the version that ArcGIS Pro needs.  Check out this post on Esri Community - a very similar issue to yours was posted here.

 

UmaHarano_0-1723490087487.png

 

View solution in original post

0 Kudos
4 Replies
UmaHarano
Esri Regular Contributor

@Vidar 

Do you have the System.Drawing.Common NuGet referenced in your addin?

When you migrate to Pro 3.0, some of the 3rd party references you had should be moved to their NuGets.

Refer to this wiki for more info: ProConcepts: 3.0-Migration-Guide 

More info:

Bitmap is part of System.Drawing which was included in .Net Framework.

It is no longer included with .net core (6.0 or 8.0) and must be added manually.

Install the Nuget package System.Drawing.Common by right-clicking on your project in visual studio and choosing Manage Nuget Packages

In the Nuget Package manager, click on the Browse Tab, search for System.Drawing.Common in the top and it should be the first Package, official by Microsoft. 

 

 

0 Kudos
Vidar
by
Frequent Contributor

Hi Uma,

Yes I have used the Nuget Package Manager to install System.Drawing.Common. Indeed I made a brand new add-in project and included this package into it. Still the same issue - I'm starting to believe there is some incompatibility going on here. At the moment, as of writing this - I am trying to achieve everything I can with core.

Small update - I think I was missing the Windows Compatibility Pack - I have installed this as directed from the ESRI help you provided a link for.  Sadly this has introduced new errors into my add-in that is causing similar error messages, but this time for: System.Configuration.ConfigurationManager 8.0.0.  So I installed the version it wanted from Nuget and it STILL says it can't find it. 

Further update - it seems you cannot use the old fashioned Properties file in .net6 projects - so this code is obsolete now as far as I can tell: 

Properties.Settings.Default.CurrentGroupId = null;
Properties.Settings.Default.Save();

 

I'm getting so frustrated with this - it's almost impossible to fix my add-in and I need to get this fixed in the next week as it's due for delivery to clients. So stressful - if you can help that would be great.

0 Kudos
UmaHarano
Esri Regular Contributor

@Vidar 

Can you please check the version of System.Configuration.ConfigurationManager that ArcGIS Pro is loading while running your addin?  You can see this version from within Visual Studio while you are debugging the addin.  See screenshot below. Sort on the Name column.

The version of the System.Configuration.ConfigurationsManager NuGet you are referencing in your addin should match the version that ArcGIS Pro needs.  Check out this post on Esri Community - a very similar issue to yours was posted here.

 

UmaHarano_0-1723490087487.png

 

0 Kudos
Vidar
by
Frequent Contributor

This appears to be the issue - so I have installed version 8.0. Nuget packages of what it thought was missing - however it needed version 6.0 - as the Module window (can only be seen when debugging) shows that version 6.0.x seems to be the versions of dlls Pro is using under the hood.

Uma, do you think its worth ESRI updating the migration docs with this in mind - as I'm sure I won't be the only one who is loading up the wrong version Nuget packages here?

0 Kudos