|
You are absolutely right, and since I have dozens of those nasty little bit manipulation
things, that will speed up my interest in 3.0
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
public frmEditor(string[] ProfileToUse)
{
ProfilesTypes = ProfileToUse;
dbProfiles.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = G:\\CSharp\\Project.mdb;Jet OLEDB:Database Password=password1";
InitializeComponent();
}
string ProfileTypesInUse = "";
bool isUpdate = false;
private void frmEditor_Load(object sender, EventArgs e)
{
if (ProfilesTypes[0] == "ProfileID")
{
try
{
isUpdate = true;
OleDbCommand cmdGetProfileFields = new OleDbCommand("select type_id from proProfiles where profile_id= " + ProfilesTypes[1], dbProfiles);
if (dbProfiles.State == ConnectionState.Closed)
dbProfiles.Open();
string[] sep = new string[1];
sep[0] = ",";
string[] ptu = cmdGetProfileFields.ExecuteScalar().ToString().Split(sep, StringSplitOptions.RemoveEmptyEntries); //I keep getting an error "Object reference not set to an instance of an object.
for (int i = 0; i < ptu.Length; i++)
Can someone please help me with this problem??
|
|
|
|
|
Are you using Visual Studio? ...Have you tried using the debugger? ...put a breakpoint on that line and when you hit F5, it should stop execution on that line....put "cmdGetProfileFields" and "sep" into your watch window and see what is returned to you....if either of those show the value of "object reference not set to an instance of an object", then you've pinpointed the cause of your exception
"I need build Skynet. Plz send code"
|
|
|
|
|
It gives me ptu value null and sep value is {Dimensions:[1]} in the Watch Window. What should I do now? I need {Dimensions:[2]} for ptu
|
|
|
|
|
T4AMD wrote: string[] ptu = cmdGetProfileFields.ExecuteScalar().ToString().Split(sep, StringSplitOptions.RemoveEmptyEntries);
seems like ExecuteScalar returns null.
if you want to be sure about this, split the line in two:
object obj=cmdGetProfileFields.ExecuteScalar();
string[] ptu = obj.ToString().Split(sep, StringSplitOptions.RemoveEmptyEntries);
and either add a null test, or use the debugger again.
If it is null, I can not tell you why...
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
I keep getting the same error when i tried your code Luc, and I think that ExecuteScalar is returning a null value
|
|
|
|
|
I use the code below to remove commants from xml strings.
The C# guru wrote me: that this code is wrong
since while iterating a collection it is not allowed to remove its element.
He wrote this is .NET bug: this code sholud throw exception.
Please confirm, is this .NET bug ?
How to remove comments from xml string (fix this code)?
using System;<br />
using System.Windows.Forms;<br />
using System.Xml;<br />
<br />
public class Test<br />
{<br />
[STAThread]<br />
static void Main()<br />
{<br />
XmlDocument xDoc = new XmlDocument();<br />
xDoc.PreserveWhitespace = false;<br />
xDoc.LoadXml(xml);<br />
XmlNodeList list = xDoc.SelectNodes("//comment()");<br />
foreach (XmlNode node in list)<br />
{<br />
node.ParentNode.RemoveChild(node);<br />
}<br />
}<br />
<br />
const string xml = @"<?xml version=""1.0""><br />
<Report><!-- --></Report><br />
";<br />
<br />
}<br />
Andrus
|
|
|
|
|
No, it's not a bug. He's saying it should be, but that would involve changes to the compiler to add mind reading capability.
Enumerating a collection is valid only so long as the collection remains unchanged. Adding and removing items changes the collection. If either of these operations happen, the Enumerator is automatically invalid because the bounds of the enumeration are no longer known and it's also unknown if the current item even exists anymore. When this happens, the Enumerator is no longer is a known state and cannot be recovered. It's behavior is undefined.
Enumerators do do not exclusive access to the collection, so enumerating one is inherently not a thread-safe operation. The collection CAN be modified from outside the enumeration. If this happens, the enumerator is, again, invalid.
If you're going to modify a collection, you cannot use foreach . You must use a normal for statement with an index into the array of items.
|
|
|
|
|
I did'nt understand your reply. You wrote that this code modifies same collection inside foreach loop which is not allowed.
.NET does not throw exception for this code.
So it is .NET bug, isn't it ?
Chris Shepherd explains:
A cloned IEnumerable instance is *not* the same IEnumerable, by nature. It may have references to the same data, but it
does not necessarily contain the same list of references. If you remove
items from the newly cloned instance, it won't affect its progenitor,
and vice versa. Kind of the point of clone, really.
This code is functionally working with two different IEnumerable objects. Below is an example of effectively what
original code is doing -- removing a subset of items in one list from
another list.
class General<br />
{<br />
class ClassA<br />
{<br />
public string name;<br />
<br />
public ClassA(string nm) { this.name = nm; }<br />
}<br />
<br />
static void Main(string[] args)<br />
{<br />
List<ClassA> listOne = new List<ClassA>();<br />
List<ClassA> listTwo = new List<ClassA>();<br />
<br />
ClassA a = new ClassA("A");<br />
ClassA b = new ClassA("B");<br />
ClassA c = new ClassA("C");<br />
ClassA d = new ClassA("D");<br />
ClassA e = new ClassA("E");<br />
<br />
listOne.AddRange(new ClassA[] { a, b, c, d, e });<br />
listTwo.AddRange(new ClassA[] { a, c, d });<br />
<br />
string msg = "Start Length of listOne: " +<br />
listOne.Count.ToString() +<br />
"\nStart Length of listTwo: " +<br />
listTwo.Count.ToString() +<br />
"\nWhat is removed:\n";<br />
foreach (ClassA z in listTwo)<br />
{<br />
msg += z.name + "\t";<br />
listOne.Remove(z);<br />
}<br />
<br />
Console.WriteLine(msg + "\nLength of listOne: " +<br />
listOne.Count.ToString() +<br />
"\nLength of listTwo: " +<br />
listTwo.Count.ToString());<br />
}<br />
}<br />
Andrus
|
|
|
|
|
AndrusM wrote: You wrote that this code modifies same collection inside foreach loop which is not allowed.
.NET does not throw exception for this code.
So it is .NET bug, isn't it ?
No, it's not a compile time error. There is no way for the compiler to know that the method called "Remove" removes items from the collection. You could call the very same method "Jaxtapose". The name of the method doesn't tell the compiler anything other than "this is a name". The compiler cannot tell what the code inside the method does.
It WILL throw a run-time exception though.
|
|
|
|
|
No, it will *not* cause run time exception in .NET 2 and 3.5.
It removes all comment from XML.
So my question was: Is this .NET but that this code does not cause run-time exception ?
Andrus
|
|
|
|
|
I wasn't talking about your code. I was talking about what the other person said about what should be a "bug". There are a few exceptions to the rule. It would appear that you have found one of them.
|
|
|
|
|
This cCode removes iterated item from collection inside foreach loop.
C# clearly does not allow to change iterated collection in foreach body.
This should cause exception.
So why do you think that this is exception of this rule and should be allowed ?
Andrus
|
|
|
|
|
Not that last snippet you posted, it's enumerating one collection and removing from the other, so there's no problem.
|
|
|
|
|
He's right. The snippet you posted isn't doing anything to the collection being enumerated. The exception to the rule...
|
|
|
|
|
Hi,
I have been making a tuning program for instruments, the idea being you play, a guitar say, into the mic and it tells you what note you are playing. It pretty much works, but I am getting strange readings. When nothing is being played, the mic is even muted, I get a reading of either 50 or 125 Hz. These values also pop up a lot when I am playing the guitar into it. I can't think where these phantom sounds are coming from and was wondering if anyone had an idea.
Cheers
|
|
|
|
|
A/D are notorious for bad readings and the right combination of filters usually helps.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
The 50Hz is likely the mains frequency you are picking up somehow; I am not sure about
the 125Hz, are you using a CRT display?
try turning off everything you don't need, switch to a battery-powered notebook (no mains,
no CRT), go outside if possible, doing so you might be able to pinpoint the ghosts
that haunt you.
I guess your audio input is using some automatic volume control; if at all possible you
may want to switch it off or reduce its range (i.e. set a minimum required level).
BTW: I would not blame C# for this.
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Cosmic background microwave radiation, from the Big Bang.
xacc.ideIronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Hertz was not even born then, was he?
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Was meant to be a joke
xacc.ideIronScheme a R5RS-compliant Scheme on the DLR
The rule of three: "The first time you notice something that might repeat, don't generalize it. The second time the situation occurs, develop in a similar fashion -- possibly even copy/paste -- but don't generalize yet. On the third time, look to generalize the approach."
|
|
|
|
|
Maybe I figured that
Luc Pattyn [Forum Guidelines] [My Articles]
this months tips:
- 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 PRE tags to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Well I got the joke. Good one too!
BDF
|
|
|
|
|
Hi,
I am trying to install a windows application using clickonce.
The application can be installed on several machines successfully but NOT on one machine.
It gives an error on .manifest file not being able to be downloaded. It seems to be looking at the C drive.
If it makes any difference I have included it below.
PLATFORM VERSION INFO
Windows : 5.1.2600.131072 (Win32NT)
Common Language Runtime : 2.0.50727.190
System.Deployment.dll : 2.0.50727.42 (RTM.050727-4200)
mscorwks.dll : 2.0.50727.190 (QFE.050727-1900)
dfdll.dll : 2.0.50727.42 (RTM.050727-4200)
dfshim.dll : 2.0.50727.42 (RTM.050727-4200)
SOURCES
Deployment url : file:///C:/Documents%20and%20Settings/nguyent/Desktop/PricingAnalytics.application
IDENTITIES
Deployment Identity : PricingAnalytics.application, Version=1.0.0.11, Culture=neutral, PublicKeyToken=345994c31edbcaf8, processorArchitecture=msil
APPLICATION SUMMARY
* Installable application.
ERROR SUMMARY
Below is a summary of the errors, details of these errors are listed later in the log.
* Activation of C:\Documents and Settings\nguyent\Desktop\PricingAnalytics.application resulted in exception. Following failure messages were detected:
+ Downloading file:///C:/Documents and Settings/nguyent/Desktop/PricingAnalytics_1_0_0_11/PricingAnalytics.exe.manifest did not succeed.
+ Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
+ Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
+ Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
COMPONENT STORE TRANSACTION FAILURE SUMMARY
No transaction error was detected.
WARNINGS
There were no warnings during this operation.
OPERATION PROGRESS STATUS
* [29/11/2007 15:51:51] : Activation of C:\Documents and Settings\nguyent\Desktop\PricingAnalytics.application has started.
* [29/11/2007 15:51:51] : Processing of deployment manifest has successfully completed.
* [29/11/2007 15:51:51] : Installation of the application has started.
ERROR DETAILS
Following errors were detected during this operation.
* [29/11/2007 15:51:51] System.Deployment.Application.DeploymentDownloadException (Unknown subtype)
- Downloading file:///C:/Documents and Settings/nguyent/Desktop/PricingAnalytics_1_0_0_11/PricingAnalytics.exe.manifest did not succeed.
- Source: System.Deployment
- Stack trace:
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
at System.Deployment.Application.SystemNetDownloader.DownloadAllFiles()
at System.Deployment.Application.FileDownloader.Download(SubscriptionState subState)
at System.Deployment.Application.DownloadManager.DownloadManifestAsRawFile(Uri& sourceUri, String targetPath, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
at System.Deployment.Application.DownloadManager.DownloadApplicationManifest(AssemblyManifest deploymentManifest, String targetDir, Uri deploymentUri, IDownloadNotification notification, DownloadOptions options, Uri& appSourceUri, String& appManifestPath)
at System.Deployment.Application.ApplicationActivator.DownloadApplication(SubscriptionState subState, ActivationDescription actDesc, Int64 transactionId, TempDirectory& downloadTemp)
at System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState subState, ActivationDescription actDesc)
at System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut)
at System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
--- Inner Exception ---
System.Net.WebException
- Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
- Source: System
- Stack trace:
at System.Net.FileWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.FileWebRequest.GetResponse()
at System.Deployment.Application.SystemNetDownloader.DownloadSingleFile(DownloadQueueItem next)
--- Inner Exception ---
System.Net.WebException
- Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
- Source: System
- Stack trace:
at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
at System.Net.FileWebRequest.WrappedGetResponseCallback(Object state)
--- Inner Exception ---
System.IO.DirectoryNotFoundException
- Could not find a part of the path 'C:\Documents and Settings\nguyent\Desktop\PricingAnalytics_1_0_0_11\PricingAnalytics.exe.manifest'.
- Source: mscorlib
- Stack trace:
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync)
at System.Net.FileWebStream..ctor(FileWebRequest request, String path, FileMode mode, FileAccess access, FileShare sharing, Int32 length, Boolean async)
at System.Net.FileWebResponse..ctor(FileWebRequest request, Uri uri, FileAccess access, Boolean asyncHint)
COMPONENT STORE TRANSACTION DETAILS
No transaction information is available.
|
|
|
|
|
Does anyone know if LINQ to SQL lets you map interface types to tables? I want to dynamically generate my classes at runtime, and the mapping scheme only seems to work with a statically-compiled class heirarchy. Has anyone had any luck with this?
|
|
|
|
|