Rdlc report unable to parse regular expression - asp.net-web-api

I am using the .net framework 4.7.2. And In a web API project with Ninject dependency injection, I am trying to generate an rdlc report with an expression. The problem is the report is generating perfectly when I am not using any expression but everything goes wrong when using an expression. Just a normal sum expression of two fields of a dataset.
=Fields!AdditionalPremiumDeposit.Value + Fields!RefundOfPremium.Value
The two fields are dataset field(decimal)
Whenever I am trying to generate a report I am getting an error, below ->
Failed to load expression host assembly. Details: Type 'Ninject.Web.WebApi.NinjectDependencyResolver'
in assembly 'Ninject.Web.WebApi, Version=3.3.1.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7'
is not marked as serializable.
the stack trace ->
at
Microsoft.ReportingServices.RdlExpressions.ReportRuntime.ProcessLoadingExprHostException(Exception
e, ProcessingErrorCode errorCode)
at Microsoft.ReportingServices.RdlExpressions.ReportRuntime.LoadCompiledCode(Report report, Boolean
includeParameters, Boolean parametersOnly, ObjectModelImpl reportObjectModel, ReportRuntimeSetup
runtimeSetup)
at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(Boolean includeParameters, Boolean
parametersOnly)
at Microsoft.ReportingServices.OnDemandProcessing.Merge.Init(ParameterInfoCollection parameters)
at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.ProcessOdpReport(Report report,
OnDemandMetadata odpMetadataFromSnapshot, ProcessingContext pc, Boolean snapshotProcessing, Boolean
reprocessSnapshot, Boolean processUserSortFilterEvent, Boolean processWithCachedData, ErrorContext
errorContext, DateTime executionTime, IChunkFactory cacheDataChunkFactory, StoreServerParameters
storeServerParameters, GlobalIDOwnerCollection globalIDOwnerCollection, SortFilterEventInfoMap
oldUserSortInformation, EventInformation newUserSortInformation, String
oldUserSortEventSourceUniqueName, ExecutionLogContext executionLogContext,
OnDemandProcessingContext& odpContext)
at Microsoft.ReportingServices.ReportProcessing.ReportProcessing.RenderReport(IRenderingExtension
newRenderer, DateTime executionTimeStamp, ProcessingContext pc, RenderingContext rc, IChunkFactory
cacheDataChunkFactory, IChunkFactory yukonCompiledDefinition, Boolean& dataCached)
at Microsoft.Reporting.LocalService.CreateSnapshotAndRender(CatalogItemContextBase itemContext,
ReportProcessing repProc, IRenderingExtension renderer, ProcessingContext pc, RenderingContext rc,
SubreportCallbackHandler subreportHandler, ParameterInfoCollection parameters,
DatasourceCredentialsCollection credentials)
at Microsoft.Reporting.LocalService.Render(CatalogItemContextBase itemContext, Boolean
allowInternalRenderers, ParameterInfoCollection reportParameters, IEnumerable dataSources,
DatasourceCredentialsCollection credentials, CreateAndRegisterStream createStreamCallback,
ReportRuntimeSetup runtimeSetup)
at Microsoft.Reporting.WebForms.LocalReport.InternalRender(String format, Boolean
allowInternalRenderers, String deviceInfo, PageCountMode pageCountMode, CreateAndRegisterStream
createStreamCallback, Warning[]& warnings)
I am not understanding whats the relation between the rdlc and Ninject.
My report generation method ->
public static byte[] ReportByte(string dataSourceName, object dataSource, string reportFileName, FileLayout fileLayout = FileLayout.Potrait)
{
try
{
var lr = new LocalReport();
var path = Path.Combine(HttpContext.Current.Server.MapPath("~/Reports/Rdlc"), reportFileName);
if (!File.Exists(path))
throw new ArgumentException("report not found");
lr.ReportPath = path;
var rd = new ReportDataSource(dataSourceName, dataSource);
lr.DataSources.Add(rd);
string reportType = "pdf";
string mimeType;
string encoding;
string fileNameExtension;
string deviceInfo = string.Empty;
if (fileLayout == FileLayout.Landscape)
{
deviceInfo = "<DeviceInfo>" +
" <OutputFormat>pdf</OutputFormat>" +
" <PageWidth>11in</PageWidth>" +
" <PageHeight>8.5in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>.50in</MarginLeft>" +
" <MarginRight>.50in</MarginRight>" +
" <MarginBottom>0.50in</MarginBottom>" +
"</DeviceInfo>";
}
else
{
deviceInfo = "<DeviceInfo>" +
" <OutputFormat>pdf</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0.5in</MarginTop>" +
" <MarginLeft>.50in</MarginLeft>" +
" <MarginRight>.50in</MarginRight>" +
" <MarginBottom>0.50in</MarginBottom>" +
"</DeviceInfo>";
}
Warning[] warnings;
string[] streams;
byte[] renderedBytes;
renderedBytes = lr.Render(
reportType,
deviceInfo,
out mimeType,
out encoding,
out fileNameExtension,
out streams,
out warnings);
return renderedBytes;
}
catch (Exception)
{
throw;
}
}
I am also sharing my dependency kernel creation method ->
private static IKernel CreateKernel()
{
var kernel = new StandardKernel();
try
{
kernel.Load(Assembly.GetExecutingAssembly());
HttpConfiguration.DependencyResolver = kernel.Get<System.Web.Http.Dependencies.IDependencyResolver>();
return kernel;
}
catch
{
kernel.Dispose();
throw;
}
}
and

