Friday, April 29, 2011

A project with output type of class library cannot be started directly - with a startup exe

Firstly I'm completely aware of this message and why it happens normally. It's not that I'm just trying to run a dll (like this question).

I have a project that compiles to a dll but has a startup program specified in the project properties. Most of the time I'm able to right-click on the project and select Debug > Start new instance, and it will run the program and let me debug my dll. However, occasionally I get this message (A project with output type of class library cannot be started directly) as if I haven't got a startup program. The first few times I thought it was just me accidentally clicking on the wrong project but I'm certain this isn't the case given that it's happened so many times and I've been careful to watch it.

When this message appears I'm able to try it again and it always works on the second or third attempt.

A colleague using the same Solution never has this problem :-/

Anyone else had this problem or know how to solve it?

I'm using Visual Studio 2005 Pro Version 8.0.50727.762 (SP.050727-7600)

From stackoverflow
  • This sounds like a transient Visual Studio problem. Reinstallation or upgrade may solve your problem.

  • Typically problems in VS are caused by:

    • Add-ins: Run VS without and see if the problems is solved
    • Corrupted files in your solution: Delete / rename all files created by Visual Studio which are not part of your project, i.e. all .suo, .ncb files and a like.
    Pedro : +1 for the deletion of the .suo file. That often fixes problems for me (especially with breakpoints that disappear or reappear for no reason.)
  • I had this problem with projects that were created as "Windows Control Library" that somehow forget their status. Unloading and reloading the project usually did the trick.

    If it was created as a "Class Library" then to make it a "Windows Control Library" I manually add the following to the .csproj file. It was the only difference I could see between a class library and windows control library project.

    BTW - starting a Windows Control Library starts the User Control Test Container - allows you to test any user control in the library. Very cool.

    <Service Include="{94E38DFF-614B-4cbd-B67C-F211BB35CE8B}" />
    

    add that inside of an <itemgroup> element.

  • no just make a start up project

  • Another colleague suggested it's because after clicking Debug > Start new instance, while I'm waiting for it to start up, I click on a different project. I don't do it for any reason, just randomly selecting things as I wait for the project to start up. Maybe Visual Studio looks at the selected project sometime after I clicked the menu, gets confused, and shows the error message?

    Anyone able to confirm this matches their experience?

Mix XML Parents and Children in MSSQL

I think what I need is CROSS APPLY, but I can't seem to figure out the syntax. I have a set of XML in an MSSQL 2008 database that looks like this:

<Cookie>
   <id>Chocolate Chip</id>
   <ChocolateChipPeanutButter>
      ...
   </ChocolateChipPeanutButter>

   <ChocolateChipPecan>
      ...
   </ChocolateChipPecan>
</Cookie>

<Cookie>
   <id>Raisin</id>
</Cookie>

<Cookie>
   <id>Coconut</id>
</Cookie>

<Cookie>
   <id>Sugar</id>
</Cookie>

I'm trying to chop the XML up so that I have a result set that looks like this:

Cookie Name                   Cookie SubName
___________                   ______________
Chocolate Chip                <null>
Chocolate Chip                ChocolateChipPeanutButter
Chocolate Chip                ChocolateChipPecan
Raisin                        <null>
Coconut                       <null>
Sugar                         <null>

