Visual Studio 2022, Debugging, Watch window shows properties that don't compile? - visual-studio-2022

My question is about Visual Studio 2022, debugging, but here is some background information.
My ASP.NET webapp targets .NET v4.7.2.
Now, While preparing to remove old/wrong code such as :
myVariable = (HttpWebRequest)WebRequest.Create('myUrl');
I started my debug session, and added a watch of 'myVariable' to 'Watch 1' window.
It shows a property 'SslProtocols' which is type System.Security.Authentication.SslProtocols.
But docs.microsoft.com makes no mention of said property.
Next, I added the code :
using System.Security.Authentication;
(clipped for brevity)
myVariable.SslProtocols = System.Security.Authentication.SslProtocols.Tls12;
But "Build Failed",
Error CS1061 'HttpWebRequest' does not contain a definition for 'SslProtocols' and no accessible...(blah blah)
Given that I am already aware that Microsoft says "we don't recommend..." WebRequest.Create(), My question is about debugging vis-a-vis 'Watch 1' window.
Why is the debugger/watch window showing me a property that isn't
actually there, or something ?? Heck, it says it contains the value
SslProtocols.Ssl3 ?

Related

Webforms Error shows TWO projects although solution shows ONE project

In a VS-2019 webforms solution I get this error that shows TWO projects although the solution only has ONE project.
Severity: Error
Code Description : BC30456 'prpPageCaption' is not a member of 'MasterPage'.
Project: 7_SessionExpired.aspx, repo_TripManagement
File: C:\Users...\SessionExpired.aspx.vb
Line: 100
Suppression State: Active
It appears that the error shows TWO projects and I did not create a project named 7_SessionExpired.aspx
The vb-page "SessionExpired.aspx and .vb" was copied from a similar project in VS-2017. This is confusing to me and I don't have any way to know what this error is saying.
Here is the LINE=100 from the source VB file:
100| | Master.prpPageCaption = "Session has Expired"
Here is the property in the master-page:
Public Property prpPageCaption() As String
Get
Return Me.lblCaption.Text
End Get
Set(ByVal p_sCaption As String)
Me.lblCaption.Text = p_sCaption
Me.updpanelPageCaption.Update()
End Set
End Property
The vb-page "SessionExpired.aspx and .vb" was copied from a similar project in VS-2017. This is confusing to me and I don't have any way to know what this error is saying. I need your help. Thanks...John
Think the IDE/VS-2019 is confused and I cut ALL of the files for SessionExpired.aspx (.vb) and pasted them in a my-documents-folder.
I then added a webform-page with Master-page (WebForm1.aspx) into the project.
I then added the ASPX objects as UI for the page. I performed a "View Code" option and the / VB-code structure is shown. I only added "Option Explicit ON". Saved both modified files and closed the SOLUTION.
I then re-opened the solution and the code compiled -- even though the full VB-functionality was not coded.
From the 'Solution Explorer' I then renamed the WebForm1.aspx to "SessionExpired" and compiled again -- all ok.
Finally I added the VB-code from the saved-off original SessionExpired.vb code.
All of the errors shown above were cleared and things are working.
IMHO, bringing in an older webform brings with it the old-style of 'designer' and by starting with a VS-2019 webform-page conforms to the VS-2019 designer pattern.
I apologize to those that viewed this question.
Thanks. John.

SubSonic throwing 'System.IndexOutOfRangeException' when in Visual Studio Debug mode

