Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 455325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:21:34+00:00 2026-05-12T22:21:34+00:00

Again disclaimer disclaimer still learning C# and OOP generally so I hope you’ll be

  • 0

Again disclaimer disclaimer still learning C# and OOP generally so I hope you’ll be patient with me 🙂

I am currently working with a CMS that has a class called FileVersion which basically contains a list of properties pertaining to a file such as filename, filetype, size in bytes, id, date uploaded, is-latest-version, etc.

A list of FileVersions is contained within a File which has it’s own unique ID. When you want to download a particular file from the CMS, the URL is built using something like the following:

string URL = "/files/"+file.id.toString()+"/"+file.fileVersion.Last().filename;

Now for a particular control I’m working on (dealing specifically with files that are documents), it makes sense to be able to store the URL along with all the other FileVersion information for later use. So what I’ve decided to do is create my own class called DocumentVersion which extends FileVersion. This is what it looks like:

public partial class DocumentVersion : FileVersion
{
    public DocumentVersion() : base() { }
    public string link;
}

Now I should note, that it appears that I don’t need to implement an interface here – but don’t take that as gospel, that’s why I’m here.

However when I try to cast my FileVersion as a DocumentVersion like so:

DocumentVersion dv = ((DocumentVersion)fileversion);

I get the following exception:

Unable to cast object of type
‘Foo.CMS.FileVersion’ to type
‘CoA.DocumentVersion’.

My inkling is that it’s because I’m trying to extend a class in a different namespace from where the original resides, but like I said, OOP is relatively new to me so I could be wrong.

Thanks in advance for your help. This community has been so valuable! I just hope once I’m more skilled up I can give some back :).

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:21:34+00:00Added an answer on May 12, 2026 at 10:21 pm

    Are you trying to downcast ? i.e. take an existing FileVersion and declare it to be a DocumentVersion ?

    If so, you can’t do that, since what you have is nothing more than a FileVersion.

    Instead you need to create a new DocumentVersion object. Your DocumentVersion constructor will take the arguments required for a FileVersion and then call the FileVersion constructor via base().

    Note that if you have an existing FileVersion object, you may want an object to wrap this, rather than have an object deriving from it. e.g. your DocumentVersion wouldn’t derive from FileVersion, but contain a private reference to a FileVersion, plus additional data as required. That may be more appropriate in this scenario.

    e.g. (in OO terms this is composition)

    public class DocumentVersion {
       private FileVersion fv;
       private String url;
       public DocumentVersion(FileVersion fv, String url) {
          this.fv = fv;
          this.url = url;
       }
    }
    

    See here for more info on composition.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: I am a layperson currently learning to program. Never been part of a
Again, I saw this sentence: A .classpath file snippet that can be included in
Again with the soap. I am trying to build a header using soap4r that
Again I'm moving from Xcode 3 to 4 and finding that some things are
Hello again, stackoverflow community! I'm working on writing a simple blog system in Rails,
Again i see that the @PostConstruct is firing every time even though no binding
Again I m sry fr that non-sense way of asking the question what i
Again a simple thing. I have a stylesheet that parses XML and XSL files.
Again I apologize for a question that might be simple to all of you.
Disclaimer again: I'm a Clojure newbie. Thanks for the help. My previous question (

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.