Log4Net.Async issue in ASP.NET MVC - c#

I keep receiving following error:
log4net:ERROR Could not create Appender [AsyncLog4NetAppender] of type [Log4Net.Async.ParallelForwardingAppender]. Reported error follows.
System.TypeLoadException: Could not load type [Log4Net.Async.ParallelForwardingAppender]. Tried assembly [log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a] and all loaded assemblies
at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR Appender named [AsyncLog4NetAppender] not found.
Packages config
<package id="log4net" version="2.0.8" targetFramework="net451" />
<package id="Log4Net.Async" version="2.0.4" targetFramework="net451" />
Web config
<dependentAssembly>
<assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0"/>
</dependentAssembly>
When I remove the log4net.async nuget package and add it again it works. But after some time I get this error again.

You (probably) need to add the assembly name to your appender reference.
<appender name="AsyncLog4NetAppender" type="Log4Net.Async.ParallelForwardingAppender,Log4Net.Async">
Note the part after the comma, Log4Net.Async.
Adding the name of the reference assembly should tell .Net how to find the class in the appropriate assembly.

Related

Microsoft.Data.Services version issue while running WCF Data Services

I am getting the following error:
Could not load file or assembly 'Microsoft.Data.Services, Version=5.6.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
But when I go and check my Packages.config:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net472" />
<package id="Microsoft.Data.Edm" version="5.6.4" targetFramework="net472" />
<package id="Microsoft.Data.OData" version="5.6.4" targetFramework="net472" />
<package id="Microsoft.Data.Services" version="5.6.4" targetFramework="net472" />
<package id="Microsoft.Data.Services.Client" version="5.6.4" targetFramework="net472" />
<package id="Microsoft.OData.EntityFrameworkProvider" version="1.0.0-beta2" targetFramework="net472" />
<package id="System.Spatial" version="5.6.4" targetFramework="net472" />
</packages>
It showing me above file, Do I need to change the version ? If yes then how I can change it? I tried through nugget it didn't work.
I checked in my C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\bin\plugins\Diagnostics there are 5.6.2 version dlls are there, I replaced them with 5.6.4 but still getting the same error.
Update:
I updated below in my web.config:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Microsoft.Data.Services" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-5.6.2.0" newVersion="5.6.4.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2" />
</system.web>
It changes the output to:
Log showing me below issues:
Model1.ssdl(2,2) : error 0152: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.ThrowOnNonWarningErrors()
at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader.LoadItems(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths)
at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Loader..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, Boolean throwOnError, IDbDependencyResolver resolver)
at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection.Init(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths, Boolean throwOnError, IDbDependencyResolver resolver, DbProviderManifest&amp; providerManifest, DbProviderFactory&amp; providerFactory, String&amp; providerInvariantName, String&amp; providerManifestToken, Memoizer`2&amp; cachedCTypeFunction)
at System.Data.Entity.Core.Metadata.Edm.StoreItemCollection..ctor(IEnumerable`1 xmlReaders, IEnumerable`1 filePaths)
at System.Data.Entity.Core.Metadata.Edm.MetadataCache.LoadStoreCollection(EdmItemCollection edmItemCollection, MetadataArtifactLoader loader)
at System.Data.Entity.Core.Metadata.Edm.MetadataCache.&lt;&gt;c__DisplayClass5.&lt;&gt;c__DisplayClass7.&lt;GetMetadataWorkspace&gt;b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Data.Entity.Core.Metadata.Edm.MetadataCache.&lt;&gt;c__DisplayClass5.&lt;&gt;c__DisplayClass7.&lt;GetMetadataWorkspace&gt;b__4()
at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.LoadAndCheckItemCollection[T](Func`1 itemCollectionLoader)
at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.&lt;&gt;c__DisplayClass16.&lt;.ctor&gt;b__f()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at System.Lazy`1.get_Value()
at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace, Boolean required)
at System.Data.Entity.Core.Metadata.Edm.MetadataWorkspace.GetItemCollection(DataSpace dataSpace)
at System.Data.Entity.Core.Objects.ObjectContext.InitializeMappingViewCacheFactory(DbContext owner)
at System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory)
at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()
at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.ForceOSpaceLoadingForKnownEntityTypes()
at System.Data.Entity.DbContext.System.Data.Entity.Infrastructure.IObjectContextAdapter.get_ObjectContext()
at lambda_method(Closure , Object )
at System.Data.Services.Providers.DbContextHelper.GetObjectContext(Object o)
at System.Data.Services.Caching.MetadataCache`1.TryLookup(Type serviceType, Object dataContextInstance)
at System.Data.Services.Providers.BaseServiceProvider.LoadMetadata(Boolean skipServiceOperations)
at System.Data.Services.Providers.EntityFrameworkDataService`1.CreateInternalProvider(Object dataSourceInstance)
at System.Data.Services.DataService`1.CreateMetadataAndQueryProviders(IDataServiceMetadataProvider&amp; metadataProviderInstance, IDataServiceQueryProvider&amp; queryProviderInstance, Object&amp; dataSourceInstance, Boolean&amp; isInternallyCreatedProvider)
at System.Data.Services.DataService`1.CreateProvider()
at System.Data.Services.DataService`1.HandleRequest()
at System.Data.Services.DataService`1.ProcessRequestForMessage(Stream messageBody)
at SyncInvokeProcessRequestForMessage(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object instance, Object[] inputs, Object[]&amp; outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage5(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc&amp; rpc)
at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)</ExceptionString></Exception></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>262164</EventID><Type>3</Type><SubType Name="Information">0</SubType><Level>8</Level><TimeCreated SystemTime="2021-11-08T16:50:19.9963405Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{5ffbff76-6cbf-4bb1-a528-801615bf5b77}" /><Execution ProcessName="iisexpress" ProcessID="15812" ThreadID="8" /><Channel/><Computer>UOFL20-G0QBVN2</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Information"><TraceIdentifier>https://learn.microsoft.com/dotnet/framework/wcf/diagnostics/tracing/System-ServiceModel-Channels-MessageSent</TraceIdentifier><Description>Sent a message over a channel.</Description><AppDomain>/LM/W3SVC/3/ROOT-1-132808638175161639</AppDomain><Source>System.ServiceModel.Activation.HostedHttpContext+HostedRequestHttpOutput/42188773</Source><ExtendedData xmlns="http://schemas.microsoft.com/2006/08/ServiceModel/MessageTraceRecord"><MessageProperties><Encoder>ByteStreamMessageEncoder</Encoder><AllowOutputBatching>False</AllowOutputBatching></MessageProperties><MessageHeaders></MessageHeaders></ExtendedData></TraceRecord></DataItem></TraceData></ApplicationData></E2ETraceEvent><E2ETraceEvent xmlns="http://schemas.microsoft.com/2004/06/E2ETraceEvent"><System xmlns="http://schemas.microsoft.com/2004/06/windows/eventlog/system"><EventID>131085</EventID><Type>3</Type><SubType Name="Stop">0</SubType><Level>255</Level><TimeCreated SystemTime="2021-11-08T16:50:19.9963405Z" /><Source Name="System.ServiceModel" /><Correlation ActivityID="{5ffbff76-6cbf-4bb1-a528-801615bf5b77}" /><Execution ProcessName="iisexpress" ProcessID="15812" ThreadID="8" /><Channel/><Computer>UOFL20-G0QBVN2</Computer></System><ApplicationData><TraceData><DataItem><TraceRecord xmlns="http://schemas.microsoft.com/2004/10/E2ETraceEvent/TraceRecord" Severity="Stop"><TraceIdentifier>https://learn.microsoft.com/dotnet/framework/wcf/diagnostics/tracing/System-ServiceModel-Diagno
Error: The server encountered an error processing the request. See
server logs for more details
This issue comes into picture whenever there is any issue at WCF service.
So see more details about the issue, you need to includeexceptiondetailInfaults attribute to true in servicedebug tag.
<Service Behavior>
<Behavior Name="myServiceBehavior">
<servicedebug includeexceptiondetailinfaults="true" />
</Behavior>
</Service Behavior>
Either you can also add class attribute to the service class.
Could not load file or assembly 'Microsoft.Data.Services,
Version=5.6.2.0,Culture=neutral, PublicKeyToken=31bf3856ad364e35' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)
For this problem, first check what version of this dll you have in your output directory.Then
clean your solution
delete all obj and bin directories
uninstall this package from the whole solution
ensure to delete this file in GAC: &userprofile%.nuget\packages\microsoft.data.services - make sure to delete whole directory
now you can install from NuGet the required version

C# windows event viewer

I want to log the errors from my C# app in Windows Event Viewer using log4net with the EventLogAppender (the errors must be logged under the Application log)
I have a log4net.config class with this code
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a" />
</configSections>
<log4net>
<appender name="EventLogAppender" type="log4net.Appender.EventLogAppender">
<applicationName value="MySource" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="{%level} {%date} – %message%newline" />
</layout>
</appender>
<root>
<level value="DEBUG" />
<appender-ref ref="EventLogAppender" />
</root>
</log4net>
</configuration>
In AssemblyInfo I added the following line
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch=true)]
Then in my Program class
class Program
{
static log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
static void Main(string[] args)
{
string name=null;
try
{
Console.WriteLine("Name : " + name.ToString());
}
catch (NullReferenceException nullException)
{
log.Error("Name is NULL", nullException);
}
}
}
I have to mention that I used power shell to create a new EventLog called "MySource"
The problem is that I receive the following error:
log4net:ERROR Could not create Appender [EventLogAppender] of type [log4net.Appender.EventLogAppender]. Reported error follows.
System.TypeLoadException: Could not load type 'log4net.Appender.EventLogAppender' from assembly 'log4net, Version=2.0.8.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a'.
at System.Reflection.RuntimeAssembly.GetType(QCallAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive, ObjectHandleOnStack assemblyLoadContext)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at log4net.Util.SystemInfo.GetTypeFromString(Assembly relativeAssembly, String typeName, Boolean throwOnError, Boolean ignoreCase)
at log4net.Repository.Hierarchy.XmlHierarchyConfigurator.ParseAppender(XmlElement appenderElement)
log4net:ERROR Appender named [EventLogAppender] not found.
Latest version of log4net (2.0.8 as of today) is implementing .net standard 1.3: https://logging.apache.org/log4net/release/release-notes.html.
In .net standard 1.3 EventLogAppender is not supported: https://logging.apache.org/log4net/release/framework-support.html#netstandard-1.3
If you want to use EventLogAppender, you will have to switch to .net framework.

Could not load file or assembly System.Net, Version=2.0.5.0

I have an ASP.NET 4.5.2 application that loads the Microsoft.Azure.ActiveDirectory.GraphClient library. When it tries to connect, the following error occurs:
System.IO.FileNotFoundException: Could not load file or assembly 'System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference.
File Name: "System.Net, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e"
bei System.Data.Services.Client.UriResolver.ConvertToAbsoluteUri(Uri baseUri)
bei System.Data.Services.Client.UriResolver.ConvertToAbsoluteAndValidateBaseUri(Uri& baseUri, String parameterName)
bei System.Data.Services.Client.DataServiceContext..ctor(Uri serviceRoot, DataServiceProtocolVersion maxProtocolVersion, ClientEdmModel model)
bei Microsoft.Azure.ActiveDirectory.GraphClient.Extensions.DataServiceContextWrapper..ctor(Uri serviceRoot, DataServiceProtocolVersion maxProtocolVersion, Func`1 accessTokenGetter, IEnumerable`1 customTypeMappings)
bei Microsoft.Azure.ActiveDirectory.GraphClient.ActiveDirectoryClient..ctor(Uri serviceRoot, Func`1 accessTokenGetter,...
I have added a binding redirect to my web.config already:
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Net" publicKeyToken="7cec85d7bea7798e" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.0.5.0" newVersion="4.0.0.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
But the problem persists. What is wrong here?

