log4net and .net Framework 4.0 - .net-4.0

I was having issues in log4net when I updated my solutions to .net 4.0 , and then I downloaded the source of it and built log4net and targeted it to .net 4.0 and used it in my projects.
Initially when I referred log4net that is targeted to run time 2.0 it complied and run the application but log did not work.
Now when I run my project with log4net targeted to .net 4.0 I get the error "The type initializer for 'Log4NetTest.TestLog' threw an exception."
Any Idea how to solve this?
Edit: this is the inner exception:
InnerException: System.TypeLoadException Message=Inheritance security rules violated while overriding member:
'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'.
Security accessibility of the overriding method must match the security accessibility of the method being overriden.
Source=log4net
TypeName=log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)
StackTrace:
at log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory loggerFactory)
at log4net.Repository.Hierarchy.Hierarchy..ctor() in C:\src\Repository\Hierarchy\Hierarchy.cs:line 150

In the log4net source code, add a [SecurityCritical] attribute to the
Util.ReadOnlyPropertiesDictionary.GetObjectData method and build.
Just compiled the source for target framework 4.0 (not client). Source code of version 1.2.11 already contains this attribute, but be sure to use 'NET_4_0' as a compiler argument. Otherwise, this attribute will not be added.

I've found a compiled version of log4net for .NET client profile here:
http://gosheg.blogspot.com/2011/04/log4net-in-net-40-c-applications-net.html

This worked for me:
In the log4net source code, add a [SecurityCritical] attribute to the Util.ReadOnlyPropertiesDictionary.GetObjectData method and build.
There might be some other things you'll need to do to get it to build for the 4.0 framework.
See this post:
Weird override problem with Fluent NHibernate and .NET 4

I have fixed the similar issue by simply updating the Log4Net package from Visual Studio package manager.
Thanks,
Khachatur

I Fixed it by adding [assembly: System.Security.SecurityRules(System.Security.SecurityRuleSet.Level1)]
to log4net AssemblyInfo but now its not logging

Related

System.Web.ApplicationServices in .NET Core 2

I'm building a Web API in .NET Core 2. I'm using some custom nuget packages to leverage their built in functionality. These custom packages were built against an older .NET version (4.6.1). The problem is some of these packages have references to the old System.Web dll. I'm getting this warning on some of the custom packages in the solution
package was restored using '.net framework version=v4.6.1 instead of using the proj target framework.
The app is also throwing this exception below when I call code in one of the custom packages
System.IO.FileNotFoundException: Could not load file or assembly System.Web.ApplicationServices, Version=4.0.0.0, Culture=neutral,The system cannot find the file specified
Is there any way around this other than re-writing the code in my web Api?
No. System.Web is completely incompatible with Core. While Microsoft opened up NuGet packages that target .NET Framework to be utilized in with .NET Core, it did so based only on .NET Standard 2.0 compatibility, and makes no assurances that the packages will function in part or whole. You'll actually get a warning during compile telling you as much. Also, while you can actually have something like an ASP.NET Core app actually target .NET Framework, again, compatibility of third-party components is not guaranteed, simply because they target the same framework.
Long and short, if there's any dependency on System.Web at all, you can't use it.

How do I stop Ninject for WebApi failing on "var kernel = new StandardKernel();"

I just installed Ninject.MVC5 into my solution (I have an MVC project and a WebApi project in there and I wanted Ninject for both).
Then I installed WebApiContrib.IoC.Ninject to build on the previous install so that I could use Ninject in the WebApi package.
Then I updated the packages (because NuGet showed updates to install - even though I had updated the packages directly prior to installing Ninject).
I tried running my WebApi project but it failed on var kernel = new StandardKernel(); in NinjectWebCommon.CreateKernel() with this error:
An exception of type 'System.IO.FileNotFoundException' occurred in Ninject.dll but was not handled in user code
Additional information: Could not load file or assembly 'System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
Having read several answers on here and contemplated certain relatively complex solutions I tried one more thing which I will share in the Answer in case it helps anyone else...
I removed WebApiContrib.IoC.Ninject from the WebApi project (via NuGet: Manage and then untick to remove) and then added it back.
Project runs and behaves as expected, and no updates are required after adding WebApiContrib.IoC.Ninject back in to WebApi project.
The update that NuGet identified as required overwrote/broke something that was fixed by this answer.
Add the package Microsoft.Aspnet.Mvc from Nuget.
Solved for me.
In my case, MVC4 for Framework 4.0 and Visual Studio 2017