Seems like Ninject.WebApi 3.3.1 has a serialization issue. I just changed it to 3.3.0. Now everything just works fine for me. Hope this helps other folks who will face the issue in the future.

Related

Connecting to RETS Servers with UserAgent Requirement

I am hoping there is someone here who is familiar with a Real Estate data standard known as RETS. The National Association of Realtors provides a dll for interfacing with their services called libRETS, but it is not being supported like it once was and recent events have prompted us to create our own as a replacement. For logistics reasons, we can't do this in Core and are using the current C#.Net 4.7.2.
There are 2 or 3 different "security levels" for connecting to a RETS Server, with the method being a per case basis from one MLS to the next. We can successfully connect to those who only require a login and password, but are hitting a wall on those who also require what is called a UserAgent and UserAgentPassword, which must passed somehow using Md5 encryption. The server is returning:
The remote server returned an error: (401) Unauthorized.
private WebResponse GetLoginBasicResponse()//*** THIS ONE WORKS ***
{
try
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var request = (HttpWebRequest)WebRequest.Create(new Uri(_cred.loginUri));
request.Method = "GET";
request.Headers.Add("RETS-Version", _retsVersion);
request.Credentials = new NetworkCredential(_login, _password);
return request.GetResponse();
}
catch (Exception ex)
{
string ignore = ex.Message;
return null;
}
}
private WebResponse GetLoginWithUserAgentResponse()//*** THIS ONE DOES NOT WORK ***
{
try
{
// ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var request = (HttpWebRequest)WebRequest.Create(new Uri(_cred.loginUri));
request.Method = "GET";
request.Headers.Add("RETS-Version", _retsVersion);
if (!string.IsNullOrEmpty(_cred.userAgent))
{
request.UserAgent = Md5(_cred.userAgent + ":" + _cred.userAgentPassword);
//request.Headers.Add("RETS-UA-Authorization", "Digest " + Md5(_cred.userAgent + ":" + _cred.userAgentPassword));
}
request.Credentials = new NetworkCredential(_login, _password);
return request.GetResponse();
}
catch (Exception ex)
{
string ignore = ex.Message;
return null;
}
}
public string Md5(string input) //*** Borrowed this from from .NET Core Project and presume it works
{
// Use input string to calculate MD5 hash
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
// Convert the byte array to hexadecimal string
StringBuilder sb = new StringBuilder();
for (int i = 0; i < hashBytes.Length; i++)
{
sb.Append(hashBytes[i].ToString("X2"));
}
return sb.ToString();
}
}
Page 20 of this document describes how to build the UA header: https://www.ranww.org/documents/resources/rets_1_8.pdf
There’s a few other fields you need to include.
We were not able to solve the issue in .NET but found a .NET Core project in GitHub that we are using instead. https://github.com/CrestApps/RetsConnector
This case can be closed
Not seeing an option to "Mark as Answer". Have tried both MS Edge and Google Chrome