I recently inherited the code set for a Product I now own which uses Subsonic 2.1.0 to perform its data-access.
When I go in to debug said code set, all that I get in the Output window of Visual Studio 2010 is the following (for pretty much every column of every object trying to be loaded):
A first chance exception of type 'System.IndexOutOfRangeException' occurred in System.Data.dll
This is the block of code where it is blowing up in Subsonic, which is located in the SubSonic.RecordBase class, which looks like so:
/// <summary>
/// Loads the object with the current reader's values. Assumes the reader is already moved to
/// first position in recordset (aka has been "Read()")
/// </summary>
/// <param name="dataReader">The data reader.</param>
public virtual void Load(IDataReader dataReader)
{
foreach(TableSchema.TableColumn col in BaseSchema.Columns)
{
try
{
SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);
}
catch(Exception)
{
// turning off the Exception for now
// to support partial loads
// throw new Exception("Unable to set column value for " + col.ColumnName + ": " + x.Message);
}
}
SetLoadState();
MarkClean();
}
The offending line in there is:
SetColumnValue(col.ColumnName, dataReader[col.ColumnName]);
col.ColumnName doesn't match anything in the dataReader at this point. It's almost like it's using an old/prior dataReader to attempt to pull data from.
I'm hoping someone else has encountered this issue, as I'm still fairly new to Subsonic and have only used Hibernate in the past for an ORM.
This happens on both my older machine and a new one I just built, both running Windows 7 Professional x64 w/ Visual Studio 2010 Professional as the IDE.
I've gone through the forums, Google, and many other sites out there, but have yet to find anyone else encountering this issue.
If more information is required, please let me know and I'll be happy to post!
Thanks in advance!
Justin
After spending a while longer looking into this issue, I've realized that it's intentionally throwing these Exceptions for the sake of "partially loading" a data object when only certain fields are being retrieved from the database and mapped to the data object itself. (e.g. just supresses the Exceptions itself and resumes if it can't map a column's data properly.
Not sure if this was originally part of the SubSonic code or something that was introduced by those before me.
Thanks again!
Justin
It looks like the DB Schema may have changed since the SubSonic objects where last created.

ConfigurationManager not declared - Have dll

Quick background: I have a VB.NET application in which I was previously using ConfigurationSettings.AppSettings to read from app.config, and got an error message to change it to System.Configuration.ConfigurationManager.AppSettings (as the first way is now obsolete)
I did so, and I even have a reference to System.Configuration.dll AND the Imports statement at the top, but I am getting a "Name ConfigurationManager not declared" error message. Any suggestions?
CODE:
It's pretty straightforward - I'm just checking if something exists, and if it does, I read from it:
If Not Exists(ConfigurationManager.AppSettings.Get(rep & "Email")) Then
Return False
End If
message = ReadAllText(ConfigurationManager.AppSettings.Get(rep & "Email"))
The project template doesn't have the reference you need. Project + Add Reference, select "System.Configuration".
For more insight, click the "Show All Files" icon at the top of the Solution Explorer window and open the References node.
Another issue that causes this is the reference being the wrong case.
System.configuration was in the .vbproj, instead of System.Configuration.
For me, compiling with the above mistake worked on Windows but not on Linux, but fixing it to the latter made it work on both.
If you are using visual studio 2015 and Visual Basic language. Go to Project + Add Reference > Select Assemblies > Framework. Search for System.configuration. Add the DLL file. After it. On your form, add this in the first line without quotations "Imports System.Configuration" go to your connection string declaration then put this value without quotation "ConfigurationManager.ConnectionStrings("'string configuration name'").ConnectionString" like this.
Public constr As String = ConfigurationManager.ConnectionStrings("string configuration name").ConnectionString
This one works for me. Just now. Hope this one helps others. ^_^

Crystal reports 11 RDC (COM API) displays printer dialog even when I tell it not to prompt

I'm using Crystal Reports 11's RDC (COM) API to print. My code looks like this:
HRESULT res = m_Report->SelectPrinter(b_driver, b_device, b_port);
if (FAILED(res)) return res;
// For these calls, the #import wrapper throws on error
m_Report->PutPrinterDuplex(dmDuplex);
m_Report->PutPaperSize(dmPaperSize);
m_Report->PutPaperSource((CRPaperSource)pdlg->GetDevMode()->dmDefaultSource);
if (m_Report->GetPaperOrientation() == crDefaultPaperOrientation)
m_Report->PutPaperOrientation(crPortrait);
VARIANT vfalse;
VariantInit(&vfalse);
vfalse.vt=VT_BOOL;
vfalse.boolVal=0;
res = m_Report->PrintOut(vfalse);
However, at the end of all this, crystal reports still shows its own printer selection dialog - but only for some reports, it seems. Why does crystal reports show a print dialog even when I pass false for promptUser? And how, then, can I suppress crystal reports' internal printer selection dialog and force it to use my values?
Edit: Whoops, CR11, not CR9.
Some further information:
The reports that work properly (ie, do not show the print dialog) are generated internally using the RDC API; we create a new report object, import subreports into it, then print the result. No problem there.
The reports that do not work properly (ie, force the print dialog to open) have been created with a previous version of crystal reports; however, opening and saving the report does not seem to help.
Sample reports in the Crystal Reports installation directory show the same problem.
I tried reproducing with VBScript; however, the result was that nothing was printed at all (no dialog, no nothing):
Set app = CreateObject("CrystalRuntime.Application.11")
Set report = app.OpenReport("C:\Program Files\Business Objects\Crystal Reports 11.5\Samples\en\Reports\General Business\Inventory Crosstab.rpt")
report.PrintOut(True)
rem Testing with a True parameter to force a print dialog - but no printout and nothing appears (no error either though)
First, let me preface that I'm not a C/C++ programmer, so I'm not able to test the code--my interaction w/ the SDK has been with the VB and .Net interface over the years.
I found the following code from BO's devlibrary:
// A dummy variant
VariantInit (&dummy);
dummy.vt = VT_EMPTY;
HRESULT hr = S_OK;
// Specify the path to the report you want to print
_bstr_t ReportPath("c:\\Program Files\\Business Objects\\Crystal Reports 11.5\\Samples\\En\\Reports\\General Business\\Inventory.rpt");
_variant_t vtEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);
// Instantiate the IApplication object
m_Application.CreateInstance("CrystalRuntime.Application.115");
//Open the Report using the OpenReport method
m_Report = m_Application->OpenReport(ReportPath, dummy)
//Print the Report to printer
m_Report->PrintOut(dummy, dummy, dummy, dummy);
Does it work? It should print the report with its 'default' printer settings and without prompting.
You wrote:
However, at the end of all this,
crystal reports still shows its own
printer selection dialog - but only
for some reports, it seems.
Generally speaking, I've found that Crystal tends to ignore commands to suppress dialogs if it thinks something is missing. I've found this to be true with the parameter dialog. Perhaps it apply to this situation as well. I would ask what is different about the reports that cause the dialog to be generated. There is a 'no printer' option that can be set. Perhaps this is the common thread.
Do you have access to the VB6 IDE? If you write the equivalent commands using VB6's interface, does the prompting occur?
You might also investigate using the CRPE32.dll instead of the report-designer control. To be honest, I don't know if the RDC wraps the CRPE DLL or is an entirely-separate code base.
Turns out it was a bug in my code after all - I'd previously put in a wrapper for the RDC API to fix certain other bugs we were having; due to the large number of methods in the IReport interfaces, I wrote a script to generate pass-through stubs for the methods I wasn't interested in. Turns out that script was passing in bogus values for parameters with default values. Oops! Fixing the wrapper code fixed the bug here.

