|
You could try to subscribe to the System.AppDomain.UnhandledException event, see if you can intercept the app.config error.
|
|
|
|
|
Thanks Mirko1980!
My code and app.config looks like this, but no exception is thrown. Any ideas?
class Program
{
public static void MyEventHandler(object sender, EventArgs e)
{
return;
}
static void Main(string[] args)
{
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.UnhandledException += MyEventHandler;
return;
}
}
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configuration>
regards,
George
|
|
|
|
|
Hi,
Code like this will catch the exception which occurs when the form is created.
Alan.
try {
CsTermForm mainForm = new CsTermForm();
Application.Run(mainForm);
} catch (System.Configuration.ConfigurationException ce) {
MessageBox.Show(ce.ToString());
}
|
|
|
|
|
Hi Alan!
Your code works ok in a Windows forms application. But for a console application, how to handle?
regards,
George
|
|
|
|
|
Hi,
Pretty much the same really. You just have to wrap any code that may access the settings in an exception block.
I've just trashed one of my config files and the following code trapped the exception.
static Int32 Main(string[] args) {
try {
App app = new App();
Int32 exitcode = app.Run();
return exitcode;
} catch (System.Configuration.ConfigurationException ce) {
Console.WriteLine(ce);
return 1;
}
}
|
|
|
|
|
Hi Alan,
I am writing a DLL, could I handle such issue inside the DLL?
regards,
George
|
|
|
|
|
George,
George_George wrote: could I handle such issue inside the DLL?
That I don't know. I've only ever used a top level handler designed to just stop the application dead in it's tracks if the config file is corrupted. If the exception occurs within the dll it will of course be passed up the call stack until a handler is found.
One thing to note is that changes to the dll's user scoped configuration settings are stored in the exe's user.config file so I suspect the best place to trap any exceptions caused by malformed xml is very early in the execution of the application.
Anything more precise than that is beyond my current level of knowledge. I had a quick look at the System.Configuration namespace and decided I wouldn't go back there again unless I absolutely had to!
Alan.
|
|
|
|
|
Thanks Alan,
1.
I can put the exception handling to EXE level. But it is still different from your posted solution before -- you use a starter EXE to track the actual configuraiton issues in the inner EXE, correct?
2.
So, do you have any ideas to let the EXE itself handle the app.config issue?
3.
If you do not suggest to handle such issue, what is your point and any advice to let end user know such issues (because of configuration file format error)?
regards,
George
|
|
|
|
|
Hi All,
I have a base class (Day) and collection class (Days) and I want to inherit from them both:
public class Day
{
Members…
}
public class Days : List<Day>
{
Methods…
}
To inherit from the Day class is straight forward
public class SpecialistDay : Day
{
Specialist Members…
}
The question is, can I inherit the members from SpecialistDay and the methods from Days with a SpecialistDays collection class?
Many thanks
Janet
Lady Programmers are a rare breed!
|
|
|
|
|
Hi,
this is how I understand it:
- you can create a special list of Days, with class SpecialDays1 : Days, but then the items have type Day
- you can create a list of SpecialDays, with class SpecialDays2 : List(SpecialDays), but then you don't inherit from Days.
However if you want a special list of special days, then you should inherit from a generic special list. You could achieve that like so (you may want to restrict T below):
public class DayList< T> : List< T> {}
public class SpecialDayList< T> : DayList< T> { ... }
public class Day { }
public class SpecialDay : Day { ... }
public class Days : DayList< Day> { }
public class SpecialListOfSpecialDays : SpecialDayList< SpecialDay>
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
modified on Friday, February 27, 2009 9:04 AM
|
|
|
|
|
Yeah, that sounds about right. Maybe add where clauses to the lists.
|
|
|
|
|
If you're asking about multiple inheritance, that is, a class SpecialistDays that inherits from both SpecialistDay and Days, then, unfortunately, you can't do that in .NET. This could also lead to the Fragile Base Class[^] problem if your base classes change a lot; this problem lead to the famous article Why extends is evil[^], a Java-based discussion that is completely applicable to the C# world.
Perhaps you want to do the following:
public interface IDay {...}
public interface IDays {...}
public interface ISpecialistDay : IDay {...}
public interface ISpecialistDays : IDays {...}
public Day : IDay {...}
public Days : IDays {...}
public SpecialistDay : ISpecialistDay
{
... ISpecialistDay methods here ...
... method proxies for IDay methods to internal Day ...
private Day _internalDay;
}
public SpecialistDays : ISpecialistDays
{
... ISpecialistDays methods here ...
... method proxies for ISpecialistDay methods to internal Days ...
private Days _internalDays;
} This way you get the inheritance of the methods without worrying about implementation.
You don't see a lot of this in C#/VB.NET because creating partial proxy objects often feels painful. Alas, it's what we've got.
"we must lose precision to make significant statements about complex systems."
-deKorvin on uncertainty
|
|
|
|
|
Hello, i use this to transform an excel file to pdf :
<br />
static void Main(string[] args)<br />
{<br />
ApplicationClass excelApplication = new ApplicationClass();<br />
Workbook excelWorkBook = null;<br />
<br />
<br />
<br />
string paramSourceBookPath = @"C:\2.xlsx";<br />
object paramMissing = Type.Missing;<br />
<br />
string paramExportFilePath = @"C:\test.pdf";<br />
XlFixedFormatType paramExportFormat = XlFixedFormatType.xlTypePDF;<br />
XlFixedFormatQuality paramExportQuality =<br />
XlFixedFormatQuality.xlQualityStandard;<br />
bool paramOpenAfterPublish = false;<br />
bool paramIncludeDocProps = true;<br />
bool paramIgnorePrintAreas = true;<br />
object paramFromPage = Type.Missing;<br />
object paramToPage = Type.Missing;<br />
<br />
<br />
<br />
try<br />
{<br />
excelWorkBook = excelApplication.Workbooks.Open(paramSourceBookPath,<br />
paramMissing, paramMissing, paramMissing, paramMissing,<br />
paramMissing, paramMissing, paramMissing, paramMissing,<br />
paramMissing, paramMissing, paramMissing, paramMissing,<br />
paramMissing, paramMissing);<br />
<br />
if (excelWorkBook != null)<br />
excelWorkBook.ExportAsFixedFormat(paramExportFormat,<br />
paramExportFilePath, paramExportQuality,<br />
paramIncludeDocProps, paramIgnorePrintAreas, paramFromPage,<br />
paramToPage, paramOpenAfterPublish,<br />
paramMissing);<br />
}<br />
catch (Exception ex)<br />
{<br />
Console.WriteLine(ex.ToString());<br />
}<br />
finally<br />
{<br />
if (excelWorkBook != null)<br />
{<br />
excelWorkBook.Close(false, paramMissing, paramMissing);<br />
excelWorkBook = null;<br />
}<br />
<br />
if (excelApplication != null)<br />
{<br />
excelApplication.Quit();<br />
excelApplication = null;<br />
}<br />
<br />
GC.Collect();<br />
GC.WaitForPendingFinalizers();<br />
GC.Collect();<br />
GC.WaitForPendingFinalizers();<br />
}<br />
<br />
<br />
}<br />
But how i can set the file in A4 format? because my excel file is bigger than A4, thank you verry mutch.
|
|
|
|
|
Hi All,
I have opened one bmp file and I want to save this bitmap as monochrom bitmap file. Please do note when the monochrom file is open using mspaint or any other tool and when you select save as it should automatically give monochrom bitmap format.
Can anybody help me out here.
|
|
|
|
|
|
hi,
i am making use of FolderBrowserDialog of .net. the problem is it is showing me control panel when FolderBrowserDialog under my computer and it allows files to be saved in administrator tool. how to avoid showing control panel.
|
|
|
|
|
You cannot customize FolderBrowserDialog , to hide special folders. If its visible in Windows Explorer, then its visible on your dialog too.
To hide "Control Panel" from Win Explorer, go to "Folder Options", "View" tab, and uncheck "Show Control Panel in My Computer".
Calin
|
|
|
|
|
Calin,
the Control Panel is hidden in win explorer i,e the check box is unchecked, but still the FolderBrowserDialog is showing the control panel.
|
|
|
|
|
|
yes i think i need to build my own custom control for this... thanks for the input...
regards
sudhir
|
|
|
|
|
Even if you hide the Control Panel, user can always manually travel to the folder location and save files there. Hence, hiding control panel is not going to solve your problem.
All I can suggest is to create your own control and do not let user select the folder you dont want to.
Time is the best teacher; unfortunately it kills all of its students.
जय हिंद
|
|
|
|
|
yes i think i need to build my own custom control for this
regards,
sudhir
|
|
|
|
|
what about error handling after the dialog is confirmed?
you can check the directory, if its one you dont what to use then inform the user and display the folderbrowsedialog again
If only MySelf.Visible was more than just a getter...
A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting
|
|
|
|
|
yes now i am doing that only as i want to avoid user saving the files in administrator tools folder, i am checking is he selected theat folder and if yes then i am showing him a msg telling he cant save there...
thanks anyway...
|
|
|
|
|
Hi,
How can word document pages convert to jpeg?
Thankyou
Yesuprakash
|
|
|
|