Create AIScene instance from the file's content

I'm writing a Java web service where it is possible to upload a 3D object, operate on it and store it.
What I'm trying to do is creating an AIScene instance using a byte[] as an input parameter which is the file itself (it's content).
I have found no way to do this in the docs, all import methods require a path.
Right now I'm taking a look at both the lwjgl java version of Assimp as well as the C++ version. It doesn't matter which one is used to solve the issue.
Edit: the code I'm trying to get done:
#Override
public String uploadFile(MultipartFile file) {
AIFileIO fileIo = AIFileIO.create();
AIFileOpenProcI fileOpenProc = new AIFileOpenProc() {
public long invoke(long pFileIO, long fileName, long openMode) {
AIFile aiFile = AIFile.create();
final ByteBuffer data;
try {
data = ByteBuffer.wrap(file.getBytes());
} catch (IOException e) {
throw new RuntimeException();
}
AIFileReadProcI fileReadProc = new AIFileReadProc() {
public long invoke(long pFile, long pBuffer, long size, long count) {
long max = Math.min(data.remaining(), size * count);
memCopy(memAddress(data) + data.position(), pBuffer, max);
return max;
}
};
AIFileSeekI fileSeekProc = new AIFileSeek() {
public int invoke(long pFile, long offset, int origin) {
if (origin == Assimp.aiOrigin_CUR) {
data.position(data.position() + (int) offset);
} else if (origin == Assimp.aiOrigin_SET) {
data.position((int) offset);
} else if (origin == Assimp.aiOrigin_END) {
data.position(data.limit() + (int) offset);
}
return 0;
}
};
AIFileTellProcI fileTellProc = new AIFileTellProc() {
public long invoke(long pFile) {
return data.limit();
}
};
aiFile.ReadProc(fileReadProc);
aiFile.SeekProc(fileSeekProc);
aiFile.FileSizeProc(fileTellProc);
return aiFile.address();
}
};
AIFileCloseProcI fileCloseProc = new AIFileCloseProc() {
public void invoke(long pFileIO, long pFile) {
/* Nothing to do */
}
};
fileIo.set(fileOpenProc, fileCloseProc, NULL);
AIScene scene = aiImportFileEx(file.getName(),
aiProcess_JoinIdenticalVertices | aiProcess_Triangulate, fileIo); // ISSUE HERE. file.getName() is not a path, just a name. so is getOriginalName() in my case.
try{
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);
return mesh.mName().toString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());
}catch(Exception e){
e.printStackTrace();
}
return "fail";
}
When debugging the method I get an access violation in the method that binds to the native:
public static long naiImportFileEx(long pFile, int pFlags, long pFS)
this is the message:
#
A fatal error has been detected by the Java Runtime Environment:
#
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000007400125d, pid=6400, tid=0x0000000000003058
#
JRE version: Java(TM) SE Runtime Environment (8.0_201-b09) (build 1.8.0_201-b09)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.201-b09 mixed mode windows-amd64 compressed oops)
Problematic frame:
V [jvm.dll+0x1e125d]
#
Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
An error report file with more information is saved as:
C:\Users\ragos\IdeaProjects\objectstore3d\hs_err_pid6400.log
#
If you would like to submit a bug report, please visit:
http://bugreport.java.com/bugreport/crash.jsp
#
It is possible if we use the aiImportFileFromMemory method.
The approach I wanted to follow was copied from a github demo and actually copies the buffer around unnecessarily.
The reason for the access violation was the use of indirect buffers (for more info why that is a problem, check this out).
The solution is not nearly as complicated as the code I initially pasted:
#Override
public String uploadFile(MultipartFile file) throws IOException {
ByteBuffer buffer = BufferUtils.createByteBuffer((int) file.getSize());
buffer.put(file.getBytes());
buffer.flip();
AIScene scene = Assimp.aiImportFileFromMemory(buffer,aiProcess_Triangulate, (ByteBuffer) null);
Long id = scene.mMeshes().get(0);
AIMesh mesh = AIMesh.create(id);
AIVector3D vertex = mesh.mVertices().get(0);
return mesh.mName().dataString() + ": " + (vertex.x() + " " + vertex.y() + " " + vertex.z());
}
Here I create a direct buffer with the appropriate size, load the data and flip it (this part is a must.) After that let Assimp do its magic so you get pointers to the structure. With the return statement I just check if I got the valid data.
edit
As in the comments it was pointed out, this implementation is limited to a single file upload and assumes it gets everything that is necessary from that one MultipartFile, it won't work well with referenced formats. See docs for more detail.
The demo that was linked in the question's comments which was used in the question as a base has a different use case to my original one.

