Debugging the application in .net - visual-studio-debugging

whenever an exception occurs,by default it creates an New object of exception class.
Is there a way to findout the how many exception objects are created in the application.
Or Is there anyway to put the breakpoint in the construtor of the exception class.

You can find out how many exceptions per second are happening in your app using VS profiling. Just launch a sampling profiler session from visual studio. See:
http://msdn.microsoft.com/en-us/library/ff647791.aspx
http://msdn.microsoft.com/en-us/library/kfhcywhs.aspx
http://msdn.microsoft.com/en-us/magazine/cc337887.aspx

Related

"ERROR: General failure building project output groups" while creating Set Up project in Visual Studio 2019

I made a Windows Form App for borehole heat exchangers simulation, consisting only of one Form. When trying to build a set up project to install the app, I constantly get an error in the building. Message appears like below, and 4 times each message. All this is using Visual Studio 2019 updated.
ERROR: General failure building project output groups
ERROR: Unrecoverable build error - 0x80004005
I checked that every image used in the app are in the source file, that I have done the building in the right order, but every time I create a project output, no .xml file appears.
Although I think it should be not an issue, the program also created a Form1.resx file that sends a message (not an error, neither a warning) Object reference not set to an instance of an object. I donĀ“t remember creating such thing. I tried to erase it and almost got my app deleted.
Does anybody now what can be the problem and how to fix it?
Mainly my process consisted in building classes that represent different modellings of a borehole heat exchanger. I then made the program build an "borehole" object of the certain class you choose in a ComboBox. I had no fundamentals whatsoever in coding so maybe this is not the way I should do that, maybe it shouldn't be classes. The app works perfectly on debugging mode.
Public Class Modelo2D
Inherits ModeloNTU
Public ReadOnly Property Calor2D As Double
Is there a problem in this?

Universal Windows Platform (UWP) and SQL Server

I've hit a wall when it comes to how the Universal Windows Platform connects/manages/interacts with a local SQL Server database. My current project (WPF using .NET Framework 4.8) that I'm interested in porting over to UWP uses EntityFramework 6 with ADO.NET models and it works like a charm. No issues at all. UWP on the other hand, well I'll just say that I have absolutely no idea what's going on when it comes to connecting to a local instance of SQL Server. I've gone through about 3-4 different guides/templates and none have worked. I really want to use UWP and take advantage of all the new features coming for Windows 10 v2004, but it doesn't look like this will happen.
As I currently understand the process, I need to essentially create two separate projects within the same solution. One is the UWP main program and the other would be a .NET Core class library that targets the .NET Standard 2.0 platform. I also have read that EntityFramework 6 is not supported on .NET Core or UWP, so the only way is by using EntityFrameworkCore (more specifically NuGet package Microsoft.EntityFrameworkCore.SqlServer). So I installed it on the .NET Core class library and then set a reference from the UWP app to the class library. Because the local SQL Server is already up and running, I'm not doing what is called the 'code first' approach to the creation of all the models/DbContext.cs files. Based on what I've read, the ONLY way to import a currently existing SQL Server into the data model is by use of the Scaffold-DbContext command with a standard connection string through the package manager. Surprisingly, this worked on the first attempt and the models and DbContext were all created without any issues.
This is about as far as I seem to be able to get as everything after does nothing but throw exceptions. If I try to pass any C# code using the DbContext to retrieve any data from the database, I get about 10-15 exceptions that essentially say the program can't find or connect to the database. I have manually edited the connection string in every way imaginable, but nothing seems to work. I also tried to manually set up a new connection using Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient.SqlConnectionStringBuilder and System.Data.SqlClient.SqlConnection but they all fail with the same exceptions.
Sorry for the long post but at this point, I really don't know what's going on and would really appreciate any feedback you all could offer.
Update 1
So, I went back through my currently working app on .NET Framework and looked for the connection string in the App.config file to see what the regular EntityFramework is using and it's completely different than anything I've used before. My guess is that it's generating a completely custom connection string that includes references to all sorts of files and a property called 'ProviderName'. Will try cutting and pasting this string into UWP to see if it'll work.
Update 2
I think I'm missing something fundamental on this. I can generate the scaffold with a connection string without any issues, but if I attempt to open a connection at runtime using the same connection string, I'm getting errors.
Finally was able to get a connection at runtime after months of trial and error. Without getting into too much detail, here's what worked for me (assuming EFCore has already generated a DbContext file):
Enable Enterprise Authentication.
Enable TCP/IP connections to the SQL Server instance.
In Visual Studio's server explorer, click Add Connection. If you already have a connection saved for the database, right click the server and click Modify Connection
In the connection properties window, click the Advanced button. Make a note of all of the listed parameters and their values and save it.
Open the data context file that isn't able to connect and add a using statement for Microsoft.Data.SqlClient. Now locate the OnConfiguring method. Use a SqlConnectionStringBuilder and configure all of the parameters from the advanced connection properties that were saved earlier.
And that should work. If there are still errors, I would double check the parameters to make sure they were all entered correctly.
Hope this post will help out anyone else dealing with this issue.

