|
I am attempting to filter a list, nothing unusual, done it 1000s of times.
List<NBAggDB> lAgg = lNBAgg.Where(x => x.NodeKey.StartsWith(oParentNode.NodeKey)).ToList();
ParentNode is populated and has a NodeKey, lNBAgg is a List<nbaggdb> and is populated and all have valid NodeKeys
Yet I get the following exception an the only null object is x and the following is highlighted by the exception.
x.NodeKey.StartsWith(oParentNode.NodeKey)
{System.NullReferenceException: Object reference not set to an instance of an object.
at Texas.ViewModels.NewBusinessVM.<>c__DisplayClass11.<LoadAggRows>b__10(NBAggDB x)
at System.Linq.Enumerable.WhereListIterator`1.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Texas.ViewModels.NewBusinessVM.LoadAggRows(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.LoadBudgetCells(TreeNodeNB oNode)
at Texas.ViewModels.NewBusinessVM.LoadNodeChildren(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.LoadNodeChildren(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.LoadNodeChildren(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.LoadNodeChildren(TreeNodeNB oParentNode)
at Texas.ViewModels.NewBusinessVM.<LoadNBBudget>b__2(String sErrorMsg, ObservableCollection`1 lResult)
at Texas.DataServices.NBBudgetDS.NBBudgetForPeriodCompleted(Object sender, NBBudgetForPeriodCompletedEventArgs e)
at Texas.TexasSvc.TexasSvcClient.OnNBBudgetForPeriodCompleted(Object state)}
How the hell am I supposed to debug that?
[edit] lNBAgg is populated with null objects [/edit]
Never underestimate the power of human stupidity
RAH
modified 10-Apr-14 20:38pm.
|
|
|
|
|
I've run into this a couple of times with the database I'm working with.
The code works, right up until one of your NodeKey objects is null, OR, in your case, oParentNode is null. Somewhere in that pile of data you're working with...
|
|
|
|
|
It was actually caused by a type mismatch between the database and the object, the conversion is done in the DAL and returns a null object when there is a mismatch, I forgot to put in the error trap and got bitten AGAIN! The code is all generated at that level and I have not moved the trap into the code generator .
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
That sounds like a better problem to have than the one I've got! Trust me, you don't want to know. On top of that, it's a problem of my own creation!
|
|
|
|
|
Hello,
I am writing a visual C# program to read GPS coordinates (x,y) and will like to plot the points on a form as a bitmap, can someone advise me on the most effective way in doing that?
Thanks,
Ron
|
|
|
|
|
You just need to scale the points to the coordinate system that you use in your bitmap. For example, if your bitmap is 100 x 100, and your latitude and longitude cover a range of 20 degrees each. Then each degree covers a range of 5 pixels, or alternatively each pixel is equivalent to 12 minutes. So to convert a latitude of 10'30" to pixel point, convert to minutes 10 * 60 + 30 = 630, divide by 12 = 52.5, rounded = 53. So that point lies at Y coordinate 53.
|
|
|
|
|
Thanks for the ideas, I'll see how this works out
Ron
|
|
|
|
|
In addition to what Richard said if I need to draw I usually use GDI+ for simple things.
You can add a panel to your form and make the background white.
Then you can get a Graphics [^]object from that. You use the FromHwnd[^] method and pass the panel's handle to it. Now you can use the Graphics object to draw.
Note that this also uses coordinates with 0,0 on the top left corner. The width and height of the panel are your maximum lengths to draw within the boundaries. Note that the x-axis is going to the right and the y-axis is going down!
Hope this helps.
(PS: there's probably a charting library available on Codeproject, you could search for that)
modified 11-Apr-14 4:59am.
|
|
|
|
|
You may also take a look at my article Bernie’s Trackviewer[^]. There, the corrdinates are loaded from gpx files.
|
|
|
|
|
I have a class that implements 2 interfaces.
I have a property that is of the type of one of those 2 interfaces.
Problem is, I want to use the other interface.
So class A implements interfaces B(my own interface) & C(third party interface).
In class D, I have a property E of type C.
How do I cast property E to type B?
ICustomControl control = (ICustomControl)Component;
is basically what I'm trying to do. But I get an exception when I try to do that.
the value of Component is a class that inherits from interface ICustomControl. The property Component is of type IComponent.
Any help would be appreciated.
|
|
|
|
|
Nico Haegens wrote: But I get an exception when I try to do that.
You'll need to post the details of the exception. Based on your description, the code you've posted will work:
interface IComponent {}
interface ICustomControl {}
class A : IComponent, ICustomControl {}
class D
{
public IComponent TheProperty
{
get { return new A(); }
}
}
static void Main()
{
D container = new D();
ICustomControl value = (ICustomControl)container.TheProperty;
Console.WriteLine(value);
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I'll provide more details:
Got 3 classes & 1 interface
1 class that has all the functionality and implements an interface
1 class that makes that class generic, has 1 property named DataItemTypeName and inherits from above class
1 class that wraps the generic class so it's usable in a webpage and also inherits from the first class.
in the controldesigner, I'm trying to access the control I made through the property Component which runtimetype is the type of the generic class.
What I understood from the exception is that it's trying to cast class nr 2 to the interface that it's baseclass implements and fails.
When I get to a line of code that says:
ICustomRepeater control = (ICustomRepeater)Component;
I get the exception below:
System.InvalidCastException was unhandled by user code
HResult=-2147467262
Message=Unable to cast object of type 'CustomRepeaterNS.CustomGenericItemsControl`1[TestApp.DummyTestClass]' to type 'CustomRepeaterNS.ICustomRepeater'.
Source=CustomRepeater
StackTrace:
at CustomRepeaterNS.CustomRepeaterDesigner.GetDesignTimeHtml() in d:\CustomRepeater\CustomRepeater\CustomRepeater.cs:line 842
at System.Web.UI.Design.ControlDesigner.GetDesignTimeHtml(DesignerRegionCollection regions)
at CustomRepeaterNS.CustomRepeaterDesigner.GetDesignTimeHtml(DesignerRegionCollection regions) in d:\CustomRepeater\CustomRepeater\CustomRepeater.cs:line 807
at System.Web.UI.Design.ControlDesigner.GetViewRendering(ControlDesigner designer)
InnerException:
|
|
|
|
|
Well either there's something else going on, or I've not understood your class hierarchy.
The following simplified version of what I think you're describing works perfectly:
interface ICustomRepeater { }
class CustomGenericItemsControl : ICustomRepeater { }
class CustomGenericItemsControl<T> : CustomGenericItemsControl { }
class DummyTestClass { }
class Wrapper : CustomGenericItemsControl
{
public CustomGenericItemsControl<DummyTestClass> Component
{
get { return new CustomGenericItemsControl<DummyTestClass>(); }
}
}
static void Main()
{
Wrapper wrapper = new Wrapper();
ICustomRepeater control = (ICustomRepeater)wrapper.Component;
Console.WriteLine(control);
}
From your error message, it would seem that the CustomGenericItemsControl<T> doesn't implement the ICustomRepeater interface, and doesn't inherit from a class that implements the ICustomRepeater interface.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Ended up fixing this problem by using delegates instead of interfaces, here is a sample of my code:
private Dictionary<string,Func<ITemplate>> templategetproperties;
private Func<ITemplate> GetITemplateProperty(string name)
{
if(templategetproperties==null)
{
templategetproperties = new Dictionary<string, Func<ITemplate>();
}
if(templategetproperties.ContainsKey(name)==false)
{
PropertyInfo pinfo = componentruntimetype.GetProperty(name);
templategetproperties[name] = (Func<ITemplate>)Delegate.CreateDelegate(typeof(Func<ITemplate>), Component, pinfo.GetGetMethod());
}
return templategetproperties[name];
}
Used Action instead of Func for the setters.
I think the problem was that the method MakeGenericType of the Type class doesn't transfer the interfaces of the non generic class type to the generic class type. This is only an educated guess though.
|
|
|
|
|
If I understand you correctly, you need to explicitly implement the interfaces (this is the correct term for it):
interface IFoo
{
int Baz {get; set;}
}
interface IBar
{
int Baz {get; set;}
}
class Quux : IFoo, IBar
{
int _fooBaz;
int _barBaz;
int IFoo.Baz
{
get { return _fooBaz; }
set { _fooBaz = value; }
}
int IBar.Baz
{
get { return _barBaz; }
set { _barBaz = value; }
}
}
To Access:
Quux quux = new Quux();
var stuff = (IFoo)quux.Baz
var stuff = (IBar)quux.Baz;
Hopefully I've got that right...
|
|
|
|
|
Thanks mate, always wondered what that option implement explicitly meant, now I know.
Your solution fixed my problem, so thanks so much.
|
|
|
|
|
|
Found out it didn't really fix the problem. Apparantly if I close Visual Studio and restart it, the problem is fixed. Well until I change something in the code, then I have to restart Visual Studio again. Kinda really annoying to restart VS every time I make a change to code.
My structure is as follows, changed the names a bit for more transparancy:
public interface ICustomItemsControl : IDataBoundControl, IComponent
{
}
public class CustomItemsControl : DataBoundControl, ICustomItemsControl
{
}
public class CustomItemsControl <TDataItem> : CustomItemsControl, ICustomItemsControl
{
private CustomItemsControlItem <TDataItem> CreateItem(int itemIndex, ListItemType itemType, bool dataBind, TDataItem dataitem)
{
return new CustomItemsControlItem <TDataItem>(itemIndex, itemType);
}
}
public class CustomItemsControlItem : CompositeControl
{
}
[ControlBuilder(typeof(CustomGenericItemControlBuilder))]
[Designer(typeof(CustomRepeaterDesigner))]
public class TypedCustomItemsControl : CustomItemsControl , ICustomItemsControl
{
private string dataItemTypeName;
[PersistenceMode(PersistenceMode.Attribute)]
public string DataItemTypeName
{
get { return dataItemTypeName; }
set { dataItemTypeName = value; }
}
}
The RepeaterControlBuilder converts the CustomRepeater class to a generic class.
I think the problem might be in the following class that does the actual work to convert my CustomItemsControl to a generic CustomItemsControl:
internal class RepeaterFakeType : TypeDelegator
{
public RepeaterFakeType(Type dataItemType)
: base(typeof(CustomItemsControl<>).MakeGenericType(dataItemType))
{
this.repeaterItemType = typeof(CustomGenericItemsControlItem<>).MakeGenericType(dataItemType);
}
protected override PropertyInfo GetPropertyImpl(string name, BindingFlags bindingAttr, Binder binder,
Type returnType, Type[] types, ParameterModifier[] modifiers)
{
PropertyInfo info = base.GetPropertyImpl(name, bindingAttr,binder,returnType,types,modifiers);
if (info == null)
return null;
if (name == "ItemTemplate" || name == "AlternatingItemTemplate")
info = new FakePropertyInfo(info, this.repeaterItemType);
return info;
}
}
|
|
|
|
|
Can't help you there, something else is going on. Sounds very like VS has broken though, or it's hanging on to something between builds. Definitely not the desired behaviour though!
|
|
|
|
|
I have a subclass of Windows.Forms.Label that I'd like to serialize to XML without using IXmlSerializable. A windows control (a Label in this case) isn't serializable.
Consider the following...
public class SubLabel : Windows.Forms.Label
{
public Text {get; set;}
public int LocationX {get; set;}
public int LocationY {get; set;}
public void Save(string path)
{
XmlSerializer xs = new XmlSerializer(typeof(SubLabel));
using (StreamWriter sw = new StreamWriter(path))
{
xs.Serialize(sw, this);
}
}
public static SubLabel Load(string path)
{
XmlSerializer xs = new XmlSerializer(typeof(TestClass));
using (StreamReader sr = new StreamReader(path))
{
return (SubLabel)xs.Deserialize(sr);
}
}
...
}
All I want to serialize are the public properties above.
I'd like to keep it simple by using the Save() and Load() methods above.
Of course this fails because of the Label parent class.
Is there an easy way to do this?
|
|
|
|
|
You could copy the selected public properties (Text , LocationX , LocationY ) to a separate class and just serialize that. Your Load() method would then deserialize that class and return a new SubLabel with those properties set.
/ravi
|
|
|
|
|
Hello
I am developing a program for a community launcher/downloader
what i am here to ask is there libraries to download a repo through an autoconfig file for downloading and updating the mod
I want the user to be able to download from this repo ftp://62.210.148.145/public/.a3s/autoconfig and to download and put these ftp://62.210.148.145/public in a game directory
The autoconfig is in an .gz file
That's the file in a nutshell it doesn't have an extention
|
|
|
|
|
Help with which part? Sounds almost like you expect the library to do everything your app should do?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
A Point in the right direction
|
|
|
|
|