Apache jena to update remote endpoint

The current procedure we now often perform is to extract data from an endpoint, perform computational analysis, generate RDF files and manually load them back into the endpoint.
Now I was looking into automating this procedure using Apache Jena ARQ as these dependencies are currently used for the retrieval of information.
I manage to get it partially to work using INSERT statements but performing thousands if not millions of inserts one by one seem a bit inefficient to me. The second issue is that we sometimes have regex or " in a string and this needs to escaped but there are many exceptions.
Is there a way to either parse or iterate over an internal apache jena model statements and inject this directly into an endpoint?
We currently use graphdb but it would be great if this can be applied using a universal approach.
Update
I have updated the code to handle 10 statements at once not sure yet what eventually the limit will be...
public class EndpointTests extends TestCase {
// Only for local testing
public void testEndpoint() throws Throwable {
String endpoint = "http://10.117.11.77:7200/repositories/Test";
Domain domain = new Domain("file:///Users/jasperkoehorst/diana_interproscan_head.nt");
StmtIterator statements = domain.getRDFSimpleCon().getModel().listStatements();
String strInsert = "INSERT DATA { ";
int insertCounter = 0;
while (statements.hasNext()) {
insertCounter = insertCounter + 1;
Statement statement = statements.nextStatement();
String subject = statement.getSubject().getURI();
String predicate = statement.getPredicate().getURI();
String object = statement.getObject().toString();
if (statement.getObject().isURIResource()) {
object = "<" + statement.getObject().toString() + ">";
}
if (statement.getObject().isLiteral()) {
object = statement.getObject().asLiteral().getString();
object = object.replaceAll("\\\\", "\\\\\\\\");
object = object.replaceAll("\"","\\\\\"");
}
if (object.startsWith("http")) {
object = "<" + object + ">";
} else {
object = "\"" + object + "\"";
}
strInsert = strInsert + "<" + subject + "> <" + predicate + "> " + object + " . ";
if (insertCounter % 10 == 0) {
System.out.println(insertCounter);
strInsert = strInsert + " } ";
UpdateRequest updateRequest = UpdateFactory.create(strInsert);
UpdateProcessor updateProcessor = UpdateExecutionFactory.createRemote(updateRequest, endpoint + "/statements");
updateProcessor.execute();
strInsert = "INSERT DATA { ";
}
}
}
}

CKEditor file upload doesn't work properly with mvc 6

