I have a controller that takes multiple arguments and I am using Unity to create an instance of that controller. The problem is that under certain circumstances Unity is not able to build all of the objects that are needed for my constructor so it throws an Exception.
[MissingMethodException: No parameterless constructor defined for this object.]
How do I handle this error and show a custom error page to the user?
Don't handle that error, either create parameterless constructors for said objects that are instantiated, or don't create them in the constructor. Handling those exceptions would just be masking the issue.
Related
I've recently followed this post on how to set up Umbraco and Glass Mapper. All of my code is set up the same as the example. However I keep on getting an error when I create a controller.
No parameterless constructor defined for this object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.MissingMethodException: No parameterless constructor defined for this object.
Does anyone know how to fix this? Do I have to set something up in Castle Windsor?
Does somebody know, how to avoid the next compilation error?
explicit constructor call not allowed
Is it possible to call a superclass-constructor inside a children class?
Thanks!
I working on .net MVC Entity Framework (Code First).
I am not able to get Datacontext in repository classes functions when i call these functions from a static function in controller
. I am getting the Exception
"An exception of type 'System.NullReferenceException' occurred in YYYYYY.Web.dll(Default project dll) but was not handled in user code
Additional information: Object reference not set to an instance of an object."
i need to call static functions since i had to call some functions asynchronously.Like Report generation
This works perfectly fine when called from a non static function in controller.
Thanks in advance
Punnoose
So the full error that I get is:
Exception while attempting to inspect or instantiate type Microsoft.TeamFoundation.Framework.Server.WindowsProvider in assembly C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\tfs\96d93be0\609f57b6\assembly\dl3\71c3ceb4\00f38a60_8f06cb01\Microsoft.TeamFoundation.Framework.Server.DLL: No parameterless constructor defined for this object.
and
Exception while attempting to inspect or instantiate type Microsoft.TeamFoundation.Framework.Server.TfsSyncAgent in assembly C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\tfs\96d93be0\609f57b6\assembly\dl3\71c3ceb4\00f38a60_8f06cb01\Microsoft.TeamFoundation.Framework.Server.DLL: No parameterless constructor defined for this object.
Both are very similar
There are two main points to this:
1)Exception while attempting to inspect or instantiate type Microsoft.TeamFoundation.Framework.Server.WindowsProvider
2)Microsoft.TeamFoundation.Framework.Server.DLL: No parameterless constructor defined for this obj
I am making a server side event handler for tfs and I keep getting this error when i check in the item This is the tutorial i am following. Anyone know how to fix this problem?
Note: I did NOT have the folder "C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\tfs\ " for some odd reason and had to create the directory and put the dll in it. That did not fix the problem either.
The Directory C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files is a directory used by IIS for Web Applications like TFS. Copies of the dlls of the web app will be deployed there. So when an exception is thrown it may happen, that you get this directory as the source of the problem instead of the real TFS-Directory.
Your problems seems to be, that you do not have a parameterless constructor in your ISubscriber. But a parameterless constructor is required!
No, you cannot add code to someone else's code.
What are you trying to accomplish? There's probably another way to do it.
I've been using MvcSiteMapProvider based on authorize attributes and it was all right until we introduced a new class derived from AuthorizeAttribute. Main difference is in its constructor signature:
public MyAuthorizeAttribute(param RoleCode[] roles) {
Roles = string.join(",", roles.Select(r => r.ToString());
}
And... MvcSiteMapProvider shown unexpected result: only actions marked by MyAuthorizeAttribute became invisible. I've checked that by disabling this constructor - everything went as it had been before adding a parameter to the constructor. Also - it's not params specific - any parameter (event int) leads to such behaviour.
AS I understood from MvcSiteMapProvider sources, it emits some code to emulate authorize attributes - but looks like it's impossible to save assembly generated by external code. I know that there is a workaround - use some kind of enumerable property, but have you got any suggestions how to make it work with constructor parameters? Do you know why MvcSiteMapProvider behaves like that?
So, after spending some time in debugging, I realized the answer: dynamic proxies.
The problem is that during request execution inside MVC framework there is no easy way to find out how a class derived from AuthorizeAttribute performs its work. In case of access check failure some could throw exception, some - return 401 status code, some redirect to login page at once, and so on.
But MvcSiteMapProvides does that! It uses the following workaround:
if class is AuthorizeAttribute:
create an instance of InternalAuthorize class which is fairly simple.
copy all properties there and
invoke AuthorizeCore method which returns boolean value.
else
generate a proxy class derived from a type of attribute,
create instance, /// << here we get an exception
copy all properties there and
invoke AuthorizeCore method which returns boolean value.
As it is clear, that's not an easy task to make a proxy, which is aware of your constructor parameters. Exception about default constructor absence is thrown, of course, but it is then consumed by empty catch clause. That is really sad - at least a single debug trace would have saved me a couple of hours.
So the answer at last:
Obviously you should use parameterless attribute constructor (why oh why that's not mentioned anywhere?)
Make custom acl provider: implement IAclModule interface and unleash your knowledge about your own authorize attributes within it.