Showing posts with label Error messages. Show all posts
Showing posts with label Error messages. Show all posts

Monday, March 3, 2014

Exception - The underlying connection was closed: An unexpected error occurred on a send.

While connecting to an external web service (using WebRequest), you might get the following error

Exception - The underlying connection was closed: An unexpected error occurred on a send.

The inner exception might be  
"Received an unexpected EOF or 0 bytes from the transport stream"

This might get resolved by setting
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

I think .NET applications use TLS for transport security by default. So when the external server where the web service resides does not support TLS, I would assume, the connection would be tried using SSL3. But in some cases (like it was for me), the connection failed with the above error. It was resolved by forcing SSL3.

Tuesday, November 15, 2011

Error: Delegate System.Func <> does not take 1 arguments

If you get the error
Delegate 'System.Func<entityName,int,bool>' does not take 1 arguments
or
Cannot convert lambda expression to type 'string' because it is not a delegate type

then check the linq query and confirm that the "where" condition has == instead of = ..
var allProducts = from p in context.Products where p.productID == 1 select p;

I wasted a lot of time on this and would like to help anyone else who might have similar issues

Wednesday, April 6, 2011

Unable to resolve dimension value "match_parent" in attribute "layout_width"

Unable to resolve dimension value "match_parent" in attribute "layout_width"


If you get the above error while developing any Android application, just replace change "match_parent" with "fill_parent"

I spend some time figuring this out .. so thought maybe this would help someone out there who has similar issues

Friday, April 24, 2009

VS2008: Error while setting the property of a custom web control - An unhandled exception has occurred

You might see this error when you create a custom web control which has a property that you would like to set in the web page that consumes the control.
An unhandled exception has occurred. 'value' could not be set on 'propertyName'

I had created lots of custom controls in VS 2005 and creating custom properties for these controls was pretty straight forward. So I was surprised when i saw this error. I tried various things to find the reason and why the value was not getting set. Finally i gave up and started searching the net and finally got this link
http://www.west-wind.com/Weblog/posts/484172.aspx

this seemed to a bug with VS 2008 and SP1 and till date there is no solution. The only option is to close VS and open it again. But again this is a problem with the IDE, you can still compile the project and run it and it will not throw any compilation error nor show any error while accessing those properties you set on your custom control.

For those who are interested, Rick (whose blog I have referenced above) also has a issue ticket raised with microsoft which is marked as resolved, but the patch mentioned also seems to be buggy (read the comments in the link given below)
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=361826

Comments from the above link

>>>> Hi, I installed the hotfix: KB961847 - "Error creating control- [text] property" ASP.NET server cntls in VS the problem still there? can anyone tell me if i got the wrong hotfix? or is there any hotfix i need to install as well?
Posted by NatureNZ on 4/23/2009 at 2:56 PM

>>>> and the hotfix seems broke the web user control as well, i had a web user control uses standard asp controls and ajax control. it was working well in design time and now it is got the same error again.
Posted by NatureNZ on 4/23/2009 at 3:38 PM

Friday, March 13, 2009

WCF - "The client was unable to retrieve service metadata. Make sure the service is running and exposing metadata."

So as you can see, not I have moved onto writing code in framework 3.5 and learning the way around WCF, WPF etc ..

I am in the processes of designing and developing a application using SOA and for that purpose, trying to create the data layer as service. Now why this is been planned has a service has its own reasons and maybe I can explain it sometime later. After creating a simple WCF service, I tried to test it using the default client tool provided by VS2008, I kept getting this error "The client was unable to retrieve service metadata. Make sure the service is running and exposing metadata."

I looked and cross-checked every detail and could not locate the issue. After a couple of trial and error, I noticed that one of the contract defined for the endpoint did not have the complete namespace. I had changed the namespace of contract class and I think I had reassigned the contract using the WCF configuration tool and suprisongly, it had not added the complete namespace. Anyway, correcting this namespace cleared the issue.

So you get a similar error, check the namespace for each of the component within the app.config by opening it within the VS IDE and not within the WCF configuration tool.