I think I need to write something like this (assume the XML data is stored in DECLARE @XMLData XML :

SELECT
     TheXML.TheCookie.query('data(./id)')     AS CookieName
   , TheXML.TheCookie.query('.')              AS CookieData
   , Sub.SubCookieName                        AS SubCookieName
FROM
   @XMLData.nodes('//Cookie') AS TheXML(TheCookie)
CROSS APPLY
   (
       SELECT
          TheCookieXML.SubCookieName.query('local-name(.)')
       FROM
          CookieData.nodes('./*') AS TheCookieXML(SubCookieName)
   )

I know, I know, this XML schema is terrible for what I'm trying to do with it, but lets assume that we're stuck with the data this way and work from there. Am I on the right track? Will CROSS APPLY ever work like this? Can even Batman save me now?

From stackoverflow
  • Try something like this:

    SELECT
         TheXML.TheCookie.value('(id[1])', 'varchar(20)') AS CookieName
       , TheXML.TheCookie.query('.') AS CookieData
       , Sub.SubCookie.value('local-name(.)', 'varchar(20)') AS SubCookieName
    FROM
       @xmlcon.nodes('//Cookie') AS TheXML(TheCookie)
    CROSS APPLY
        TheXML.TheCookie.nodes('./*') as Sub(SubCookie)
    

    Trouble is - this also selects the "id" node :-(

    Marc

    Tomalak : TheXML.TheCookie.nodes('./*[local-name() != 'id']) as Sub(SubCookie)
    brian : perfect, thanks guys!
    Tomalak : Third attempt of a comment... The above contains some single quote glitches, nothing serious. Alternative, simpler XPath: TheXML.TheCookie.nodes('./*[not(self::id)]')
    marc_s : Excellent comment, Tomalak! Thanks - nice technique for excluding nodes!
    brian : Tomalak, that XPATH was very helpful, I wish you could get rep from votes on comments.
    Tomalak : @brian: Glad to help. Virtual rep is also accepted. :-D
    Tomalak : @marc_s: Oh, I nearly forgot. +1 for the answer.

Apply Multiple CSS classes on an HTML element (jQuery addClass)

Given this HTML:

<html>
<head>
  <style type="text/css">
    tr.Class1
    {
      background-color: Blue;
    }
    .Class2
    {
      background-color: Red;
    }
  </style>
</head>
<body>
  <table>
    <tr id="tr1">
      <td>Row 1</td>
    </tr>
    <tr id="tr2">
      <td>Row 2</td>
    </tr>
  </table>
</body>
</html>

Below is the script secion. What will happen when I click on the first row? Will it remain blue, or will it turn red? If it will remain blue, how do I get it to turn red instead WITHOUT removing the Class1 class from the row (so I can remove the Class2 class later and the row will return to its original color of blue)?

<script type="text/javascript" language="javascript">

  $(document).ready(function() {
    $("#tr1").addClass("Class1");

    $("tr").click(function() {
      /* clicked tr's should use the Class2 class to indicate selection, but only one should be selected at a time */

      $(".Class2").removeClass("Class2");
      $(this).addClass("Class2");
    });
  });

</script>

Edit I should say - I tried this, and it's not working as expected (in either FireFox or IE). What is going on?

From stackoverflow
  • It should turn red...that's why it's called cascading style sheets...new additions to the properties override older ones.

    Brandon Montgomery : I know, but I'm not getting that behavior.
  • Mozilla says here:

    If the same property is declared in both rules, the conflict is resolved first through specificity, then according to the order of the CSS declarations. The order of classes in the class attribute is not relevant.

    But this isn't the behavior I'm getting.

  • try this:

     $("tr").click(function() {
      /* clicked tr's should use the Class2 class to indicate selection, but only one  should be selected at a time */
    
      $(".Class2").removeClass("Class2");
      $(this).toggleClass("Class1");
      $(this).addClass("Class2");
      $(this).toggleClass("Class1");
    });
    

    I don't know if it will work but maybe it will give you more into the problem.

  • Figured it out. I put my example up a little incorrectly. The CSS actually looked like:

    tr.Class1
    {
      background-color: Blue;
    }
    .Class2
    {
      background-color: Red;
    }
    

    Therefore, the most specific rule applies, just like Mozilla told me here:

    If the same property is declared in both rules, the conflict is resolved first through specificity, then according to the order of the CSS declarations. The order of classes in the class attribute is not relevant.

oracle jdbc driver version madness

Why the heck does Oracle offer a different(!) version of the JDBC driver, e.g. ojdbc14.jar, for every(!) database version?
The files all have different sizes and thus probably different content.

background:
We get a random and seemingly irreproducible error saying "invalid number" when saving data (we guess it's the Timestamp). But it's not any particular statement. Most of the time, it saves just fine. Just once a month a harmless looking statement will fail.

So i had a closer look at Oracle's download site and noticed that none of the filesizes match despite files sharing the same name.

Our product is run on databases maintained by our clients, i.e. whatever version and patch the clients have running is what it is.
So what driver do we use? The latest (Oracle 11g) - despite the fact that it's usually 9i and 10g databases?

Why don't they just link all versions to the same "one driver suits all" file?
Or are there minute differences leading to effects like our random errors?

EDIT: i was mistaken about the 9i databases.

From stackoverflow
  • please see the compatibility matrix at http://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html#02_02

    Also take in mind that the timestamp datatype is only available since Oracle 10.

    Stroboskop : These drivers "can talk to" just about any modern database version. So you're saying i just pick the newest release and keep my fingers crossed that it has all the bug fixes i need? ... and i was wrong about the 9i's. We retired them last year.
    Oliver Michels : well, i doubt it is a bug in the jdbc driver. i would inspect the code for number casting bugs, "number to string", "string to date" and so on. Are we talking about ORA-01722, invalid number? If so, i would check the debugging logs and not care about driver version conflicts.
    Stroboskop : Yes, it's ORA-01722. We use PreparedStatements, meaning the type conversions are all done by the driver. And the same statement works fine 99.9% of the time. We of course looked at our code first, but there seems to be nothing out of the ordinary.
  • When we upgraded our Oracle database from 8.1.7 to 10.2.0, I was able to use the same Oracle jdbc driver (ojdbc14.jar). So their jdbc driver supports quite a few versions at the same time. Of course it's possible that some of the drivers are buggy, but the plan is to support more versions at the same time.

issue of virtual method in C#

Hello everyone,

In MSDN, it is mentioned,

http://msdn.microsoft.com/en-us/library/9fkccyh4(VS.80).aspx

I am confused what does this item mean "A virtual inherited property can be overridden in a derived class by including a property declaration that uses the override modifier."?

(this is the 2nd differences between virtual and abstract)

thanks in advance, George

From stackoverflow
  • Can you explain what's confusing about it? Properties can be overridden like any other method.

    public class Base {
      public virtual int Prop1 { get { ... } set { ... } }
    }
    
    public class Derived : Base {
      public override int Prop1 { get { ... } set { ... } }
    
    George2 : My confusion is not overridden property, but why it is a differences between abstract and virtual -- ""A virtual inherited property can be overridden in a derived class by including a property declaration that uses the override modifier."? Please see the context of MSDN I quoted.
    Tor Haugen : Abstract members have no implementation, and so _must_ be overridden. Virtual members have an implementation, and _may_ be overridden. That's the difference.
    George2 : Understand, MSDN words are so fuzzy. :-)
    Coincoin : I don't think this is what the doc meant, or if it did, it's a very bad choice of words. Still, it's the best explanation. The writer was probably just past the Ballmer peak. Yay MSDN!
  • If you declare a method virtual in your base class you can override it in your derived class.

    Example

    class MyBaseClass
    {
       public virtual void MyOverridableMethod()
       {
              ...
       }
    
    }
    
    class MyDerivedClass : MyBaseClass
    {
       public override void MyOverridableMethod()
       {
             ...
       }
    }
    

    Notice the override modifier in MyDerivedClass.

    George2 : My confusion is what is the differences between abstract and virtual in the quoted words -- " virtual inherited property can be overridden in a derived class by including a property declaration that uses the override modifier"?
  • The only difference between virtual and abstract, is that an abstract method or propery has no implementation in the class where it has been defined (the abstract class), and that it must be overriden in a subclass; whereas a virtual method or property has an implementation in the class where it has been defined, and so it is not mandatory to override it in a subclass.

    public abstract AbstractClass { // This class cannot be instantiated, since it is // abstract, and the class is abstract because // it has an abstract member

    public abstract MyProperty {get; set; }
    

    }

    In a class where you derive from AbstractClass (the above AbstractClass is just for explanation purposes; since it has no methods / properies that have an implementation, you could create an interface instead of an abstract class), you will have to provide an implementation of MyProperty. Otherwise, it won't compile. You do this by 'overriding' the MyProperty, you don't want to introduce a new member, but just provide an implementation for a property that has been defined previously.

    public class ConcreteClass : AbstractClass
    {
        public override MyProperty {
           get
           {
                return _someValue;
           }
           set
           {
                if( _someValue != value ) _someValue = value;
           }
    }
    
    George2 : So, you think MSDN means, for abstract base class, it is "must", but for non-abstract base class, it is "can" (not a must)?
    Frederik Gheysels : It is defenitly a must; try to inherit from an abstract class, and don't override an abstract method or property; the compiler will complain.
  • Okay, let's say you have a base class, and that that base class is, itself, derived from another class.

    public class Bar : Foo
    {
       virtual public int SomeProperty { get; set; }
    }
    

    What the virtual keyword means is that in a class derived from Bar, you can override SomeProperty to change its behavior:

    public class Baz : Bar
    {
       private int thisInt;
       override public int SomeProperty 
       {
          get { return thisInt; }
          set 
          {
             if(value < 0)
             {
                throw new ArgumentException("Value must be greater than or equal to zero.");
             }
             thisInt = 0;
          }
       }
    }
    

    Clarification: When an object of type Baz is used, its version of SomeProperty is invoked, unless the type is cast to Bar. If you define Baz's SomeProperty as virtual, classes derived from Baz can also override it (in fact, that may be required--can't recall right off the top of my head).

    Further Clarification: An abstract method has no implementation; when you add one to your class, you must also mark the class as abstract, and you cannot instantiate new instances of it, like this:

    MyAbstractType m = new MyAbstractType();
    

    Virtual members, on the other hand, can have an implementation (like SomeProperty, above), so you don't have to mark the class abstract, and you can instantiate them.

    George2 : Thanks Mike, you answered well but not what I am asking. My question is answered by Tor Haugen, and you can refer there. It is my fault that I do not make myself understood.
    Frederik Gheysels : It is not required to override virtual members.
    Mike Hofer : @George: I clarified the answer to accomodate your question. @Frederik: Note that I said that "you can override" a virtual member.
    Frederik Gheysels : @Mike: I was referring to this sentence of yours: In fact, that may be required--can't recall right off the top of my head
    Mike Hofer : @Frederik: Of course, you're right. I think I was trying to say something else. Way too early in the morning at that time, and I have no idea why I was trying to write that before enough coffee. :) Thanks for the clarification.
    Mike Hofer : Would someone care to explain the downvote? If I'm wrong, please point out where, and enlighten me. I'd rather learn than be left in the dark. Seriously.
  • I can understand the confusion. I have been there before, so I'll share how I keep the basic differences straight...

    virtual vs. abstract:

    • If a class method (or property) is marked virtual, then it may be overridden using the override keyword, if you choose to inherit (aka derive) from that class.

      The virtual keyword is intended to evoke the idea that the method may or may not be the actual method called. Therefore, I always think of virtual members as default implementations, meaning that it represents functionality that can be generalized, such as an Eat() method on a Human class, which might involve eating with one's hands. However, a ChineseHuman class might override the default implementation of Eat(), in order to allow for an implementation that uses chop sticks instead. Finally, because virtual methods and properties are default implementations, the class that defines that member must provide a complete implementation of the method or property. All Human objects must know how to Eat().

      An object-oriented way of thinking might declare that virtual members represent instincts. To Eat() is an instinct of a Human class object. A ChineseHuman may learn to Eat() with chop sticks.

    • If a class method (or property) is marked abstract, then it must be overridden using the override keyword, if you choose to inherit from that class.

      The abstract keyword is intended to evoke the idea that the class only supports the capability represented by the member, and that there is not any common logic that can be generalized for that feature. In other words, abstract members are only conceptual, and therefore they lack an implementation. It is a little confusing that C# asks us to override abstract members when we implement an inheritance relationship, but in this case it really means that we are overriding the empty concept with a concrete implementation. An example of an abstract member of a Human class might be Speak(). There would not be a common way of speaking for all Human objects, nor is it instinctual, because it requires language to express. Note: Some might argue that Speak() belongs on an interface instead.

      An object-oriented way of thinking might declare that abstract members represent behavior (methods) to be learned and knowledge or beliefs (properties) to be acquired. To Speak() is a learned behavior of a Human class object. A ChineseHuman may learn to Speak() differently than an EnglishHuman and neither knows how to Speak() just because they are both Human.

    Nuances:

    • virtual methods do NOT need to be overridden.
    • There is no such thing as a virtual class.
    • abstract members can only appear on abstract classes. In the above examples, having an abstract method on the Human class implies that Human is an abstract class, and that, therefore, a Human cannot be instantiated using the phrase var baby = new Human();. Instead, the BabyHuman class should inherit from Human, and it should be instantiated as var baby = new BabyHuman();. Because a BabyHuman() is a Human and EnglishHuman and ChineseHuman both also inherit from Human, EnglishHuman could inherit from BabyHuman instead of Human. Being Human is abstract because we are all something more than simply Human.
    • abstract members cannot be hidden, only their override implementations may be (further up the inheritance chain). For example, BabyHuman must implement the abstract Speak() method as an override. If EnglishHuman inherits from BabyHuman, it may then hide the BabyHuman implementation of Speak() with its own implementation by using the new keyword (see "Method Hiding in C#" reference below).
    • abstract classes can have virtual members. That's a main distinction between an interface and an abstract class. In that sense, an abstract class can define both a contract and a template of the class' behavior, whereas an interface only defines a contract.

    Code Reference:

Using VBA to parse text in an MS Word document

Hi, I was hoping someone could help with a MS Word Macro.

Basically, I have a MS Word document which lists out several text files and specific pages of interest in each file.

The file format is similar to:

textdocument1.txt              P. 6, 12 - issue1
textdocument2.txt              P. 5 - issue1
                               P. 13, 17 - issue3
textdocument3.txt              P. 10

I want to read each line into my Macro as a string.

Then traverse through it to identify the file name. With the file name, I can then open the file, go to the page number, and copy the data I need.

But I'm stuck at step 1, how do I capture the line into a string in an MS Word Macro?

Any help will be appreciated.

From stackoverflow
  • If your word document lists all the text files like this:

    <name>{tab}<page ref>{newline}
    <name>{tab}<page ref>{newline}
    <name>{tab}<page ref>{newline}
    

    Then all the lines are available in the Paragraphs collection. You can loop through that with a simple For Each loop:

    Dim p As Paragraph
    
    For Each p In ActiveDocument.Paragraphs
      Debug.Print p.Range.Text
    Next p
    
  • The following code should get you started:

    Public Sub ParseLines()
        Dim singleLine As Paragraph
        Dim lineText As String
    
        For Each singleLine In ActiveDocument.Paragraphs
            lineText = singleLine.Range.Text
    
            '// parse the text here...
    
        Next singleLine
    End Sub
    

    I found the basic algorithm in this article.

    Anonymous Type : This will break the document up into paragraphs. If you want sentences do this per line (i.e. sentence) check my answer below.
  • per line

    Public Sub ParseDoc()
    
        Dim doc As Document
        Set doc = ActiveDocument
        Dim paras As Paragraphs
        Set paras = doc.Paragraphs
        Dim para As Paragraph
        Dim sents As Sentences
        Dim sent As Range
        For Each para In paras
    
            Set sents = para.Range.Sentences
            For Each sent In sents
                Debug.Print sent.Text
            Next
    
        Next
    
    End Sub
    

Object Oriented Database Vs object Relational Database

Hi,

I wonder how Object Oriented data modeling is different from Object Relational data modeling?

Is it something like the pluses of both object oriented and relational data modeling were clubbed to achieve object relational data modeling?

cheers

From stackoverflow
  • this might be helpful comparison of RDM and OOM

  • Object-Relational data modeling supports some object-oriented concepts, while still supporting some relational concepts:

    • Inheritance -- one table can have an IS-A relationship with another table. Likewise custom data types support inheritance.
    • Distinction between a class and an object (instance of a class) that goes beyond simply the distinction between a table and a row.
    • Custom or complex data types.
    • Relational query language.
    • Referential integrity.

    Object-Oriented data modeling is just persistence for objects:

    • Greater support for complex objects.
    • No query language -- you just retrieve individual objects like some giant key/value store.
    • No relational referential integrity -- though you may have one object contain a reference to another object.
    Rik : +1: very good answer