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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:15:07+00:00 2026-06-11T16:15:07+00:00

I have a generic model: public abstract class MyModel<T> where T: MyBase, new() {

  • 0

I have a generic model:

public abstract class MyModel<T> 
    where T: MyBase, new()
{ ... }

and I have a specific model, where Foo inherits from MyBase:

public class MySpecificModel : MyModel<Foo>
{ ... }

and in my Razor template, I want to instantiate an instance of MySpecificModel:

@{
    var test = new MySpecificModel();
}

If MyBase inherits from System.Windows.DependencyObject (because it happens to be a WPF ViewModel class that I need to reuse) I get an exception when the Razor template is compiled saying that I’m missing a reference to WindowsBase.dll, even though I have that reference in my project. I tried adding @using System.Windows to my template, but Razor won’t recognize the namespace at all.

To work around this issue, I changed the code as follows:

public abstract class MyModel 
{
    protected abstract MyBase myBase { get; }
    ... 
}

public class MySpecificModel : MyModel
{
    private Foo _myBase;
    protected override MyBase myBase
    {
        get
        {
            if (_myBase == null)
                _myBase = new Foo();
            return _myBase;
        }
    }
    ... 
}

Inside of MyModel I have to change any “new T()” to “myBase” in order to access the Foo object. This approach works perfectly, but it’s a lot more work for the MySpecificModel class, which I’m going to have many variations of for different sub-classes of MyBase.

So, why does the first approach fail while the second succeeds? It’s not just the use of generics, because if MyBase doesn’t inherit from a WindowsBase class there’s no problem. I think it has to do with where the Foo object is being constructed, and something Razor is doing to prevent the use of any WPF classes. But I can’t find any documentation about that.

  • 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-06-11T16:15:08+00:00Added an answer on June 11, 2026 at 4:15 pm

    ASP.NET generates a new anonymous assembly from the .aspx/.ascx/.master/.cshtml files that then references your web application’s assembly, the generated classes are stored in the ASP. namespace. This assembly is generated at runtime when the first request is made to your web application.

    This new assembly only additionally references a few other assemblies (System.Web.dll, etc) and not the System.Windows.xxx assemblies as you noticed.

    Because ASP.NET is generating a new assembly based on exposed types from System.Windows it needs to reference that assembly directly, which it won’t – whereas when it works with types that children of types derived from System.Windows types (i.e. your working example) it works because it isn’t interfacing with System.Windows directly.

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

Sidebar

Related Questions

I have an abstract generic view-model that I use as a base-class for several
I have the following model structure: class Container(models.Model): pass class Generic(models.Model): name = models.CharacterField(unique=True)
I have a model class similar to the following: using System; using System.Collections.Generic; using
I have generic type that looks like: public class GenericClass<T, U> where T :
using System; using System.Collections.Generic; using System.Linq; using NUnit.Framework; namespace UnitTest.Model { [TestFixture] public class
I have the following class in my model: public class Notebook : TableServiceEntity {
I have the following Model: public class Person { public string Name {get;set;} public
This is my scenario. I have a generic class: public class Tuple<T> extends ArrayList<T>
Lets imaging the we have model: public class InheritModel { public int Id {
For simplicity's sake, lets say I have the following Abstract Base Controller Class: public

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.