Oop - .NET Class Properties Ends Up In Circular References And Through StackOverflow Exception?
Jan 9, 2012
I have 2 classess. Role and User like this
Role
Public Class Role
Public Property RoleID As Integer
Public Property CreatedBy As User
[code]....
The situation is like when we create roles, we will save who created this role. So i have a CreatedBy Property of type User. Similarly when we create a User, we will mention what role the new user belongs to .So i have a property called "Role" of type "Role". This circular reference giving me StackOverflow exception as its recursive when i create an object of User class.How do i handle this ? should i restucture my entties ? how ?
I have a button which opens FormTest. When FormTest opens, it creates an instance of ClassTest and that class instance takes the form instance that called it (FormTest) so that it can perform operations on FormTest from the ClassTest class instance. So i have a form which owns an instance of a class which has a reference to the form.
I'm implementing some custom serialization (to byte array), and have run into a problem handling circular references.Example:
Class A public MyBs as new List(of B) End class
Class B public MyParent as A public MiscInt1 as integer[code]....
If I know that an instance of B will only ever be serialized through the serialization of an instance of A, then I can handle the setup of the MyParent reference from the instance of A and not even record that information inside the byte buffer for the instance of B.This doesn't feel quite right, but it might be the best solution.
I have a theory that the CLR garbage collection mechanism means that I can get away with circular references in my object hierarchy without creating deadlocks for teardown and garbage collection. Is this a safe assumption to make? (Target language VB.NET)
I have done some reading and it seems that this error comes from recursive calls but I have not done anything in my form_closing handler except for call me.close, that's it.
So I don't understand how this exception has entered my project. All of my data and functionality is still working as I expect. It just seems to throw this exception when I try and exit my project.
what I could check to prevent something like this from happening?
when i select a reference, it doesnt show the properties for it any longer. I would really not have to copy every reference locally for each project im working on, as well as im not too keen on reloading visual studio either.
I am trying to create a tool which executes some oracle procedures and telnet commands. Besides this Job my tool also needs to update a counter in some table in oracle db at regular intervals(10 secs as per current settings). So I used backgroundworker class in VB.NET to implement this back ground job of updating the counter. My problem is I have put logs at every possible exit of the backgroundworker_dowork functions but still this logic stops working after some time --7-8 hours. I am not able to understand when/where/why/how is it stopping? I am saying logic has stopped because it stops incrementing the counter. And am saying it is exiting abruptly because in _RunWorkerCompleted, I have written a log and closed the application but nothing comes in the log and application is not exiting.
Private Sub backlogicthread_DoWork(ByVal sender As Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles backlogicthread.DoWork WriteLog("Background worker", "entered") dbbackcontrol = New OracleConnection(odbcBill) Dim dr As OracleDataReader [Code] .....
I tried adding a loop inside this loop but continue to get the error "Null reference exception was unhandled" before the loop ends.
For rowIndex = 0 To dgvVisit.RowCount - 2 MessageBox.Show(dgvVisit.Rows(rowIndex).Cells("CoPayCharge").Value.ToString) For rowIndex1 = 0 To dgvPayment.RowCount - 2 MessageBox.Show(dgvPayment.Rows(rowIndex).Cells("CoPayPaid").Value.ToString) Next Next
I have recently started learning VB.NET. I created a simple 3 tier windows application. The DAL project contains a class with a number of functions. In the BLL project, I've added a reference to the DAL project, but I still can't access the functions in the DAL class from the BLL. However, if I change the DAL class to a module, I can access them then. Both the DAL class and its functions are public.
When I try to create a instance of a COM class it throws an exception as Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
When I try to create a instance of a COM class it throws an exception as Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG))
This is another one of my "I think it's not possible but I need confirmation" questions.I have a base class for a bunch of child classes. Right now, this base class has a few common properties the children use, like Name. The base is an abstract class (MustInherit)Technically, this means that everytime a child class is instantiated, it lugs around, in memory, its own copy of Name. The thing is, Name is going to be a fixed value for all instances of a given child. I.e., Child1.Name will return "child_object1", and Child2.Name will return "child_object2".
I have Crystal Reports 2008 installed on my win7 laptop but when i go to insert references from my application settings the CrystalDecisions references are missing and im not able to find them. Note: they do exist in my "c:windowsassembly" folder.
I have a class in which some of the fields are also classes.I can put values in the "normal" properties, but in the others when o try to assign values it gives the: "Object reference not set to an instance of an object"But the code compiles fine.
dados_Defenicao = New ServiceReference1.draftClaimEntryDefinition dados_Defenicao.arCode = "123" dados_Defenicao.claimMarket.warrantyType = "w" - Here it gives the error
I have a class in which some of the fields are also classes.
I can put values in the "normal" properties, but in the others when o try to assign values it gives the: "Object reference not set to an instance of an object"
But the code compiles fine.
dados_Defenicao = New ServiceReference1.draftClaimEntryDefinition dados_Defenicao.arCode = "123" dados_Defenicao.claimMarket.warrantyType = "w" - Here it gives the error
Code will run from frmFacility and will shift into UserControl:
Public Class frmFacility Private primaryBaseDay As Date Private isClassPrimaryView As Boolean = False
[Code].....
At the line If facilityForm.IsOnPrimaryView Then, I get a NullReferenceException. Do you know the reason?
Also, I cannot create a new instance of the facilityForm, since I need to work with its singleton, although when I add a new instance of frmFacility, the IsOnPrimaryMode is set to false while it should be set to true in the gotoday sub from frmFacility.
I'm slowly learning about loops. I have a couple of questions
1) When a condition is being tested.. what does that mean? I don't understand the "condition" word.
2) What is the difference between a loop that never ends and a loop that ends?
I have the code for the loop that ends and the loop that never ends. I can see the difference in the code, but I don't understand what is making it different. Here is the code below.
I wrote a function that copies the properties of one class to another so make a copy of an object.So something like
MyObject myObject = myOtherObject.MyCustomCopy(myObject) where myObject and myOtherObject are of the same type. I do it by bascually doing myObject.prop1 = myOtherObject.prop1
[code]....
I am pretty sure in the past I used a .NET object that automaticaly did this, by reflection I guess, but can't remember it ... or an I imagining that such a method exists?
Okay, so I wrote a few custom ItemTemplates for VS2010 that implement IWizard in VB.NET (4.0). Straight forward enough. They work during my testing, but when someone else deploys and attempts to use any of them, Visual Studio throws an incredibly generic Exception has been thrown by a target of invocation error.
Stranger still, after they open up the project properties and try again... they work. Without changing anything. Anyone have any clue what is going on? Or perhaps even just a way of getting VS to give me a more specific error? I already tried devenv.exe /log but nothing out of the ordinary was there.
Class Foo ReadOnly name As String Public Sub New(name As String, dependentUpon As Foo) Me.name = name
[code]....
The output of New Bar() is:
Dependent created. Dependent upon nothing. Independent created. Dependent upon nothing.
It seems fields are initialized in the same order as they appear in the source code, which (a) leads to an unexpected result, and (b) seems a little puzzling, given that one is normally not permitted to read from uninitialized variables in .NET, yet that seems to be working fine above.I would've expected VB.NET to be smart enough to initialize referenced fields first, and only then those that reference it; i.e. I'd have liked to see this output instead:
Independent created. Dependent upon nothing. Dependent created. Dependent upon Independent.
how to get VB.NET to behave like that instead, without simply having to swap the declaration order of dependent and independent inside class Bar?
I have a program that uses Lucene.net in ASP.NET (VB.NET), when you search a term, results are stored in the Lucene.net data structure "hits".I want to read out the hits into an data structure and work with them, after that I display them in a DataGrid.By searching a term with a lot of results, often (but not always) there is an error by following code :
For i = 0 To results - 1 Step 1 Try Dim tmpobj As New object_hit(( _ hits.Doc(i).Get("title") + _
[code]....
I checked the server; it's a dwh server and has no problems to execute the program.At first I used a ReDim Array, but now I use a List(Of T).
as you might guess from the variable names I'm making a game (but this problem isn't game related!) which involves multiple "bullets" moving along straight trajectories. This is my attempt at changing my code for firing one bullet into one for firing many bullets at once. It works perfectly except for one thing.The class I made (BulletClass) to contain all the things needed to move the bullet isn't setting all of its properties correctly. I apologise for the walls of code however I wasn't entirely sure whether I should chop bits out. I wanted to colour code my code so that you could scroll through and see the subs where things have gone wrong, but apparently I can't even code a new thread. Let alone a video game. Instead I'll just list them, you can search for them if you like or just scroll through at your leisure.
[Code]...
In a nutshell: the properties TargetPosY, TargetPosX, ShipPosX and ShipPoseY are not working properly. As a result the calculations involving them are skewed and the bullets always travel directly downward.
[URL]notice that the tag topic count for C# is in excess of 8900 while the vb.net tag topic count is sitting at 1019. Does this mean that there is a shift towards c# as a .net language of choice. the only reason I decided to build some applications for work using c# was that I like curly braces - after all vb has the same language support as c#, doesn't it so there should be no advantage to choosing one over the other; other than curly braces;)
I have an StackOverflowException in one of my DB functions that I don't know how to deal with. I have a SQLite database with one table "tblEmployees" that holds records for each employees (several thousand posts) and usually this function runs without any problem.
But sometimes after the the function is called a thousand times it breaks with an StackOverflowException at the line "ReturnTable.Load(reader)" with the message: An unhandled exception of type 'System.StackOverflowException' occurred in System.Data.SQLite.dll
If I restart the application it has no problem to continue with the exact same post it last crashed on. I can also make the exactly same DB-call from SQLite Admin at the crash time without no problems.
Here is the code:
[Code]...
When crashes, the reader has "Property evaluation failed." in all values.I assume there is some problem with allocated memory that isn't released correctly, but can't figure out what object it's all about. The DB-connection opens when the DB-class object is created and closes on main form Dispose.
Should I maybe dispose the mycommand object every time in a finally block? But wouldn't that result in a closed DB-connection?
I need some advice to make a small application running, i need to calculate a integer prime and i use a recursive function inside a while true loop, first i get a random number with random class and then i call the recursive function that checks if it's prime, if it's prime it exits the while. Sometimes it works others throws the stack overflow exception, what i must do to get rid off this exception?