Code Analysis Error: Declare types in namespaces

Is VS2010, I analyzed my code and got this error:
Warning 64 CA1050 : Microsoft.Design : 'ApplicationVariables' should be declared inside a namespace. C:\My\Code\BESI\BESI\App_Code\ApplicationVariables.vb 10 C:\...\BESI\
Here is some reference info on the error. Essentially, I tried to create a class to be used to access data in the Application object in a typed way.
The warning message said unless I put my (ApplicationVariables) class in a Namespace, that I wouldn't be able to use it. But I am using it, so what gives?
Also, here is a link to another StackOverflow article that talks about how to disable this warning in VS2008, but how would you disable it for 2010? There is no GlobalSuppressions.vb file for VS2010.
Here is the code it is complaining a bout:
Public Class ApplicationVariables
'Shared Sub New()
'End Sub 'New
Public Shared Property PaymentMethods() As PaymentMethods
Get
Return CType(HttpContext.Current.Application.Item("PaymentMethods"), PaymentMethods)
End Get
Set(ByVal value As PaymentMethods)
HttpContext.Current.Application.Item("PaymentMethods") = value
End Set
End Property
'Etc, Etc...
End Class
I suspect that the code you entered is in your App_Code fodler of your web app. This code is accessible from your web code as you have deomnstrated but is not accessible from any other assembly.
You can suppress the instance of the error by right mouse clicking on the particular error and selecting "Suppress Message In Source." That'll result in code being added to your source that says "the next time you check this error-fuggedabodit!"
When to Suppress Warnings
--------------------------------------------------------------------------------
While it is never necessary to suppress a warning from this rule, it is safe to do this when the assembly will never be used with other assemblies.
To suppress the error on all occurences, select "Suppress in Project Suppression File"