Cannot Deplay Private SQL Server CE Winforms

I got some issues when trying to install the setup.exe. In the log it says 'the referenced assembly couldn't be found on the computer(HRESULT: 0x800736B3).
Stack:
bei System.Deployment.Internal.Isolation.IStore.GetAssemblyInformation(UInt32 Flags, IDefinitionIdentity DefinitionIdentity, Guid& riid)
bei System.Deployment.Internal.Isolation.Store.GetAssemblyManifest(UInt32 Flags, IDefinitionIdentity DefinitionIdentity)
bei System.Deployment.Application.ComponentStore.GetSubscriptionStateInternal(DefinitionIdentity subId)
bei System.Deployment.Application.SubscriptionStore.GetSubscriptionStateInternal(SubscriptionState subState)
bei System.Deployment.Application.SubscriptionState.Validate()
bei System.Deployment.Application.ComponentStore.CollectCrossGroupApplications(Uri codebaseUri, DefinitionIdentity deploymentIdentity, Boolean& identityGroupFound, Boolean& locationGroupFound, String& identityGroupProductName)
bei System.Deployment.Application.SubscriptionStore.CommitApplication(SubscriptionState& subState, CommitApplicationParams commitParams)
bei System.Deployment.Application.ApplicationActivator.InstallApplication(SubscriptionState& subState, ActivationDescription actDesc)
bei System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut, String textualSubId, String deploymentProviderUrlFromExtension, BrowserSettings browserSettings, String& errorPageUrl)
bei System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)
I've set everything I think. All the dlls are copied to the output dir. I've set the application to target x86.
app.config:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SqlServerCe.4.0" />
<add name="Microsoft SQL Server Compact Data Provider 4.0"
invariant="System.Data.SqlServerCe"
description=".NET Framework Data Provider for Microsoft SQL Server Compact"
type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>
</system.data>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SqlServerCe" publicKeyToken="89845dcd8080cc91" culture="neutral"/>
<bindingRedirect oldVersion="4.0.0.0-4.0.0.1" newVersion="4.0.0.1"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
Is there anything wrong? Or why do I still getting this issue?

