Resolved Partial Friend Class MyApplication Warning

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
216
Programming Experience
10+
Converted to Net7 and now get the following warning about:
Me.HighDpiMode = HighDpiMode.DpiUnaware
Should I ignore or do something.

Partial Friend Class MyApplication
<Global.System.Diagnostics.DebuggerStepThroughAttribute()>
Public Sub New()
MyBase.New(Global.Microsoft.VisualBasic.ApplicationServices.AuthenticationMode.Windows)
Me.IsSingleInstance = false
Me.EnableVisualStyles = true
Me.SaveMySettingsOnExit = true
Me.ShutDownStyle = Global.Microsoft.VisualBasic.ApplicationServices.ShutdownMode.AfterMainFormCloses
Me.HighDpiMode = HighDpiMode.DpiUnaware
End Sub

Warning BC42025 Access of shared member, constant member, enum member or nested type through an instance;
qualifying expression will not be evaluated.
...\Net7\CAG Suite\CagSuite\My Project\Application.Designer.vb
 
Solution
This seems like Microsoft have broken something that they previously fixed in an older version. It appears that the reference to HighDpiMode on the right-hand side of that assignment is being interpreted as the HighDpiMode property of the current form, rather than the System.Windows.Forms.HighDpiMode type. That's how things used to work in the code editor and the most common manifestation of that was when displaying a modal dialogue, e.g.
VB.NET:
Using dialogue As New SomeForm
    If dialogue.ShowDialog() = DialogResult.OK Then
        '...'
    End If
End Using
It used to be that that code would generate the same warning because DialogResult was interpreted as the current form's DialogResult property...
This seems like Microsoft have broken something that they previously fixed in an older version. It appears that the reference to HighDpiMode on the right-hand side of that assignment is being interpreted as the HighDpiMode property of the current form, rather than the System.Windows.Forms.HighDpiMode type. That's how things used to work in the code editor and the most common manifestation of that was when displaying a modal dialogue, e.g.
VB.NET:
Using dialogue As New SomeForm
    If dialogue.ShowDialog() = DialogResult.OK Then
        '...'
    End If
End Using
It used to be that that code would generate the same warning because DialogResult was interpreted as the current form's DialogResult property rather than the System.Windows.Forms.DialogResult type. They fixed that some time ago though. I wonder whether they only did so for specific types and that isn't one of them.

Anyway, it's not going to cause an issue because, as the message says, what it is interpreting as a qualifying expression is going to be ignored and the type used anyway. If you want clear the warning then you can add a qualifying namespace to the type to disambiguate it, i.e.
VB.NET:
Me.HighDpiMode = System.Windows.Forms.HighDpiMode.DpiUnaware
or:
VB.NET:
Me.HighDpiMode = Windows.Forms.HighDpiMode.DpiUnaware
That will work but, if you change the application settings, that file may be rewritten and your change lost, so the warning would return. I suspect that Microsoft will address this at some point though, but it may be low priority.
 
Solution
Back
Top