AutoMapper is taking too much memory. I think it's a memory leak.
I'm using 11.0.1 version in .Net Core 6 framework.
I've profiled the project. Here are a couple of screenshots:
Memory Usage reaches up to 2 GB by the Web API
Any ideas as to why it is taking this much memory for around 400 mapping classes?
Here's the configuration of AutoMapper being applied from the static IServiceCollection class:
services.AddAutoMapper(
cfg => cfg.AddMaps("WebApi.Common"),
typeof(MapperProfile),
typeof(VendorProfile));
enter code here
I fixed it by configuring AutoMapper according to the latest documentation.
Below is the code that fixed this issue:
var mapperConfig = new MapperConfiguration(mc =>
{
mc.AddMaps("WebApi.Common");
mc.AddMaps("WebApi.Core");
});
IMapper mapper = mapperConfig.CreateMapper();
services.AddSingleton(mapper);
Previously, it was configured according to the documentation of an older version of AutoMapper.
Related
I'm trying to limit the amount of data sent to Application Insights in a .NET Core program. I'm attempting to follow the documention here which says I should use the UseAdaptiveSampling method. It has the rather cryptic instruction:
Use extension methods of TelemetryProcessorChainBuilder as shown below to customize sampling behavior.
However, it doesn't tell me where exactly this extension method lives. My code is as follows:
public AppInsightsStats(string appInsightsKey)
{
TelemetryConfiguration configuration = TelemetryConfiguration.CreateDefault();
configuration.InstrumentationKey = appInsightsKey;
telemetry = new TelemetryClient(configuration);
// Enable sampling since amount of logging is massive
var builder = configuration.DefaultTelemetrySink.TelemetryProcessorChainBuilder;
builder.UseAdaptiveSampling(maxTelemetryItemsPerSecond:5); // <-- Compiler error here
}
However, the code doesn't compile since UseAdaptiveSampling isn't found. I have the following using statements:
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
The source code I can dig up that uses UseAdaptiveSampling all seems to be .NET Framework 4.5 code, so I'm wondering if this just isn't included with the .NET Core version. These instructions are for ASP.NET Core, but I'm wondering if they mean running that on the .NET Framework on Windows.
For console project, you should use this package Microsoft.ApplicationInsights.WorkerService. It's used for non-http application like console project.
I used your code with this package, everything is ok. Please give it a try, and let me know if you still have the issue.
I'm working on enabling security transparency model in .NET Core code (on Linux). I've discovered that just enabling APPDOMAIN_SECURITY_SANDBOXED flag during AppDomain initialization is not enough. At least my P/Invoke
[DllImport("/usr/lib/libc.so.6")]
private static int system(string path);
call hasn't blocked.
Could anyone help with this?
.NET Core does not support AppDomains or sandboxing:
Free of problematic tech. .NET Core doesn’t include certain technologies we decided to discontinue because we found them to be problematic, for instance AppDomain and sandboxing. If the scenario still makes sense for .NET Core, our plan is to have replacements. For example, AssemblyLoadContext replaces AppDomains for loading and isolating assemblies.
I cant find a method since I upgraded the Azure storage dlls.
The static method I cant find is: CloudTableClient.CreateTablesFromModel
The old class:
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.cloudtableclient_methods.aspx
This is the new class:
http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storage.table.cloudtableclient_methods.aspx
I did some searching but couldn't find a word about this being replaced or deleted.
Does anybody have an idea?
Storage client library 2.0 is quite different from the previous version and a number of methods have been removed in the newer version. This method is one of them. If you look under the remarks section on this page: http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.storageclient.cloudtableclient.createtablesfrommodel.aspx, it is recommended that you not use this method.
Since these 2 versions are quite different, it is recommended that you read up the following blog posts from the storage team before upgrading your code to use the latest version:
http://blogs.msdn.com/b/windowsazurestorage/archive/2012/10/29/introducing-windows-azure-storage-client-library-2-0-for-net-and-windows-runtime.aspx
http://blogs.msdn.com/b/windowsazurestorage/archive/2012/10/29/windows-azure-storage-client-library-2-0-breaking-changes-amp-migration-guide.aspx
http://blogs.msdn.com/b/windowsazurestorage/archive/2012/11/06/windows-azure-storage-client-library-2-0-tables-deep-dive.aspx
I also wrote a blog post about migrating code from storage client library 1.7 to 2.0 which you can read here: http://gauravmantri.com/2012/11/17/storage-client-library-2-0-migrating-table-storage-code/
I have a fairly stable server application version that's been deployed for nearly a year at dozens of customers.
One new customer recently setup the application and is getting the following error:
System.MethodAccessException: Attempt by security transparent method
[SomeMethod] to access security critical method [SomeOtherMethod]
failed.
Both SomeMethod and SomeOtherMethod are methods in assemblies that I wrote, that are built against .NET 4, and that are running inside a Windows Service. If it makes a difference, SomeOtherMethod does reference a type from a 3rd party assembly (EntLib 4.1) built against .NET 2.0. Looking at the code for EntLib 4.1, I do see that they use both SecurityTransparent and APTC attributes, but this has never caused issues at other clients.
These assemblies were upgraded from the .NET 2.0 CLR, but a long time ago. This exact code is running on other customers just fine, and I'm not explicitly using the APTC attribute nor am I using the SecurityCritical attribute anywhere.
This leads me to the conclusion that it's a configuration issue or perhaps .NET Framework patch issue. Has there been a patch released for .NET that would cause this breaking change? Is there a configuration setting some where that enforces this type of check which is off by default but that my customer may have enabled?
One last point. My service utilizes SSRS RDLCs to generate PDFs. Due to some changes in .NET 4, I must force the service to use the legacy security policy via the following config:
<runtime>
<NetFx40_LegacySecurityPolicy enabled="true" />
</runtime>
For more details on why I need to do this, see this stackoverflow post: Very High Memory Usage in .NET 4.0
The important point is that I do this at all my other customers as well. Only this one customer is having issues.
Sigh, the patterns and practices employed by the Microsoft Patterns And Practices team that's responsible for the Enterprise libraries are pretty deplorable. Well, the exception is accurate, you cannot call a method that's decorated as "I'll definitely check security" from code that's decorated with "Meh, I won't check security so don't bother burning the cpu cycles to check it". Which scales about as well as exception specifications as used in Java. CAS is incredibly useful, but diagnosing the exceptions is a major headache and often involves code that you don't own and can't fix. Big reason it got deprecated in .NET 4.
Editorial done. Taking a pot-shot at the problem, you need to find out why CAS is being enforced here. The simplest explanation for that is that the service doesn't run in full trust. The simplest explanation for that is that the client didn't install the service on the local hard drive. Or is generally running code in don't-trust-it mode even on local assemblies, a very paranoid admin could well prefer that. That needs to be configured with Caspol.exe, a tool whose command line options are as mysterious as CAS. Pot-shooting at the non-trusted location explanation, your client needs to run Caspol as shown in this blog post. Or just simply deploy the service locally so the default "I trust thee" applies.
Editing in the real reason as discovered by the OP: beware of the alternate data stream that gets added to a file when it is downloaded from an untrusted Internet or network location. The file will get a stream named "Zone.Identifier" that keeps track of where it came from with the "ZoneId" value. It is that value that overrides the trust derived from the storage location. Usually putting it in the Internet zone. Use Explorer, right-click the file and click "Unblock" to remove that stream. After you're sure you can trust the file :)
I was facing the similar issue while running the downloaded WCF sample from http://www.idesign.net/ while using their ServiceModelEx library.
I commented out the below line in AssemblyInfo.cs in ServiceModelEx project
//[assembly: AllowPartiallyTrustedCallers]
and it worked for me.
In case it helps others i post my solution for this issue:
1) On the AssemblyInfo.cs, removed/commented the [assembly: SecurityTransparent] line.
2) The Class and the Method that does the actual Job was marked as [SecuritySafeCritical], in my case establishing a Network Connection:
[SecuritySafeCritical]
public class NetworkConnection : IDisposable
{
[SecuritySafeCritical]
public NetworkConnection(string networkName, NetworkCredential credentials)
{
.............
}
}
3) The Caller Class and Method was market as [SecurityCritical]:
[SecurityCritical]
public class DBF_DAO : AbstractDAO
{
[SecurityCritical]
public bool DBF_EsAccesoExclusivo(string pTabla, ref ArrayList exepciones)
{
....
using (new NetworkConnection(DBF_PATH, readCredentials))
{
....
}
}
}
In my case it was an issue when I managed a NuGet packages in the solution some package overrides System.Web.Mvc assembly version binding in main web site project. Set back to 4.0.0.0 (I had 5.0 installed). I didn't change notice the change because Mvc v4.0 was installed and accessible via GAC. Set back
Basics:
Visual Studio 2010
WP7 SDK 7.1 RC
AutoMapper added to project via NuGet
Ask for more!
Problem:
I'm getting the following error at runtime:
Could not load type 'AutoMapper.Mapper' from assembly 'AutoMapper, Version=1.1.0.188, Culture=neutral, PublicKeyToken=BE96CD2C38EF1005'.
There seems to be an open issue about this # CodePlex, but i thought that i'd ask if anyone has found any solutions to this?
As always, i'm more than happy to provide any additional info required!
AutoMapper uses Castle Dynamic Proxy which requires Reflection.Emit which is not supported on the phone.
If you want this you're going to need to look at building it all yourself. In terms of getting round the lack of reflection.Emit (if you really do need it) then you should look at using Mono.Cecil to provide this missing functionality.
Seems that automapper is working on silverlight edition so possible WP7/WP8 compatibility coming soon.
In the mean time there is a simple mapper library that you can use. It is very basic but probably meets most of your requirements for WP7 applications.
// Configure LazyMapper
Mapper.Create<SampleClass, SampleClassDto>();
// Perform mapping
var dto = Mapper.Map<SampleClass, SampleClassDto>(new SampleClass {
StringVal = "String1"});
Assert.AreEqual("String1",dto.StringVal);
Download at http://lazycowprojects.tumblr.com/LazyMapper