I have created a widows application with setup project. I compiled and build.Everything looks fine.
For changing the configuration file during installation am trying to add a new Installer file. when i add it by default i get the below code
Collapse | Copy Code
[RunInstaller(true)]
public partial class Installer : Installer
{
public Installer()
{
InitializeComponent();
}
}
When i compile this Am gettin
Circular base class dependency involving 'windows_setup.Installer' and 'windows_setup.Installer'
windows setup is the name space i used for the application. Then i found that i need to create the new classs which inbherits Installer.So i changed my class name to
public partial class MyInstaller : Installer
Now am Getting
Inconsistent accessibility: base class 'windows_setup.Installer' is less accessible than class 'windows_setup.MyInstaller'
Suggest your ideas.
Thanks
Well, you can't have a public class inheriting from an internal class for example. Try to set everything as internal if not required outside, or public otherwise.
Either change class Installer and MyInstaller to public.
Write Something like this:
System.Configuration.Install.Installer and class definition should be public partial
[RunInstaller(true)]
public partial class MyInstaller : System.Configuration.Install.Installer
{
public MyInstaller()
{
InitializeComponent();
}
}
Related
I following this answer
My auto generated file has this code for dbContext:
public partial class TrafficEngineEntities : DbContext
{
public TrafficEngineEntities()
: base("name=TrafficEngineEntities")
{
}
I can modify the file to add the additional method with the string parameter:
public partial class TrafficEngineEntities : DbContext
{
public TrafficEngineEntities()
: base("name=TrafficEngineEntities")
{
}
public TrafficEngineEntities(string connectionString)
: base("name=TrafficEngineEntities")
{
}
But if I try only write the part to add the additional method in a separated file (to avoid overwrite in case updates), then visual studio said my db tables class aren't part of the dbcontext, like I overwrite everything in the partial class.
public partial class TrafficEngineEntities : DbContext
{
public TrafficEngineEntities(string connectionString)
: base("name=TrafficEngineEntities")
{
}
}
The problem here is that your manually created TrafficEngineEntities partial class and auto generated TrafficEngineEntities are in different namespaces. So, in fact these are 2 different classes.
Typically, you have namespaces in your solution in align with your solution folders. Auto generated files may not respect this convention or you may accidentally create your manually created partial class in the different folder.
Make your manual class namespace same as in auto generated class and it should solve the problem.
You may suffix your files like TrafficEngineEntities.AutoGenerated.cs and TrafficEngineEntities.Patrial.cs so, you can clear see the difference between auto generated and manually edited files.
So recently; I refactored Views to their own WPF Application project and I moved my ViewModel classes into their own Class Library project. This worked well for keeping my code in order. Then I realised that I didn't have the comfort of the App.xaml.cs class.
This class (for me) meant that I could declare all sorts of objects and access them application wide.
i.e: In the App.xaml.cs
public partial class App : Application
{
public myDatabaseEntities context { get; set; }
// App.xaml.cs Constructor
public App()
{
context = new myDatabaseEntities();
}
}
In some random View Model:
myDatabaseEntities context = ((App)Application.Current).context;
The above allows me to recylce the instance, and comes in particularly handy with Unity's (IoC container) version of lifetime manager.
Thing is, I'm not sure on how to achieve this behaviour within a class Library project. I'm not sure how to create a class that instantiates at runtime. And I have no clue how to pass that App class instance around to relevant classes. Any ideas on how to do this? Any help would be much appreciated.
Personally, I would keep all the "functionally" related Views and ViewModels together (next to each other). You may want to create class libraries (or modules) based for different functional parts of the application. Also, please refer to this MSDN page on building composite application using WPF and Prism.
Coming to your question, have an interface called IApplication defined something like this:
public interface IApplication
{
MyDatabaseEntities Context { get; }
}
and implement that interface on App class:
public partial class App : Application, IApplication
{
public MyDatabaseEntities Context { get; set; }
// App.xaml.cs Constructor
public App()
{
Context = new MyDatabaseEntities();
}
}
In your App.xaml.cs, as part of bootstrapping your application register this App instance with the container by calling RegisterInstance extension method on Unity container:
Container.RegisterInstance(typeof (IApplication), this, new ContainerControlledLifetimeManager());
Now, if your ViewModels take a dependency on IApplication, then they will have access to your App object and to the Context property via this interface. In future you could expose additional properties like: Dispatcher, Resources, etc from your App object through this interface.
Turns out all I needed was a regular class without the xaml front end. Then inherit the Application class. And lastly set it as the base class for app.xaml.cs. The answer is already here
I'm using a public LoginContext class to manage user logins in my web app.
Unfortunately, even though I have the LoginContext class declared publicly, my partial class Login at Login.aspx.cs can't seem to access it.
My code is as follows:
// ~/App_Code/LoginContext.cs
namespace stman
{
public class LoginContext
{
}
}
// ~/Login.aspx.cs
namespace stman
{
public partial class Login : System.Web.UI.Page
{
protected void btnLogin_Click(object sender, EventArgs e)
{
LoginContext log = new LoginContext(); // error is here
}
}
}
The error that comes up on the line where I instantiate LoginContext reads as follows:
The type or namespace name 'LoginContext' could not be found (are you missing a using directive or an assembly reference?)
When I try to generate a new class for LoginContext, it goes into the web app's root folder where it can no longer access the public Database class that I need in LoginContext.
I have no idea what's causing all of these problems, but based on what I've learned over the last 18 months doing this professionally, they shouldn't exist right now...
Can anyone help clear things up here? Specifically I'd like to know:
What I'm doing wrong
Why it's wrong
Who can I fix it?
Thanks in advance!
EDIT
I've had a look and it seems neither the Database class in ~/App_Code/Database.cs or the LoginContext class in ~/App_Code/LoginContext.cs are accessible to the page - or any page in the website.
In LoginContext.cs properties, marked it as BuildAction = Compile.
You can achieve this behaviour when these classes are located in different projects.
If this is true then you should use full path to the class starting from the project name
ProjectName.stman.LoginContext
try using constructor
namespace stman
{
// Database is a class that handles the sql queries and such
public class LoginContext : Database
{
public LoginContext () : base("Name=LoginContext")
{
}
}
}
From what I read from the App_Code behavior may be different in web site projects and web application. I wonder what kind of project you're working on? One possible solution would be to make this project in web application project, this Link can help you to make this project:
Source
I have written a console application in C# /VS2008. In that I have multiple classes declared without specifying any accessibility modifier. Like
Namespace MyNamespace
{
Class MyClass
{
..
}
}
Now I added a new console application for testing purpose. I added reference to NUnit framework dll. And then a reference to my main project dll. But when I try to create an object of MyClass into my TestFixture class, then I get an error like "MyNamespace.MyClass is inaccessible due to its protection level"
Do I need to create my class as public? But what if my project cannot afford it?
The class needs to be public if you want it to be accessible from another assembly:
namespace MyNamespace
{
public class MyClass
{
}
}
If your project cannot afford it you may take a look at [InternalsVisibleTo] attribute.
I have a generic abstract UserControl class, SensorControl, which I want all my sensor control panels to inherit from.
The problem
When attempting to design the EthernetSensorControl (one of my inherited UserControl forms, from within Visual Studio, the following error is displayed in the form designer:
The designer could not be shown for this file because none of the classes within it can be designed. The designer inspected the following classes in the file: DeviceSensorControl --- The base class 'Engine.Sensors.SensorControl' could not be loaded. Ensure the assembly has been referenced and that all projects have been built.
SensorControl class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Engine.Sensors
{
public abstract class SensorControl<SensorType>
: UserControl where SensorType : class
{
protected SensorType _sensor;
public SensorControl(SensorType sensor)
{
_sensor = sensor;
}
}
}
Example inherited class, EthernetSensorControl:
namespace Engine.Sensors
{
public partial class EthernetSensorControl
: SensorControl<EthernetSensor>
{
public EthernetSensorControl(EthernetSensor sensor)
: base(sensor)
{
}
}
}
And the call stack:
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.EnsureDocument(IDesignerSerializationManager manager)
at System.ComponentModel.Design.Serialization.CodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager manager)
at Microsoft.VisualStudio.Design.Serialization.CodeDom.VSCodeDomDesignerLoader.PerformLoad(IDesignerSerializationManager serializationManager)
at System.ComponentModel.Design.Serialization.BasicDesignerLoader.BeginLoad(IDesignerLoaderHost host)
Everything compiles and I can see the panel displayed, but I can't design it. I think the problem may be related to the partial classes. Any ideas?
You cannot design a control or form that inherits an abstract class.
(The designer needs to instantiate the base class to serve as the design surface)
The base class also needs to have a parameterless constructor for the designer to call.
This constructor can be private.