Posts

Showing posts from June, 2020

C# .NET Remoting shows error System.Security.SecurityException. Type System.DelegateSerializationHolder and the types derived from it (such as System.DelegateSerializationHolder) are not permitted to be deserialized at this security level.

When using .NET Remoting you may see the following error: System.Security.SecurityException.  Type System.DelegateSerializationHolder and the types derived from it (such  as System.DelegateSerializationHolder) are not permitted to be deserialized  at this security level.  System.Runtime.Serialization.SerializationException A lot of comments on the Internet point to the following to change your security level. https://docs.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.typefilterlevel?view=netcore-3.1 However if this is the first time that you've seen this error it maybe because you've introduced something inadvertantly that breaches the security requirements of the default low security level and it would be safer to remove that issue instead of reducing your security. For me I found that we'd implemented the INotifyPropertyChanged interface on a class. This defines the PropertyChanged event, and this then breaks your security model. /// <summar

C#.NET Suppress Trace Messages From Specific "noisy" DLL

We've recently had a problem with the .NET diagnostics trace listeners. These allow you to easily write diagnostics information to, for example, a text file. However these are static methods so when you use 3rd party DLLs you may find that your nice simple trace messages suddently become "hijacked" by a "noisy" DLL. It's very hard to separate the source of the Trace.WriteLine() call without pulling up stack traces which can impact performace. Here's a simple workaround where you can use the category to exclude messages from elsewhere. Create a method which calls Trace.WriteLine() for you which passes a GUID so you know it has been called from your class. /// <summary> /// Provides the ability to log diagnostics information to the system trace log. /// </summary> public class DiagnosticsSupport {     /// <summary>     /// Writes the specified message to the diagnostics trace log.          /// </summary>      /// <