.NET Framework

I'm trying to get my head around a good way to set up exception management in a custom class, if I understand some of the advice in CP articles and elsewhere correctly then something like this setup is 'a' good way:

Simplified case: A class encapsulates a 2D array and has an UpperBound property that takes a an integer and returns the UpperBound of that dimension (since it does not expose the array directly).

Rather than the UpperBound property testing that the integer is either 0 or 1, I should put the call to the array GetUpperBound(dimension) method in a Try block and catch the exceptions that can be thrown by the array method, then re-throw the exception from the encapsulating class with the array exception as the inner exception parameter. Is that smart?

Then if another method in the class uses the UpperBound property (in the encapsulating class) it should catch and re-throw the exceptions created by the UpperBound method (again with the inner exception as a parmater), hence the exception the programmer recieves has a trail directly from the methods they called through whatever path was then followed and ending up with the base exception thrown by the encapculated array.

For example:

'''<summary>''' Gets the upper bound of the specified dimension in the matrix
'''</summary>'''<paramname="dimension">A zero based dimension of the matrix. Must be zero or one since the a Matrix is two dimensional</param>'''<value></value>'''<returns>The upper bound of the specified dimension</returns>'''<exceptioncref="IndexOutOfRangeException">This exception is thrown if the specified <paramrefname="dimension"/><c> is less than zero or exceeds one, since the a Matrix is two dimensional</c></exception>'''<remarks></remarks>PublicReadOnlyProperty UpperBound(ByVal dimension AsInteger) AsIntegerGetTryReturnMe._matrix.GetUpperBound(dimension)
Catch inex As IndexOutOfRangeException
ThrowNew IndexOutOfRangeException("The dimension you specified is out of range for this matrix object. Matrix objects have only two dimensions, 0 and 1. See the inner exception for more detail.", inex)
Catch ex As Exception
ThrowEndTryEndGetEndProperty

Then if I had another method in my class (call it Iterate for example) that needed the UpperBound of the rows (dimension = 0), say to use in a For loop, it would again do this in a Try block, call the UpperBound property and catch the exceptions thrown by the UpperBound property. So if somehow this latter method (Iterate) managed to make a call to UpperBound(2) then the programmer would see the Iterate method throw an IndexOutOfRange exception with the UpperBound exception as its inner exception and that in turn would have the array GertUpperBound exception as an inner exception.

As long as your catching the exception adds value, then it's fine for you to catch it, add detail and then pass it back up the chain. A big note, in your sample though, you catch and throw the general purpose exception for no reason - as you are only interested in the IndexOutOfRangeException, that's the only one you should be catching there.

Thanks, Pete. In terms of adding value I am assuming that an exception raised by a method that you didn't call is harder to trace / debug, whereas if you have the full history then it should start with the method you called and you can then trace back to where that call went and probably have a better idea of where it went wrong - i.e. there's no apparent direct benefit of what I am doing in this (and most) cases other than tracing exceptions.

Pete O'Hanlon wrote:

in your sample though, you catch and throw the general purpose exception for no reason

That's something I saw in one of the CP articles (I think I interpreted it from this one[^]). I had read into it that what I am doing is saying that if anything I wasn't expecting happens, just re-throw the same thing to ensure you don't lose it, i.e. it's a side effect of a Try block. Maybe I assumed that without it I would in effect be 'swallowing' all other exceptions, but maybe that only happens if I catch the general purpose one and then leave the catch block empty?

Does your comment mean that it is redundant - i.e. is that what would have happended anyway, even without that last catch statement?

I had read into it that what I am doing is saying that if anything I wasn't expecting happens, just re-throw the same thing to ensure you don't lose it, i.e. it's a side effect of a Try block. Maybe I assumed that without it I would in effect be 'swallowing' all other exceptions, but maybe that only happens if I catch the general purpose one and then leave the catch block empty?

Actually, what I was referring to was don't bother catching it at all. When you catch and throw, without doing anything with the exception, it's a waste of time. So, in your case, all you needed to catch was the IndexOutOfRangeException. Any other exception is still going to show your method in the stack trace, so there is still context there for you to work with.