I'm trying to use the built in upload file of CKEditor, it works with my MVC5 project, but it doesn't work with my MVC6 project, the code for uploading the file is correct, I've tested it, and it actually upload the file to the server, but it doesn't populate the form with the URL and image information, here's the code for my MVC5 project that works:
public ActionResult UploadImage(HttpPostedFileBase upload, string CKEditorFuncNum, string CKEditor,
string langCode)
{
string vImagePath = String.Empty;
string vMessage = String.Empty;
string vFilePath = String.Empty;
string vOutput = String.Empty;
try
{
if (upload != null && upload.ContentLength > 0)
{
var vFileName = DateTime.Now.ToString("yyyyMMdd-HHMMssff") + " - " + Path.GetFileName(upload.FileName);
var vFolderPath = Server.MapPath("/Upload/");
if (!Directory.Exists(vFolderPath))
{
Directory.CreateDirectory(vFolderPath);
}
vFilePath = Path.Combine(vFolderPath, vFileName);
upload.SaveAs(vFilePath);
vImagePath = Url.Content("/Upload/" + vFileName);
vMessage = "The file uploaded successfully.";
}
}
catch(Exception e)
{
vMessage = "There was an issue uploading:" + e.Message;
}
vOutput = #"<html><body><script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + vImagePath + "\", \"" + vMessage + "\");</script></body></html>";
return Content(vOutput);
}
And here is the code for MVC6 project that doesn't work:
public async Task<ActionResult> UploadImage(IFormFile upload, string CKEditorFuncNum, string CKEditor,
string langCode)
{
string vImagePath = String.Empty;
string vMessage = String.Empty;
string vFilePath = String.Empty;
string vOutput = String.Empty;
try
{
if (upload != null && upload.Length > 0)
{
var vFileName = DateTime.Now.ToString("yyyyMMdd-HHMMssff") + " - " + ContentDispositionHeaderValue.Parse(upload.ContentDisposition).FileName.Trim('"');
var vFolderPath = Path.Combine(_environment.WebRootPath, "Files", "ArticleUploads");
if (!Directory.Exists(vFolderPath))
{
Directory.CreateDirectory(vFolderPath);
}
vFilePath = Path.Combine(vFolderPath, vFileName);
await upload.SaveAsAsync(vFilePath);
vImagePath = Url.Content("/Files/ArticleUploads/" + vFileName);
vMessage = "The file uploaded successfully.";
}
}
catch (Exception e)
{
vMessage = "There was an issue uploading:" + e.Message;
}
vOutput = #"<html><body><script>window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ", \"" + vImagePath + "\", \"" + vMessage + "\");</script></body></html>";
return Content(vOutput);
}
And in CKEditor config file I have:
config.filebrowserImageUploadUrl = '/Admin/Article/UploadImage';
I've inspected the variables, and they send the same value, also worth to note that I'm using the same version of CKEditor, so that can't be the problem, I'd appreciate any help on this.
If the file gets uploaded and you don't see the image gets populated, I guess there should be some problem with the way you return your content, since you are returning html, try to specify your content type, like so:
return Content(vOutput, "text/html");
If that didn't solve your problem, you need to provide more information, tell us what exactly you get from this action in JavaScript side.

Replacing VAR datatype in .NET 2.0

