RavenDB within ASP.NET MVC with Unity causes ResolutionFailedException - c#

I have the following:
ASP.NET MVC 5
RavenDB.Client version="3.0.3690"
Unity version="3.5.1404.0"
Unity.Mvc latest
Periodically, especially after the ASP.NET application has been idle for some time, upon loading the page I get the following exception:
Exception information:
Exception type: ResolutionFailedException
Exception message: Resolution of the dependency failed, type = "MyCompany.Web.Controllers.MainController", name = "(none)".
Exception occurred while: Calling constructor XXXXXXXX.
Exception is: FileNotFoundException - Could not load file or assembly 'ICSharpCode.NRefactory.CSharp, Version=5.0.0.0, Culture=neutral, PublicKeyToken=d4bfe873e7598c49' or one of its dependencies. The system cannot find the file specified.
Note that ICSharpCode.NRefactory.CSharp appears to be an embedded assembly inside RavenDB. I don't reference it anywhere in my code, and it's not in the bin folder.
I never get this error in a console or WPF application, so it must be something with unloading AppDomains and/or recycling ASP.NET AppPools.
Perhaps the code in Unity.Mvc doesn't handle the unloading of embedded assemblies properly. Or perhaps something is missing from the section of my web.config.
Once I get the error, I hit the F5 (Refresh) button in the browser, and viola, the error goes away and the page loads as expected.
Any idea?
Thanks,
-Alec.

Related

Application trying to call a local library .dll that is no more appearing in the references

I created a custom library named it portableLibrary and added it to my C# soluation using portableLibrary;
after a time I changed its name to be UtilityMethods, so I removed the old one from my solution, and added the new one.
Everytime I try to debug or execute the application, since that time, the system showing me this error, tha indicate it is trying o call the old name, which is not in the references any more!!
An unhandled exception of type 'System.IO.FileNotFoundException'
occurred in mscorlib.dll
Additional information: Could not load file or assembly
'portableLibrary, Version=1.0.6146.37242, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. The system cannot
find the file specified.

Trouble when redeploying WP8.1 app

I met a problem, every time I want to deploy my app again, I will encounter error:
"An exception of type 'System.IO.FileNotFoundException' occurred in DropNetRT.ni.DLL but was not handled in user code
Additional information: Could not load file or assembly 'System.Net.Http.Phone, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified."
I have to uninstall the app, and then deploy. But next deployment same error again.
I'm also seeing this error - it only shows in Release mode, running the same app in Debug mode it doesn't repro.
The WP8.1 Silverlight solution builds without issue in both configurations.
Workaround for me is to remove all System.Net references solution-wide, clean the solution, then add them back in (using NuGet with Microsoft.Net.Http). Takes time and is annoying, but it works.
There seems no logic that the System.Net references removed and added back in are exactly the same assemblies and work fine on first deployment but fail on redeployment. It is even possible to redeploy exactly the same build and see this error.

Re-named assembly, application won't build

I renamed my WPF application's assembly from DBce_TEST2 to AMS, then attempted to build it to see what would happen. I ran it, and it wouldn't build for obvious reasons but now after renaming it back to DBce_TEST2 I get the following error:
Managed Debugging Assistant 'BindingFailure' has detected a problem in 'G:\C# Projects\Asset Management System\DBce_TEST2\bin\Debug\DBce_TEST2.vshost.exe'.
Additional Information: The assembly with display name 'AMS' failed to load in the 'Load' binding context of the AppDomain with ID 1. The cause of the failure was: System.IO.FileNotFoundException: Could not load file or assembly 'AMS' or one of its dependencies. The system cannot find the file specified.
The error can be fishy. Use Fusion log viewer to understand what has gone wrong.
How to enable assembly bind failure logging (Fusion) in .NET
Figured it out. Renamed the assembly again to some random text, attempted to run it, then renamed back to original assembly name and the error disappeared. Guess some generated files were messed up by visual studio a little bit, and this fixed it.

File not found exception for my MyWebservice.XmlSerializers when using PrincipalSearcher.FindAll()

I have a web service added by service reference (called "MyServiceReferences") in my ASP .NET MVC 4 solution. Also I have an Active Directory service in another project in the same solution. I am trying to display user name (First name and Last name) in my web page using active directory users information. The problem is when I call
PrincipalSearcher.FindAll(), it works sometimes. The exception I am getting is
Could not load file or assembly 'MyServiceReferences.XmlSerializers'
or one of its dependencies. The system cannot find the file specified.
In my project build setting I have tried to set Generate serialization assembly "On". But it did not solve my problem.
Following command from visual studio command line solves the problem
Sgen.exe (locationOfTheDllFile)\MyServiceReferences.dll
But there is another following error occurs rarely (when attempting to load the page very very often)
[System.AppDomainUnloadedException] = {"Attempted to access an unloaded appdomain. (Exception from HRESULT: 0x80131014)"}

Strange error in Quartz: Quartz.XmlSerializers not found

I am getting the following error in Quartz.net
The assembly with display name 'Quartz.XmlSerializers' failed to load
in the 'LoadFrom' binding context of the AppDomain with ID 1. The
cause of the failure was: System.IO.FileNotFoundException: Could not
load file or assembly 'Quartz.XmlSerializers, Version=2.0.1.100,
Culture=neutral, PublicKeyToken=null' or one of its dependencies. The
system cannot find the file specified.
It's very odd since Quartz.XmlSerializers does not exist anywhere in any code I'm using. It's not in the Quartz source code, my code, and none of my dependencies best I can tell. It only occurs when I debug my project, but not when I download the Quartz 2.0.1 source code and run the server from there.
I am using topshelf as the service install library.
It occurs during deserialization on line 226 of XMLSchedulingDataProcessor.cs of the Quartz source.
// deserialize as object model
System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(QuartzXmlConfiguration20));
Any clue to solving this would be helpful as I'm stumped by this error.
In applications that use XmlSerialization, you can get a first-chance exception in outside code when the application looks for a cached serialization assembly. You can find more information in this question.

Categories