I have a fully implemented property with private variable as shown below:
using System;
namespace ClaimMonitorInfo
{
internal class Claims
{
static Claims()
{
new MainModule();
}
private string claimName = string.Empty;
public string ClaimName
{
get
{
return claimName ;
}
set
{
claimName = value;
}
}
}
}
External projects will be setting it but the property never gets set inside its own namespace. So Jenkins thought setter has never been used and gave me a warning message. The constructor of the class is static. How can I assign default values for the property? Need to mention that, project has to be built with MSBuild 12, so C# 6.0 features won't be acceptable. Any help is greatly appreciated.
Sincerely
Related
Solved, see comments!
I have a simple .NET DLL written in c#.
In asp-classic or VB.NET i can create the object and call a member function in the DLL without any problem.
But, and this is my stumbling point, i can't access class properties.
Here's the sample code:
[Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"),
ClassInterface(ClassInterfaceType.None),
ComSourceInterfaces(typeof(IComEvents))]
public class Com : IComInterface
{
public string MyProperty{ get; set; } // <-- NOT ACCESSIBLE
public void MyFunction() // <-- ACCESSIBLE
{
}
}
Here's the server-side script:
Set com = Server.CreateObject("ns.Com") // WORKS
com.MyProperty = "abc" // GIVES ERROR
com.MyFunction // WORKS
I get the following error-message:
Microsoft VBScript Runtime Error "800a01b6'
Object Doesn't Support This Property or Method: MyProperty
Can anybody tell me, why i can call the function 'MyFunciton', but if i want to set the property-value, i get the error above?
Properties must be included in the interface definition to make them visible to COM.
Example:
[Guid("... some GUID ...")]
[ComVisible(true)]
public interface MyClassInterface
{
string MyProperty { get; set; }
bool MyMethod();
}
I'm new to OSGI framework and I'm trying to access the 'Derived' Class variable 'publicVariable' from another class 'Derived2' like "Derived.publicVariable" but publicVariable is always shows null. I really appreciate if someone can help me out with this.
Thanks
Manifest file - Derived2
Require-Bundle:com.xxxxxx.Derived1
Java code
abstract class Base {
protected Vector <String> supportedCommands = new Vector <String> ();
protected abstract void initialiseCommands();
}
class Derived extends Base {
private static Derived derivedPlugin = null;
public Derived()
{
derivedPlugin = this;
}
public static Derived getPlugin()
{
return derivedPlugin;
}
public String publicVariable = null;
protected void initialiseCommands()
{
publicVariable = "someData";
System.out.println("Derived" + publicVariable);
}
}
class Derived2 extends Base {
protected void initialiseCommands()
{
supportedCommands.add(Derived.getPlugin().publicVariable);
System.out.println("IMRSAUtilitiesPlugin" +supportedCommands);
}
Also referred below link, which is a similar issue but i'm not using any static variable, it is just a public variable.
how use Singleton object in different class loader....?
The code in the question will not compile. You are trying to access an instance field (publicVariable in class Derived) in a static way, i.e. Derived.publicVariable.
OSGi does not change the semantics of the Java language, and if you cannot even compile your code then OSGi will certainly not be able to run it.
I know that this is one of the most encountered error but I am really struggling to get around it.
i have a property on my Controller:
private readonly ISelectListFactory _selectFactory;
and a method that called to populate the viewbag
private void PopulateLists()
{
var continent = _selectFactory.GetItems();
}
and the interface
public interface ISelectListFactory
{
IEnumerable<SelectListItem> GetItems();
}
and in the controller constructor I have the following:
public LocationController(ISelectListFactory selectFactory)
{
_selectFactory = selectFactory;
}
but I am getting this error Object reference not set to an instance of an object and not sure how to overcome it.
Regards
Make sure you have instantiated this _selectFactory variable somewhere. Like for example:
_selectFactory = new SomeConcreteSelectListFactory();
or if you are using dependency injection you might configure your DI framework to inject it into the constructor:
public class HomeController: Controller
{
private readonly ISelectListFactory _selectFactory;
public HomeController(ISelectListFactory selectFactory)
{
_selectFactory = selectFactory;
}
... some controller actions where you could use the _selectFactory field
}
I'm trying to get OnDeserializing work with my WCF Proxy by using partial classes, but for some reason the OnDeserializing doesn't get triggered. In OnDeserialing I need to examine whether the web service returned nothing and set my own default value in that case. Everything looks OK in Visual Studio 2010 and I can access the properties of my WCF proxy in the code editor but at run-time OnDeserialing is never called. Can you please advice me what I'm doing wrong? Here's the code:
Proxy class
public partial class SerialInfo : object, System.ComponentModel.INotifyPropertyChanged {
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified, Order=2)]
public string Location {
get {
return this.locationField;
}
set {
this.locationField = value;
this.RaisePropertyChanged("Location");
}
}
}
Extended proxy class
public partial class SerialInfo
{
[OnDeserializing]
void OnDeserializing(StreamingContext c)
{
Location = "Test value";
MessageBox.Show("OnDeserializing was triggered!");
}
}
Try adding brackets to your attribute, and changing the method name
[OnDeserializing()]
void OnDeserializingMethod(StreamingContext c)
{
Location = "Test value";
MessageBox.Show("OnDeserializing was triggered!");
}
EDIT: Also, shouldn't partial classes have identical inheritance? Are you sure your partial class is extending what you think it is?
I have installed Ninject (v4.0.30319) package in test project to test. Create test code below, unfortunately ValidateAbuse.Instance.Repository is always Null. Why Ninject do not bind repository to ValidateAbuse.Repository property?
Some of you may suggest to use constructor binding but I can't use it due to code structure. The below code is just example and I need to find a way to bind to property.
Test method which always fail
[TestMethod]
public void PropertyInjection()
{
using (IKernel kernel = new StandardKernel())
{
kernel.Bind<ISettingsRepository>().To<SettingsRepository>();
Assert.IsNotNull(ValidateAbuse.Instance.Repository);
}
}
The repository interface
public interface ISettingsRepository
{
List<string> GetIpAbuseList();
List<string> GetSourceAbuseList();
}
The repository implementation
public class SettingsRepository : ISettingsRepository
{
public List<string> GetIpAbuseList()
{
return DataAccess.Instance.Abuses.Where(p => p.TypeId == 1).Select(p => p.Source).ToList();
}
public List<string> GetSourceAbuseList()
{
return DataAccess.Instance.Abuses.Where(p => p.TypeId == 2).Select(p => p.Source).ToList();
}
}
The class to which I am trying to bind repository
public class ValidateAbuse
{
[Inject]
public ISettingsRepository Repository { get; set; }
public static ValidateAbuse Instance = new ValidateAbuse();
}
Ninject will only bind properties on an object when it creates an instance of that object. Since you are creating the instance of ValidateAbuse rather than Ninject creating it, it won't know anything about it and therefore be unable to set the property values upon creation.
EDIT:
You should remove the static singleton from ValidateAbuse and allow Ninject to manage it as a singleton.
kernel.Bind<ValidateAbuse>().ToSelf().InSingletonScope();
Then when you ask Ninject to create any class that needs an instance of ValidateAbuse, it will always get the same instance.
It seems like you don't fully understand how Ninject works or how to implement it so I would suggest you read the wiki https://github.com/ninject/ninject/wiki/How-Injection-Works and follow some more basic examples before trying to wire it into an existing application.