I am using .NET 2.0, need to implement VAR datatype in here:
var doc = XDocument.Parse(result);
var sw = doc.Descendants("viewport").Elements("southwest").SingleOrDefault();
if (sw != null)
{
var lat = (double)sw.Element("lat");
var lng = (double)sw.Element("lng");
// do stuff
}
I used STRING instead
public string getLatLang(string address)
{
string latlang = "";
string url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + address + "&sensor=false";
System.Net.WebClient client = new System.Net.WebClient();
string result = client.DownloadString(url);
string doc = System.Xml.Linq.XDocument.Parse(result).ToString();
string sw = doc.Descendants("viewport").Elements("southwest").SingleOrDefault();
if (sw != null)
{
string lat = (double)sw.Element("lat");
string lng = (double)sw.Element("lng");
latlang = lat + "," + lang;
// do stuff
}
return latlang;
}
But I get an error :
'string' does not contain a definition for 'Descendants'
Please help me to replace VAR here.
To replace var, research the actual return type of the method and change it to that. For example, XDocument.Parse can be found on MSDN here In the documentation, it states "Creates a new XDocument from a string", therefore, the return type must be XDocument. And if you drill down into one of the method overloads (like this one), you'll see the actual method's signature which confirms that it does indeed return an XDocument.
Also, Visual Studio has intellisense, so if you hover over something you can generally get details about it. Try typing System.Xml.Linq.XDocument.Parse(, When you type the first paren, you should see a popup in Visual Studio that tells you what the return type is for the method you're using. If intellisense is not working, then check to make sure you have a reference to the DLL.
Also note that Visual Studio has what is known as Object Explorer. This will allow you to see the method signatures of each object you're working with which includes the return types. Simply right click on any object or method and select "Go To Definition". Hopefully, the Visual Studio version you're using has this, if not, consider upgrading because it's extremely useful.
public string getLatLang(string address)
{
string latlang = "";
string url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + address + "&sensor=false";
System.Net.WebClient client = new System.Net.WebClient();
string result = client.DownloadString(url);
XDocument doc = System.Xml.Linq.XDocument.Parse(result);
XElement sw = doc.Descendants("viewport").Elements("southwest").SingleOrDefault();
if (sw != null)
{
string lat = sw.Element("lat").Value;
string lng = sw.Element("lng").Value;
latlang = String.Format("{0},{1}", lat, lng);
// do stuff
}
return latlang;
}
Edit: Please note that this solution will not work in .NET 2.0 without some hacks due to LINQ and redistributing System.Core is against the EULA, so you'll likely have to change XDocument to XmlDocument and figure out how to integrate it with Google's return value. I believe it has a Load method, or LoadXml method, can't remember which one does which.
var in itself isnt a data type it just takes the data type from the other side of the equality operator. read more about it here
therefore replacing every var with string wont help you will have to use the correct data type instead of var if you cannot use a var.
error in your case is originating because you i think on this line string doc = System.Xml.Linq.XDocument.Parse(result).ToString(); when replacing var you should have used XDocument but instead you used a string to accomodate errors used a ToString() function.
Edit:- after the comment
public string getLatLang(string address)
{
string latlang = "";
string url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + address + "&sensor=false";
System.Net.WebClient client = new System.Net.WebClient();
string result = client.DownloadString(url);
XDocument doc = System.Xml.Linq.XDocument.Parse(result);
XElement sw = doc.Descendants("viewport").Elements("southwest").SingleOrDefault();
if (sw != null)
{
string lat = (double)sw.Element("lat").Value;
string lng = (double)sw.Element("lng").Value;
latlang = lat + "," + lang;
// do stuff
}
return latlang;
}
The var keyword is used to implicitly type variables. You're letting the compiler infer the type of your variables. But under the covers, once compilation occurs, variables are still assigned specific types.
What you've done wrong is call .ToString() on your XDocument. Now you just have one big string and you're attempting to treat it like it's still an XDocument.
Try this instead.
XDocument doc = System.Xml.Linq.XDocument.Parse(result);
XElement = doc.Descendants("viewport").Elements("southwest").SingleOrDefault();
Edit
Finally got in front of a computer with Visual Studio on it. You have a few more problems.
The following will compile in .NET 3.5+.
public string getLatLang(string address)
{
string latlang = "";
string url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + address + "&sensor=false";
System.Net.WebClient client = new System.Net.WebClient();
string result = client.DownloadString(url);
XDocument doc = System.Xml.Linq.XDocument.Parse(result);
XElement sw = doc.Descendants("viewport").Elements("southwest").SingleOrDefault();
if (sw != null)
{
string lat = sw.Element("lat").ToString();
string lng = sw.Element("lng").ToString();
latlang = lat + "," + lng;
// do stuff
}
return latlang;
}
(Notice that you were later explicitly casting values to double and still defining their types as string).
As for the error you mention in your comment, I'm not sure... the Elements<T>(IEnumerable<T>, XName) member is included in the extensions class of System.Xml.Linq (MSDN), so it should work. Make sure that you have also included the System.Linq directive with your other using directives:
using System.Linq;
As an aside, I actually don't see how a lot of the code you have written will work in .NET 2.0. The System.Xml.Linq and System.Linq namespaces weren't introduced until .NET 3.5. If you're really using .NET 2.0, then you may want to reference this thread for a work-around for the framework version you're using.
Ok ,Now I tried everything possible with .NET 2.0 ,I came up with this solution which I know is very low level coding but is the only possible solution with 2.0 , this works EXCELLENT FOR .NET 2.0 !!
public string getLatLang(string address)
{
string latlang = "";
string url = "http://maps.googleapis.com/maps/api/geocode/xml?address=" + address + "&sensor=false";
System.Net.WebClient client = new System.Net.WebClient();
string result = client.DownloadString(url);
int firstlat = result.IndexOf("<lat>");
int lastlat = result.IndexOf("</lat>");
int firstlng = result.IndexOf("<lng>");
int lastlng = result.IndexOf("</lng>");
string _latitude = result.Substring(firstlat+5, (lastlat-5) - firstlat);
string _longitude = result.Substring(firstlng+5, (lastlng-5) - firstlng);
latlang = _latitude + "," + _longitude;
return latlang;
}

Resources