UnityContainerBase.RegisterInstance<Interface> throwing ThreadSynchronizationLock Exception - unity-container

I am working on a Silverlight application which gets data from WCF service. Once I receive the data from the service I am trying to register an instance of an object to the Unity container and I see that it throws ThreadSynchronizationLock exception.
Can anybody help me avoid this exception?

Known issue. The RegisterInstance method (actually the ContainerControlledLifetimeManager) will try to release a lock it doesn't have when doing RegisterInstance. This is actually a first-chance exception, is properly handled in the codebase, and only shows up in the debugger.
Basically, you don't need to avoid it, it's already handled properly inside the code.
Also, my understanding is that this behavior was changed in Unity 3.0 to avoid exactly these kinds of questions. :-)

Related

UWP: AccessViolationException on an attempt to open a page

I have a Xamarin.Forms application that uses FreshMvvm. On an attempt to open a particular page with this code:
await CoreMethods.PushPageModel<DistributorsLocatorPageModel>();
after the execution passes the page's Init() method and all properties, the app crashes with the following error:
System.AccessViolationException
HResult=0x80004003
Message=Attempted to read or write protected memory. This is often an
indication that other memory is corrupt.
Source=Cannot evaluate the exception source
StackTrace: Cannot evaluate the exception stack trace
This happens only in UWP. iOS and Android have no issue. And other pages also open fine even in UWP.
I would appreciate your suggestions.
just found this through desperate googling and didn't find much in the way of answers.
one thing i'll say for it is that the issue lies in thread safety - when navigation is done explicitly on the main thread the problem doesn't arise, however if you're using AppShell navigation on a tabpage or some other place where you don't invoke the navigation in your own code, there doesn't seem to be a lot you can do.
I'm currently attempting to find a good place to override OnNavigatedTo, but so far have come up short.
so I guess this is a long way of saying "bump"

Getting exception when instantiating AlternatorDBClientV2

When I am trying to create a new instance of AlternatorDBClientV2 I am getting below exception.
java.lang.NoSuchMethodError: com.amazonaws.transform.JsonErrorUnmarshaller: method ()V not found
at com.michelboudreau.alternatorv2.AlternatorDBClientV2.init(AlternatorDBClientV2.java:106)
at com.michelboudreau.alternatorv2.AlternatorDBClientV2.(AlternatorDBClientV2.java:100)
at com.michelboudreau.alternatorv2.AlternatorDBClientV2.(AlternatorDBClientV2.java:95)
I am using 0.12.0 version of alternator.
any idea why this exception is occurring.
Thanks!!
I recently ran into this as well.
JsonErrorUnmarshaller is a class internal to Amazon's SDK, and if you take a look in the jar's source, they apparently changed the constructor to take some arguments recently.
That means that the line at https://github.com/mboudreau/Alternator/blob/master/src/main/java/com/michelboudreau/alternatorv2/AlternatorDBClientV2.java#L106 would fail, as it calls new JsonErrorUnmarshaller().
I'm afraid you might need to configure local DynamoDB. Alternator hasn't been updated in 2 years, there's going to be incompatibilities.

Error when using DependencyResolver for Controller instantiation with MVC 3

I'm using MVC 3 and using the following code when the application starts...
UnityContainer container = new UnityContainer();
new UnityMappings(container);
DependencyResolver.SetResolver(new UnityServiceLocator(container));
Now when the app runs I'm getting the following error (but only sometimes)...
Activation error occured while trying to get instance of type
IControllerFactory, key ""
Interestingly, if I continue with the web request, the website works normally.
Any ideas? I can't see what I'm doing differently from before when this worked fine.
Cheers, Ian.
MVC3 requests a lot more than just controllers from the DependencyResolver. For most of them MVC3 falls back to the default implementation in case the DependencyResolver does not return an instance.
In your case it requests the IControllerFactory which is unknown to your IoC container and it throws an exception which is caught by the UnityServiceLocator implementation and null is returned. MVC then falls back to the default controller factory.
Unlike other IoC containers Unity does not provide an optional TryResolve and therefore does not support a proper exceptionless implementation of the DependencyResolver.
I would suggest first looking through the config and make sure everything is correct there, then I would make sure I had all the assemblies needed for Unity referenced in the project. That error message may (in my experience) point to an error in config or a missing DLL, perhaps an assembly you want to load in the container or another DLL needed by a DLL loaded by Unity?
Hope this helps.

ASP.Net MissingMethodException - "ctor" method not found