Friday, May 16, 2008

"Exception has been thrown by target of invocation" Error

You might face this error and wonder what happened. I had a similar situation today. The code was working fine and all of a sudden I got this error. I am not that kind of person who beleives very strongly that all errors are due to some bad coding, maybe by the developer or maybe thrown bt the tools used for development. Till now, whenever I have been involved in coding or debuging someone's problem , I have managed to at least find out where the issues have been and most of time solve it too. Anyway, so I started tracing my steps backwards and commenting recenlty changed codes. But still was not able to find exactly where the error is occuring.

Finally, during one my debug attempts, I happened to look at the exception object's inner exception and noticed the error was because of a new addition I had on the app.config file. I made the correction and the error was gone. BTW, the change I did was add a "configSections" tag at the end of the app.config file. If you add a "configSections" tag, it has be the first line after the "configuration" tag.

So to conclude, if you get this error ""Exception has been thrown by target of invocation"", look at the inner exceptions. Keep looking recursively into the inner exception's "inner exception" till you see "nothing" and hopefully you see the actual error message and correct the problem.

happy coding !!

Tuesday, May 6, 2008

Public member 'OverRideMethod' on type 'ObjectHandle' not found. [Reflection - Access methods from class dynamically]

I had a hard time with this. Spend around 2-3 hours trying various options till i got a clue from one of the links on the internet.

I had a class library (dll) referenced in a windows project and all the classes in this dll is inherited from a base class. The baseclass is mustinherit and has mustoverride function. My plan was that this windows application would have a list of (dynamically maintained using a XML file in the windows application) classes and its methods that can be executed from this dll. Each of the class within this dll overrides the mustoverride function from the baseclass and does some actions. The reason for this design was to make a "plug and play" kind of application. So if i wanted to add a new functionality, i just need to add a new class to the dll, edit the XML file and the front-end will show this new functionality and it will execute it. There were many other functions that were specific to the project that need not be discussed here .. Anyway, this sounded very simple to me and i started with writing the code..

The first thing that came into my mind was whether i would have to use reflection. But the dll was referenced in the main windows project. So there was no need to load a assembly dynamically and i did not want to go with that approach. Then found from the help about Activator.CreateInstance which has a overloaded function which accepts 2 strings .. the assembly name and the class name .. this was what i wanted. So i wrote this

Dim lObject As Object
lObject = Activator.CreateInstance("Namespace.MyAssembly", "Derived Class Name")
lObject.OverRideMethod

But this kept giving an error on the line where it is executing overriden method.
Public member 'OverRideMethod' on type 'ObjectHandle' not found.

I was sure that the object was getting created because when i changed the assembly or the class name, it gave the error on that line. So what was the issue? I could not get any help in MSDN. So i started searching the net and luckily got a link which said that Activator.CreateInstance does not give a object in return, but returns a object handle. I checked MSDN and it said that it gave back a object. I aklso noticed now that the error I got mentioned that "... on type ObjectHandle not found" So I decided to give it a try.. So I changed the code to

Dim lHandle As System.Runtime.Remoting.ObjectHandle
lHandle = Activator.CreateInstance("Namespace.MyAssembly", "Derived Class Name")
lRulesObject = lHandle.Unwrap()
lRulesObject.OverRideMethod

Lo and behold, it worked !! ..

I also type cast my object to the baseclass so that I can now call the method from the baseclass directly.. So my final code was

Dim lHandle As System.Runtime.Remoting.ObjectHandle
Dim lRulesBase As MyBaseClass
Dim lRulesObject As Object

lHandle = Activator.CreateInstance("Namespace.MyAssembly", "Derived Class Name")
lRulesObject = lHandle.Unwrap()
'-- cast it to the base class
lRulesBase = DirectCast(lRulesObject, MyBaseClass)
'-- call the service method
lRulesBase.OverRideMethod()

I spend some time finding this out and i thought I will post this for others who might have similar issues.

Happy coding !!