Tuesday, August 24, 2010

how to get file from resources

Hi,
Today I was busy in two issues
First one was something refactoring I have to deal with some objects and their property name
and object property will be called by name Like I want obj.property(string name).setvalue("")
Any how I achieved this by reflection. lemme me share code with u


private static void LoadPropertiesValues(object dataObject )
{
if(dataObject != null)
{
PropertyInfo[] properties = dataObject.GetType().GetProperties();
foreach (PropertyInfo objInfo in properties)
{
XmlNode xmlMapNode =
_xmlMappingDoc.SelectSingleNode("/parentElement/ChildName[@fieldname='" +
objInfo.Name + "']");
if (xmlMapNode != null && xmlMapNode.Attributes[1] != null &&
xmlMapNode.Attributes[1].Value != string.Empty)
{
string mapGroupName = xmlMapNode.Attributes[1].InnerText;
Mapping mapping = _dataMapperDao.GetMappingByCodeAndResidencyValue(mapGroupName,
dataObject.GetType().GetProperty(objInfo.Name).GetValue(dataObject,null).ToString());
if (mapping != null)
{
dataObject.GetType().GetProperty(objInfo.Name).SetValue(dataObject,mapping.code,null);
}
}

}
}
}


Second issue was access file from resources
Actually I have to load some values from xml file and then I have to take care about its path because in production Envoirnment I cann't guarantee that path will be same neither I can enforce it. It will be changed so I want to get rid of this issue I put this file inside resources, then I put little effort on accessing this file.

Assembly objAssembly = Assembly.GetAssembly(typeof (ClassName));
if(objAssembly!=null)
{
Stream stream = objAssembly.
GetManifestResourceStream("ParentApp.ApplicationName.FileName.xml");
if (stream != null)
{
var xmlTextReader = new XmlTextReader(stream);

_xmlMappingDoc.Load(xmlTextReader);

}
}

So, this is all about today :)

Tuesday, August 17, 2010

breakpoints connot be set in method or class with the debuggerstep through attribute just my code is enable

Today I face this problem I was unable to debug my code and I spent several hours to solve it.
I got this exception when I put debug point and it displays this message on runtime.
Anyhow I found two solution
[assembly:System.Diagnostics.Debuggable(true,true)] attribute at assembly level.
I declare this attribute in assemblyinfo.cs

second solution is I change my webservice project from website to web application and everything is going smoothly :) Happy!!

Wednesday, August 4, 2010

Cannot import wsdl:port

Error: Cannot import wsdl:port
Detail: There was an error importing a wsdl:binding that the wsdl:port is depend
ent on.
XPath to wsdl:binding: //wsdl:definitions[@targetNamespace='http://www.xxx.xx.com/Service/SyncRiskProfileService/1.0']/wsdl:binding[@name='ISyncRiskBinding']
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://www.xxx.xx.com/Service/xxxxx/1.0']/wsdl:service[@name='SyncRiskxxx']/wsdl:port[@name='ISyncRiskService']

Solution is very simple actually svcutil looking for xsd's if you are using multiple xsd ,beacuse it's unable to load xsd. so, give xsd paths with spaces.
svcutil.exe