We are getting intermittent problems on a production server that we cannot recreate.
There are two very strange things about the issue. Firstly it's a method not found error on the constructor (ctor) for an exception handling helper class and secondly we have custom errors switched on for remote users and this property is being ignored.
The detail of the error is:
Server Error in '/MyWebsite' Application.
Method not found: 'Void MyExceptionHelperClass..ctor (System.Exception)'.
...
Exception Details: System.MissingMethodException: Method not found: 'Void MyExceptionHelperClass..ctor (System.Exception)'.
...
The stack trace is pretty unhelpful.
My thoughts are that there may be an out-of-memory error or something like that that is killing the page. When the exception handling code kicks in it tries to create an exception object which fails for the same reason giving this error.
However this is wild speculation. We are waiting for the event logs to see whether anything is amiss with the server but in the meantime does anyone have any thoughts or suggestions?
UPDATE:
It has proven difficult to get information out of the team responsible for the production servers but I have managed to find out that as far as load balancing is concerned, this site is currently only running on one server (this can be made to switch over onto another if necessary). Given that this is an intermittent problem and there is only one server involved, then I find it difficult to believe that this could be an assembly issue. Surely if it was then the problem would occur every time?
If you see this error happening on a site that has custom errors turned on, then the error is happening in the custom error handling routine itself.
From the look of the .NET error message it appears that your routine is expecting a constructor that accepts an exception by reference - your comment above shows a constructor that accepts by value.
Check carefully that there isn't a stale version of an assembly in your system somewhere. These can lurk in the Temporary ASP.NET Files folder; you'll need to do an "iisreset /stop" before you can clear them out.
In that regard it's always a good idea to make sure that AssemblyInfo.cs is set up to automatically stamp version numbers in some way. We have our version numbers tied to our source code repository system and CI build box so we can tell exactly what was in what assembly really easily.
I would use elmah: http://code.google.com/p/elmah/ to hopefully give you a bit more insight into the issue. It is free and can be used on an existing site without any recompilation. Try it - and post back if the issue is still happening.
As others have also mentioned, I would suspect that your site is somehow using an out of date version of an assembly. Something you could try doing is a full Precompile of your site before deploying to your production server. This ensures that ASP .Net doesn't dynamically compile the site on the fly, and therefore should mean that it's using completely up to date code throughout.
Do you have a no parameter public constructor defined for MyExceptionHelperClass in your code? Or is the class meant to only have static methods, in which case it should be a static class.
public class MyExceptionHelperClass()
{
public MyExceptionHelperClass() { }
}
Unfortunately, this may be one of those cases where the error message is of little to no value. In my experience, this general class of exception may be the result of either a configuration issue or bad logic aroung threading/app domains. For example, I have seen similar issues upon attempting to load the same assembly into an app domain more than once.
You mention that this is difficult to reproduce. If it's only happening on one server in the production farm it's more likely to be a config issue (with that machine). If it's happening on more than one server than it could be either config or threading.
It might be worth spending some time looking at the larger code base around the areas mentioned above. The root cause may not be in this class. Good luck!
I think it's a Framework issue with keeping compiled versions consistency. It's common to see same sort of errors while updating site sources repeatedly. Just try something like
net stop iisadmin /y && del /q /f /s "%systemroot%\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\*.*" && iisreset
I encountered this exception today on a webforms page. I found a solution, but I'm not sure why it worked.
Nest the code behind in a 'Namespace [YourNamespace]' tag.
Add the namespace to the html Page tag's Inherits property in the aspx page 'Inherits="PathStart.YourNameSpace.ClassName"'.
Rebuild
Navigate to the page again and you should not encounter the exception.
After following the steps above I reverted the changes and did not re-encounter the exception.

Method 'XYZ' cannot be reflected

We have consumed a third party web service and are trying to invoke it from an ASP.NET web application.
However when I instantiate the web service the following System.InvalidOperationException exception is thrown:
Method 'ABC.XYZ' can not be reflected.
System.InvalidOperationException:
Method 'ABC.XYZ' can not be reflected.
---> System.InvalidOperationException: The XML element 'MyDoc' from namespace
'http://mysoftware.com/ns' references
a method and a type. Change the
method's message name using
WebMethodAttribute or change the
type's root element using the
XmlRootAttribute.
From what I can gather there appears to be some ambiguity between a method and a type in the web service.
Can anyone clarify the probably cause of this exception and is there anything I can do to rectify this or should I just go to the web service owners to rectify?
Edit: Visual Studio 2008 has created the proxy class. Unfortunately I can't provide a link to the wsdl as it is a web service for a locally installed thrid party app.
I ran into the same problem earlier today.
The reason was - the class generated by Visual Studio and passed as a parameter into one of the methods did not have a default parameterless constructor. Once I have added it, the error had gone.
It seems the problem is down to data type issues between VS and the web service that was written in Java.
Ultimately it was fixed by manually editing the class and schema files that were created by VS.
I have come across the exact same problem when I was consuming a 3rd party web service. The problem in this instance was that the mustUndertand property in the reference file was looking for a Boolean, whereby the namespace property looked for a string.
By looking through the reference i was able to idenitfy the offending property and simply add "overrides" to the method signature.
Not ideal as any time you update the service you have to do this but I couldn't find any other way around this.
To find the reference file select "all files" from the solution explorer
Hope this helps
I'm guessing the wsdl emitted by or supplied with the service is not in a form that wsdl.exe or serviceutil can understand - can you post the wsdl or link to it?
how are you creating the proxy classes?
Also you might like to try and validate the wsdl against the wsdl schema to check its valid
In my case I was getting a "method cannot be reflected" error due to that fact that in the class being returned by method, I had failed to expose a default parameter-less constructor.
I was working in VB.NET. In my return class I had declared a "New(..)" method that took a couple parameters (because that is how I wanted to use it in my code). But by doing so, I had supressed the default (hidden) parameterless New() constructor that VB adds behind the scenes. Apparently the web service handler requires that a parameterless constructor be available. As soon as I added back into my class a parameterless New() constructor, it all worked fine.
I got the same message but mine was caused by a missing System.Runtime.Serialization.dll since I tried to run a 3.5 application on a machine with only .NET 2.0 installed.
I had the same issue but I found that one of the WebMethod parameters has a member that is of type interface that is why VS could not serialise it. here is the exception when trying to download the disco file
System.InvalidOperationException: Cannot serialize member
'Leopard.JobDespatchParameters.SendingUser'
of type 'Leopard.Interfaces.IUser', see inner exception for more
details. ---> System.NotSupportedException: Cannot serialize member
Leopard.JobDespatchParameters.SendingUser
of type Leopard.Interfaces.IUser because it is an interface.
Old thread but I had a different issue, Maybe of help to someone. referenced dlls were mixed up between two versions on data layer and service layer that caused the problem.
Another scenario where this error can happen: I simply had another web method with the same name (but different parameters)in my web service that slipped in during a code merge. After I deleted the old method it worked.

Resources