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 6892861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:35:14+00:00 2026-05-27T06:35:14+00:00

in my Silverlight 4 application I started creating and using some generics and now

  • 0

in my Silverlight 4 application I started creating and using some generics and now I stumbled upon the following problem:

In a non-generic class, I have a abstract method, that returns a generic class:

public abstract class DTO_Base()
{
  public abstract ServiceModelBase<ServiceNodeBase> CreateBusinessObject();
}

The generic class is defined in the following way:

public abstract class ServiceModelBase<RootNodeType> where RootNodeType : ServiceNodeBase

Naturally, from DTO_Base derived classes will have to override the CreateBusinessObject method:

public class DTO_Editor : DTO_Base
{
  public override ServiceModelBase<ServiceNodeBase> CreateBusinessObject()
  {
    // the object to return have to be of type ServiceModelEditor
    // which is derived from ServiceModelBase<ServiceNodeEditor>
    // public class ServiceModelEditor : ServiceModelBase<ServiceNodeEditor>

    // ServiceNodeEditor is derived from ServiceNodeBase
    // public class ServiceNodeEditor : ServiceNodeBase
    ServiceModelEditor target = new ServiceModelEditor()

    ...
    Functions to populate the 'target'
    ...

    return target;
  }
}

The line return target; causes an error, stating that it isn’t possible to implicitly convert the type ServiceModelEditor in ServiceModelBase<ServiceNodeBase>. Also, an explicit conversion via target as ServiceModelBase<ServiceNodeBase> doesn’t work.

How would I have to implement this method to work?

  • 1 1 Answer
  • 0 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-27T06:35:14+00:00Added an answer on May 27, 2026 at 6:35 am

    Try this:

    public interface IDTO<Node> where Node : ServiceNodeBase
    {
        ServiceModelBase<Node> CreateBusinessObject();
    }
    public abstract class DTO_Base<Model,Node> : IDTO<Node>
        where Model : ServiceModelBase<Node>
        where Node : ServiceNodeBase
    {
        public abstract Model CreateBusinessObject();
    
    
        #region IDTO<Node> Members
    
        ServiceModelBase<Node> IDTO<Node>.CreateBusinessObject()
        {
            return CreateBusinessObject();
        }
    
        #endregion
    }
    
    public class DTO_Editor : DTO_Base<ServiceModelEditor, ServiceNodeEditor>
    {
    
        public override ServiceModelEditor CreateBusinessObject()
        {
            // the object to return have to be of type ServiceModelEditor
            // which is derived from ServiceModelBase<ServiceNodeEditor>
            // public class ServiceModelEditor : ServiceModelBase<ServiceNodeEditor>
    
            // ServiceNodeEditor is derived from ServiceNodeBase
            // public class ServiceNodeEditor : ServiceNodeBase
            ServiceModelEditor target = new ServiceModelEditor();
    
    
            return target;
    
        }
    }
    

    I have faced a similar problem before and the only thing reasonable to do is to make the core base class generic also. You can remove the Model generic parameter (and the interface) and it will look a little less scary, but you loose visibility on the functionality of ServiceModelEditor outside of the method.

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

Sidebar

Related Questions

I am currently developing a silverlight application, however yesterday I started getting the following
Some background information: I am creating a Silverlight WCF RIA Services Project. I started
I started developing an application in Silverlight that was dealing with downloading the HTML
I have a Silverlight application that is built from a set of Silverlight class
I started a Silverlight 4 RIA Services application with the Navigation Application template, instead
I've been working in silverlight to do a date-oriented application. I started off with
I'm getting started with Silverlight. When creating a new solution I have the option
I have an asp.net MVC project hosting a silverlight application. I just started rebuilding
I have made a Silverlight application that can be started with deep links. My
Our Silverlight Application can run in both http and https (SSL, using Transport Security)

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.