Getting error in umbraco The type or namespace name 'Umbraco' could not be found

The type or namespace name 'Umbraco' could not be found (are you
missing a using directive or an assembly reference?)
I am getting this error when I am inheriting my controller from
Umbraco.Web.Mvc.RenderMvcController
I have checked that umbraco.dll is referenced when I install umbraco from NuGet in Visual Studio 2012.
Intellisense allow me to select this reference but when I compile code it throw this exception like below screen explains it.
All other umbraco is working nice I have designs some static views, master pages, macros etc. all working fine.
In case of Umbraco.
my application was on .Net FrameWork 4.0
umbraco previous version was using .Net FrameWork 4.0
so i was try to use new release of Umbraco 7.0.1 on same FrameWork 4.0 after reading an post i check for .Net Framework for new release i found that was on .Net FrameWork 4.5 so i upgraded my application to 4.5 it resolve the issue.
thanks to everyone who visit to this post.

The type initializer for 'PayPal.Manager.ConfigManager' threw an exception >Paypal SetExpressCheckout

for some reason I am getting an error "cannot read config file" when trying to set the SetExpressCheckout, I have copied across the web config settings, but for some reason I cannot read them, the error isn't very helpful other than what I have mentioned.
I am using mvc4, and to be honest I have had a problem reading the web.config in the past..
any suggestions would be much appreciated.
Just looked at this... thought it might help someone. Looked at the Inner Exception, saw it was looking for the Log4Net dll... so I gave it to the app and hey ho. It worked.
I had a similar problem and ended up getting both the core and merchant sdk source from GitHub. Change the SpecificVersion=True to False for the log4net reference in the core sdk and re-build it. I also re-targeted both for .net 4.0 so I re-built the merchant sdk with a reference to the new core sdk. Import both of these new dll's to your main project and you should be good to go. I had to change the config in 1 place for the section handler.
<section name="paypal" type="PayPal.Manager.SDKConfigHandler, PayPalCoreSDK"/>
since the Assembly name does not have the underscores if built from source (vs downloaded or added via NuGet).
A bit of explanation:
I was already using log4net version 1.11 before adding the sdk. The sdk was looking specifically for version 1.10. these 2 versions have a different public key, so 'simple' binding redirection won't work. If you have a reference to a different version of log4net (for example using ninject logging extensions requires min version 2.11 so these 2 ninject and the paypal sdk, are incompatible off the shelf).
so the root of the problem was actually caused by the dll version issues but manifested as a Configuration exception. check the inner exceptions and see what you get.
ok, just a quick update, I think it must be something to do with MVC, I have created a new empty asp project, copied the sdk config details across, created the same function call as I have in my mvc code, and called it from a simple asp button... and it works ??
does anyone have any ideas why I am getting an error in an mvc4 project, and not in a simple asp project ??
any help or ideas would be much appreciated.

ASP.NET Web API conflict after installing VS 2012 Ultimate

I installed asp.net mvc-4 beta a while ago to host our api. It worked fine until I just installed vs2012 ultimate on my machine. The project is neither compiling in vs2010 nor in vs2012. What can I do to resolve this conflict. Furthermore, I bin deployed asp.net web api assemblies on my server. What I have to do to run the latest build (once the previous problem is solved) on server?
Edit:
The compilation errors when I open in vs2012 are
'System.Net.Http.HttpRequestMessage' does not contain a definition for 'GetUserPrincipal' and no extension method 'GetUserPrincipal'...
'System.Web.Http.Hosting.HttpPropertyKeys' does not contain a definition for 'UserPrincipalKey'
In vs 2010 on the other hand, it refuses to accept types like DelegatingHandler and others. Some errors are as follows.
The type or namespace name 'DelegatingHandler' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'HttpResponseMessage' could not be found (are you missing a using directive or an assembly reference?)
I have installed the latest build of asp.net mvc 4 as well and the version its showing me is 4.0.20713.0. Previously, I added web-api beta using nuget. I have removed them all and installed latest builds of web-api from nuget. I don't know what could be the problem. One thing, I don't understand: why do I need to install web-api assemblies seprately when they are supposedly part of mvc framework?
thanks
Add using System.ServiceModel.Channels; to your file. The Extension methods for HttpRequestMessage exist in this namespace according to THIS.
add
using System.Net.Http;
You probably have the reference already, so just add the using for the extension method.
Otherwise add the Assembly of the same name.