Setting Report Source in Crystal Report for .Net throws a NullReferenceException in crdb_adoplus.dll

I have come across a very strange exception when using Crystal Reports XI for dot net. I'm currently developing a reporting service in VB.Net for an enterprise application. The service is hosted in the main application as a plugin/add-in using System.AddIn (aka Managed Add-in Framework or MAF). The main application utilizes Win Forms, and will be hosting controls provided by my add-in in a WPFElementHost.
The add-in resides in it's own app domain and passes WPF controls using NativeHandleContracts from the add-in app domain, to the host app domain where they are bound at runtime to the WPFElementHost.
The WPF control the add-in provides has a Crystal Report Viewer Control in it. Up to this point, everything works fine. I can create nearly any WPF control in my Add-in and it works flawlessly in the host application. This falls apart as soon as I try and attach a report to the viewer.
First I tried using and ADO.Net DataSet as my data schema to build my report against. Whenever this would try and load into the report viewer, crystal reports would throw an exception that the schema didn't exist. This was caused because for some reason crystal report want's to look in the host applications app domain, as well as namespace for the schema. However The schema exists in an entirely different app domain and namespace. I tried embedding the schema as a resource, and copying local. With no success I moved on to using .Net Objects.
With .Net Objects I created an XML document that the report is designed against. This worked fine and allowed me to pass my report and view it in the host application. This is where I am stuck at the moment. Whenever I try and supply a DataSource for the report Crystal Reports throws a null reference exception in the crdb_adoplus.dll which is SAP's DLL and gives me no indication of what caused the exception. All of my objects are properly instantiated, the report, viewer, wpf element host, and the wpf control. My dataset, which is served using entity framework, is being converted to a DataSet so there are no nullable types in it, only dbnull values. There is no reason this exception should be throwing at this point. No additional output is provided other than the exception being thrown.
Additionally, the report object that is created will have portions of it time out during this loading process. This will happen without any exceptions or errors of any kind being thrown.
Here is the code that is retrieving the data, attempting to bind data to the report, and binding the report to the viewer.
Try
Dim messages As String = Nothing
If report Is Nothing Then
report = New BOMPartsListWithStandard
End If
Using conn = BOMReportingService.BOMReportingServiceClient.CreateConnection()
Dim dataSet As DataSet = conn.Proxy.GetBOMTreePartsListElements(5339, messages).ToDataSet
report.SetDataSource(dataSet)
End Using
reportViewer.ViewerCore.ReportSource = report
reportViewer.ViewerCore.RefreshReport()
Debug.WriteLine($"Created and attached report succesfully. With {IIf(String.IsNullOrEmpty(messages), "no messages.", messages)}")
Catch ex As Exception
Debug.WriteLine(ex.ToString)
End Try
The report.SetDataSource(dataSet) bit of code is where the exception is being thrown.
Am I overlooking somthing obvious? Is there a way to convince Crystal Reports to use an ADO.Net DataSet in the correct app domain so I can get away from the XML issue?
This add-in needs to exist in a separate app domain, or process, so that it can be unloaded and reloaded dynamically at runtime. This is a requirement for the system. It also needs to be self contained, so I can't do anything on the host side of the application, it all must operate within the add-in.
Thanks in advance for the help.
After digging around I figured out an answer to my own question. So i'll post the answer here just in case someone else comes across a similar problem.
The problem seems to lie in how the report interprets the DataSet object. For some reason it get's lost when looking for data. So you have to point it to the actual first table entry.
So I changed this bit of code:
Using conn = BOMReportingService.BOMReportingServiceClient.CreateConnection()
Dim dataSet As DataSet = conn.Proxy.GetBOMTreePartsListElements(5339, messages).ToDataSet
report.SetDataSource(dataSet)
End Using
I replaced report.SetDataSource(dataSet) with report.SetDatSource(dataSet.Tables(0)). So now it looks like this
Using conn = BOMReportingService.BOMReportingServiceClient.CreateConnection()
Dim dataSet As DataSet = conn.Proxy.GetBOMTreePartsListElements(5339, messages).ToDataSet
report.SetDataSource(dataSet.Tables(0))
End Using
Hopefully this will help someone else out in the future.

