I have an ASP.NET 4.5 Web Application (running on IIS 7.5), which calls a method from a class library I have referenced.
I want to add ELMAH to log when I have unhandled exceptions.
I have installed ELMAH with NuGet. It works great.
The problem is that it doesn't log any exceptions coming from the class library, it only logs the ones coming from the web application.
I tried adding a try catch in my class library and tried to log the exception manually with:
ErrorSignal.FromCurrentContext().Raise(e);
But this doesn't do anything.
Do I have to install and reference ELMAH on both web application and class library ? And will the web.config be enough for the class library to know which handlers and modules to use ? Or do I need to add another config in the class library ?
I noticed that both web app and class library have a packages.config but it only contains:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="elmah" version="1.2.2" targetFramework="net45" />
<package id="elmah.corelibrary" version="1.2.2" targetFramework="net45" />
</packages>
I have found many pages on stackoverflow about this topic but couldn't find an answer that works for me.
Some people recommended using
ErrorLog.GetDefault(HttpContext).Log(new Error(errExc));
But HttpContext is not available. I tried using null instead of HttpContext but it didn't help either.
While searching online, I found out that ELMAH only logs the stuff coming from the web app. I was able to log the stuff coming from the class library by installing NLog or using System.Diagnostic.Trace.
Perhaps I'm wrong about this, and I'd be open to corrections.
Related
I have read several postings about assembly binding issues and have tried many of the proposed solutions, all with no luck.
I have a relatively old asp.net web forms web site. It depends on a .Net Framework 4.6 Analytics assembly that in turn depends on NewtonSoft.Json. That Analytics assembly is one of our own and was built with NewtonSoft.Json v7.0.1. That is the version of the assembly that resides in the web site's bin folder.
I have a newer web site, an Angular SPA, that relies on .Net Framework WebApi services. The services rely on a logging helper component that calls a separate logging service. The logging helper component depends on Microsoft.AspNet.WebApi.Client to make the service call, which depends on System.Net.Http.Formatting, which depends on NewtonSoft.Json v6.0.4.
When I try to use the new logging helper component in the web site, at runtime, the logging fails saying that it cannot load v6.0.0.0 of NewtonSoft.Json or one of its dependencies.
If I drop the v7.0 file in the web site bin folder, the web site fails because the Analytics assembly cannot load v7.0.0.0 of NewtonSoft.Json or one of its dependencies.
Ideally I'd like to have Microsoft.AspNet.WebApi.Client and System.Net.Http.Formatting play nicely with the newer version of NewtonSoft.Json, but I don't have much control over how those assemblies play. I've tried rebuilding my Analytics component with NewtonSoft.Json v6.0.4, but when it gets built and deployed, somehow on the web server it still ends up looking for v7.0.0.0.
I feel like I'm stuck between a rock and a hard place. I can either have my Analytics work or my Logging work, but I cannot get both to work. Any suggestions as to a) what direction to pursue for a solution - getting my Analytics component to accept the older version or getting my Logging component to work with the newer version and b) how to accomplish either of those approaches?
Update 1 - Some of the things I've tried beyond what I've described above:
In my logging helper component .csproj project file, I tried eliminating the version information from my NewtonSoft.Json reference. I deployed it into the web site with the NewtonSoft.Json v7.0 file, but it still failed saying it couldn't load v6.0.
I tried using fuslogvw.exe, the Assembly Binding Log Viewer. Maybe I wasn't using it right, but I could reproduce my assembly binding error and saw nothing at all the Assembly Binding Log Viewer.
Update 2 - I tried adding an assembly binding redirect in my logging helper component redirecting it from 6.0.0.0 to 7.0.0.0, but when I build the component and drop it in the web site bin folder, which now has the NewtonSoft.Json 7.0 file, the logger still fails saying that it can load v6.0.0.0. Is there no way out of this?
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NewtonSoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="6.0.0.0"
newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
Update 3 - Below is the packages.config from the logging helper component. I believe that everything in packages.config is based on my adding the Microsoft.AspNet.WebApi.Client package. According to the package info on NuGet, it should work with NewtonSoft.Json >= 6.0.4, but it always fails looking for 6.0.0.0.
<packages>
<package id="Microsoft.AspNet.WebApi.Client" version="5.2.6" targetFramework="net461" />
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.5" targetFramework="net461" />
<package id="Microsoft.Net.Compilers" version="2.4.0" targetFramework="net461" developmentDependency="true" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net461" />
<package id="System.Net.Http" version="2.0.20126.16343" targetFramework="net461" />
</packages>
I'm not entirely satisfied with this answer, but it does appear to work. I read through several more posts on this topic, specifically posts about issues with version conflicts with NewtonSoft.Json, which seems to have conflicts quite often. In this article several people reported that the assembly binding redirects only worked if they were in machine.config. I had been trying to add assembly binding redirects in my logging helper component config file. I realize now that since I had a runtime binding error, I needed to work on the configuration of the runtime application, i.e. the web site. But adding the bind redirects to web.config seems to have no effect, while adding them to machine.config works. Unfortunately it breaks other applications on the server that need a different version. So... sort of an answer, but not all the way there yet. Here is the binding redirect that, when added to machine.config on the web server, gets the logging helper component working correctly in the web site.
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="NewtonSoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
<bindingRedirect oldVersion="6.0.0.0" newVersion="7.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
But I still need to figure out how to get the other applications on the server to work correctly. This problem seems to never end.
Update: I have a working solution, at least in my Dev and Test environments. The solution involves the assembly binding redirect in machine.config as described above plus installing the desired version of the assembly into the Global Assembly Cache (GAC) so that it's available to all applications on the server.
It's not my favorite solution and I'd still be happy to hear alternatives, but for now, this is what I've got and it seems to work. Only problem left is getting the assembly into the GAC on Production servers that don't have Visual Studio or Windows SDK installed - so no gacutil.exe utility.
I am working on an asp.net website. I have large amounts of data (around 20 millions) and need to cache them in order to query and display data faster in my website. I am using threads to do it but after visiting some pages on my local machine I get this error:
How can I avoid this error or what are things I need to check?
Try this:
Change the unhandled exception policy back to the default behavior that occurs in the .NET Framework 1.1 and in the .NET Framework 1.0.
Note We do not recommend that you change the default behavior. If you ignore exceptions, the application may leak resources and abandon locks.
To enable this default behavior, add the following code to the Aspnet.config file that is located in the following folder:
%WINDIR%\Microsoft.NET\Framework\v2.0.50727
<configuration>
<runtime>
<legacyUnhandledExceptionPolicy enabled="true" />
</runtime>
</configuration>
Took from here
(Or) Try using Debug Diagnostic Tool to resolve your issue. Here is the link:-
Tool for diagnosing memory leaks in .NET (ASP.NET Application)
Also I found a nice article about memory leaks, go through this article and see that if there is something wrong with your code:-
http://msdn.microsoft.com/en-us/magazine/cc163491.aspx
I have a class library whcih is a Wrapper class for Enterprise Library Logging Application Block. There I kept an App.Config configuration file. Where all the Enterprise Library related configurations are present.
Now I refered this Class Library in a ASP.NET Web Application. Problem I am getting is: The ASP.NET Web Application is unable to read the App.Config file to fetch Configuration Information. And I am getting below Exception:
Config files are per appdomain, not per binary. If you've got an .exe, it'll looking .config, in a web app, it looks in web.config. There are some tricks you can use, but they all involved putting something in the main config file - you can't avoid it for the most part.
The easiest thing to do would be to put the information in the web.config file. There are some other options, but they get increasingly more complicated. What version of Entlib are you using? If using 5.0, there's the programmatic configuration support (the configuration builder stuff) that makes is reasonably easy to set up entlib settings through code - you could use those in your library if the configuration is actually fixed.
Although you mention you're wrapping the logging block, but the screenshot shows the exception block. Is your main app going to be using Entlib as well, or just through your wrappers?
I'm trying to develop a settings application whererby a developer can download a zip file containing a SQLite database and the relevant DLL's and simple use it by calling Setting.Set and Setting.Get in their code. Using a simple Key/Value pair in the database, this lets users store any setting, for anything.
However, I keep getting the error:
"Could not load file or assembly 'System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. The system cannot find the file specified."
...when trying to integrate it into a new test app.
I've tried the
<configuration>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0"/>
<requiredRuntime version="v4.0.20506"/>
</startup>
</configuration>
section in the App.config but this doesn't fix the problem.
I'm trying to make the "plug-in" as easy as possible for the end user/developer for re-usability but this is becoming very tedious indeed! >:-(
Any ideas guys?
Thank you for your help!!
You can start by using the latest System.Data.SQLite assembly:
http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
Somewhere on that page you'll find "Precompiled Statically-Linked Binaries for 32-bit Windows (.NET Framework 4.0)" which should be fine for packaging the System.Data.SQLite assembly with your app.
This should also allow you to not use the useLegacyV2RuntimeActivationPolicy="true" application setting.
I developed a Solution in VS2005 for an ASP.net application which also has some class library projects that the ASP.Net project references. I have changed the Build Configuration of the solution to release but strangely, the ASP.net build config remains Debug whatever I do. This is weird as I see no reason why MS should have done that. Is it something else I could not thiink of?
Is this a web application? Is so, did you changed the web.config debug="True" attribute to debug="False"?