I am thinking of an app (C# windows app ) as it just needs to be started once - it must itself stand and loop - so it detects when there are new images also the to run automatically afterwards. Please enlighten me some ideas I will be ever so grateful.

This makes very little sense as it stands right now. I'm sure that you have a great understanding of what you want your application to do, but sadly, you haven't managed to convey it. For instance, what does it need to run automatically?

As far as monitoring for new images, take a look at the FileSystemWatcher, but be aware that there are some limitations with it that you need to understand based around when it fires events.

Well I am sorry for not being very clear, the scenario is like this, I get a number of HDR pictures in a folder, I have a program which batches these images and put them out in different folders, This particular program can also be used with command-line, So what I am trying to do is create an windows app, where I want to use this particular command, so all the images go in a single folder. Therefore I want construct this app where once I have started it giving it a source, it should keep running and once new images arrive it just simply updates. I don't know if it's clear enough or its simple not logical.

Okay, some things to think of - you will want to put your processing on background thread, I would recommend using the Task Parallel Library for this as it's so easy to use. I'm not clear on whether you are moving the original image, or copying them - if you are copying them, then move them into a processed folder as soon as you are finished.

I make it even simpler in one folder I put an app which on Run command runs and checks its existence. Lets says there are jpg images in it e.g image1 image2 image3 then it loops checking if there is more. If there is nothing it just keeps running and if there are new it just updates.

Hi, I recently found that knowing a .NET programming language itself isn't enough to become a pro .NET developer. So my question is where can I find best ebooks about knowing .NET framework structure, deeply and completely?

I recently found that knowing a .NET programming language itself isn't enough to become a pro .NET developer

.NET developer is very a broad term; it does not imply that you lack in-depth knowledge of the for loops, but that there are "area's" that you could still explore.

.NET can be used to develop web-apps, cross-platform desktop-apps and mobile apps. Did you try all three of those? Desktop can be divided into various GUI-concepts, like WinForms, WPF and Gtk#. Besides that, .NET offers some various additional technologies that are interesting to learn, like serialization, the MEF-framework, WCF and WF.

atoi_powered wrote:

So my question is where can I find best ebooks about knowing .NET framework structure, deeply and completely?

Warning 1 The referenced assembly "CrystalDecisions.CrystalReports.Engine, Version=13.0.2000.0, Culture=neutral, PublicKeyToken=692fbea5521e1304, processorArchitecture=MSIL" could not be resolved because it has a dependency on "System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which is not in the currently targeted framework ".NETFramework,Version=v4.0,Profile=Client". Please remove references to assemblies not in the targeted framework or consider retargeting your project. StudentManagementSystem

You have targetted the Client Profile in your project (take a look in the project properties). This doesn't include the web assemblies. You need to change your profile to the full .NET 4 profile to get access to System.Web.

For love nor money I cannot get the syntax right.I want to return 3 x 2D arrays from a function but can't wrap my head around it - I suspect I have just failed to grasp some fundamental aspect of jagged arrays!

Probably also worth noting, for posterity, that I solved this problem using a structure, 3 private members as double(,) and a constructor that takes the same as paramaters and off you go - quite a few advantages of doing it this way and I could also add a second constructor using just one parameter, the syntax Richard gave : ()(,) as double.

in visual studio 2010 when going in break mode and place the mouse over a var of object type that represent a com object from MS office application the VS visualizer shows as system.__ComObject and list all of the com object members.

in visual studio 2010 when going in break mode and place the mouse over a var of object type that represent a com object from MS office application the VS visualizer shows as system.__ComObject and list all of the com object members.

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machinekey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

This exception generally appears because Controls using DataKeyNames require Viewstate to be encrypted. And the viewstate hidden field might not have been rendered to the browser with long-running pages, and if you make a postback before it does, the page doesn't know that Viewstate is encrypted and causes the aforementioned Exception.The problem happens specifically when you postback before the EventValidation field has been rendered.

Workarounds:1. Set enableEventValidation to false and viewStateEncryptionMode to Never OR2. Mark the form as disabled and then enable it in script once the load is complete OR3. Override the Render Event of the page to place the hidden fields for Encrypted Viewstate and Event validation on the top of the form

Hi,I tried to connect VB.NET with MSAccess which is simple process in which i got error in connection.open()"The 'Microsoft.Jet.OLEDB.4,0' provider is not registered on the local machine".Am working with Windows 7 - 64 bit machine. Please help me with the above error.

As you are running x64 windows and Microsoft.Jet.OLEDB.4.0 provider is not 64-bit compatible.It seems to be version problem with the provider.

You can try this option and see if it gets ressolved:1. From the solution explorer right-click your project then click Properties2. Click the Build tab3. Change Platform target from: Any CPU to x864. Re-build your solutionThis may work.

We are looking for a .NET component which will do lookup tables (with interpolation). I've spent hours searching google/forums to no avail.

As the lookup table will be used frequently in a computationally intensive process, speed is of great importance. Ideally we would want to stay away from a database approach as we are not using database/tables anywhere else in the product.

We tried building a component ourselves but were struggling with speed. Our method came down to looping through every single element in the table and comparing it (calculating distance) to what we were trying to lookup. I should mention that we only are dealing with numbers and we have the need for higher dimensions in the table (ie. 1D, 2D, 3D, nD tables).

Can anyone recommend either an exisiting component or should we should try to optimize our algorithm and move to a native C++ implementation to gain speed?

As the lookup table will be used frequently in a computationally intensive process, speed is of great importance. Ideally we would want to stay away from a database approach as we are not using database/tables anywhere else in the product.

Meh, I was just about to recommend the TimesTen database.

HentoDeluxe wrote:

Our method came down to looping through every single element in the table and comparing it (calculating distance) to what we were trying to lookup.

Does your lookup have a key that you're comparing to? If yes, try a Dictionary. You might also enjoy benefits from reading up on database-theory; if your data contains several fields that you do for the lookup, it might be a cute idea to have something similar to an index.

HentoDeluxe wrote:

Can anyone recommend either an exisiting component or should we should try to optimize our algorithm and move to a native C++ implementation to gain speed?

You need to find the correct approach; changing language isn't going to help much.

I would like to convert a decimal number (base10) into hexadecimal and then save it into an unsigned char array.

I have an integer whose value increments from 1024 to a max of 2047 in steps of 1 whenever the user clicks a button. At each step I need to convert it to a hexadecimal number and save it into an unsigned char array or 2 elements so that I can send it to a device via USB.

For example:If I want to send 1955 decimal number I would like to have my unsigned char array as belowOut[0] = 0x07;out[1] = 0xA3then I can use my transferdata(out) function.

In order to provide the ability to use many different languages in .net, and for components written in one language operate with components written in another, we need to use the same primitive types. These are supplied by the CTS.

As we develop application in different language so they have different way of defining variable so How CLR will understand this.So for this .net define CTS like in c# we have int in VB we have Integer when they complied they are converted to Sysyem.int32 which is common for both language.

In Microsoft's .NET Framework, the Common Type System (CTS) is a standard that specifies how Type definitions and specific values of Types are represented in computer memory. It is intended to allow programs written in different programming languages to easily share information.