Silverlight Exception Message is different on other machines

I am currently stuck with the following problem and running desperately out of ideas, any clues are welcome!
We are using a custom built framework that loads what we call "pages" on demand for the UI, each of these "pages" is a self contained Silverlight XAML that is loaded on demand via:
XamlReader.Load(somePageXamlFile)
It may happen that a part inside this xaml is outdated, so a try / catch block ensures that a XAMLParseException is caught and the respective error handled.
Our current error handling is heavily based on the message of the exception, e.g. we expect a message like this:
"The type 'someType' could not be found. [Line: x Position: y]"
-> we parse the message string and replace the essential xaml parts with custom logic to make it valid again and display info for administrators.
The problem:
Some test machines throw the same exception, but with a different message!
Errormessage there:
"Error 2502 An error has occured."
This breaks our "safety net" logic for this case and currently we can not figure out any reason for this.
Solutions or proposals are very welcome,
thanks in advance!
-Steve
After long and hard search we came down to the following: The clients and the development machines seem to have different versions of the Microsoft agcore.dll (development machines have 2 different version in different paths). As this is the core of the exception we suppose this is the reason for the different error message - we were unable to fix this issue however (we cannot be sure what dll our clients get during SL5 download...) therefore we decided to rewrite the whole code segment to not make use of the exception message text at all. Lesson learned.
Thanks for the feedback. -Steve

How can I get details about a Silverlight code generation exception?

I'm getting the following error now when I build my Silverlight Business Application:
The code generator
'Microsoft.ServiceModel.DomainServices.Tools.CSharpCodeDomClientCodeGenerator'
encountered a fatal exception and
could not generate code for project
'C:\Software\ProjectPartCenterAdmin\Alpha\Latest
Version\ProjectPartCenterAdmin\ProjectPartCenterAdmin.csproj':
Exception has been thrown by the
target of an invocation.
I DID ABSOLUTELY NOTHING TO MY CODE since it last worked! All I did was a clean rebuild of the application. Is there a way to get the details on what the exception was? I am dead in the water until i can figure this out.
Oh, and by the way, I hate code generation! I've had endless problems with RIA Services and I'm trying my best to do things "the right way"; that is, no hacks.
Edit:
I've also been getting a similar warning:
The following exception occurred
creating the MEF composition
container:
Unable to load one or more
of the requested types. Retrieve the
LoaderExceptions property for more
information.
The default code
generator will be used.
I've been getting this for some time now, and have ignored it because the application seems to be working fine.
Also, when I remove my CustomValidation attributes the exception goes away. But the warnings do not.
First, you need to check if there were custom validation errors in the project. I had the same issue but when I realized that I had two validation result methods with the same name! and change it, the built was successfull.

Resources