NLog.Mongo and latest mongoDB C# driver not working

nLog does not work when I upgrade my project to the latest mongoDB Driver:
---> System.TypeInitializationException: The type initializer for 'NLog.Mongo.MongoTarget' threw an exception. ---> System.IO.FileLoadException: Could not load file or assembly 'MongoDB.Driver, Version=1.9.2.235, Culture=neutral, PublicKeyToken=f686731cfb9cc103' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
at NLog.Mongo.MongoTarget..cctor()
--- End of inner exception stack trace ---
at NLog.Mongo.MongoTarget..ctor()
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.ConstructorInfo.Invoke(Object[] parameters)
at NLog.Internal.FactoryHelper.CreateInstance(Type t)
It logs nothing. I am using a mongoDB target for nLog. I already posted an issue (https://github.com/loresoft/NLog.Mongo/issues/7). But maybe there is a way to solve it on my own.
Any suggestions?
The target works with official mongoDB driver versions before 1.9.
You can add an Assembly binding to your web.config
<runtime>
<dependentAssembly>
<assemblyIdentity name="MongoDB.Driver" publicKeyToken="f686731cfb9cc103" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.10.0.62" newVersion="1.10.0.62" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="MongoDB.Bson" publicKeyToken="f686731cfb9cc103" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.10.0.62" newVersion="1.10.0.62" />
</dependentAssembly>
</runtime>

Categories

Resources