-1

I installed PropertyChanged.Fody into a WPF application. Now 3rd party code that uses native memory are having memory allocation issues. Uninstalling PropertyChanged.Fody resolves all these issues. I thought that the package was causing property changed injection into classes in those assemblies so I added a [assembly: PropertyChanged.FilterType("My.Specific.OptIn.Namespace.")] the project I installed fody in to make injection opt-in. Note that I left the filter attribute exactly as I just wrote it so that nothing at all matches, just to test. Still having issues however.

Sheldon Cooper
  • 577
  • 2
  • 14
  • Please be specific on what the "memory allocation issues" are. For all we know you might have a completely different issue that just so happens to trigger this problem. I can actually think of a few reasons why that would happen, but clarity and a bit more explanation would help get you an answer. – Kodaloid Oct 07 '20 at 11:19
  • The reason for the obscurity is that there isn't much more that I know. There is a method on the 3rd party API interface called CaptureImage() and another method called GetImage(). When PropertyChanged.Fody is added, a call to GetImage returns an OutOfMemoryException. – Sheldon Cooper Oct 07 '20 at 13:39
  • For anyone else that thinks there's too little info and can "think of a few reasons why that would happen", please state the reasons. While I would love to provide more information, this is literally all I have. – Sheldon Cooper Oct 07 '20 at 14:29
  • Let me clarify, you said that 3rd party code is having memory allocation issues, but how you know that? If you've seen something in an error box, we need to know exactly what that error said verbatim. If it's a theory, then also let us know so we can correctly work through process of elimination. Point is, there is missing information in your question which leaves too much for guess work. – Kodaloid Oct 08 '20 at 00:55
  • Calls to 3rd party API cause the debugger to pause with various errors 1. "Bad allocation" 2. "OutOfMemoryException" 3. "No image found" – Sheldon Cooper Oct 08 '20 at 03:10

1 Answers1

0

After days of debugging I've finally found the issue. My project is set to ANYCPU and Prefer 32 which by default allows it to access more RAM. Fody does not respect this and leads to a normal 32bit assembly that can only access 2GB of RAM.

Before (ANYCPU + Prefer 32): enter image description here

After (with Fody): enter image description here

My solution was to use the Large Address Aware NuGet package (the target in the package only runs if you change your Platform Target to x86, in my case I changed from ANYCPU + Prefer32 to simply x86). I configured my .csproj to look like this:

 <PropertyGroup>
   <LargeAddressAware>true</LargeAddressAware>
   <LargeAddressAwareAfterTargets>FodyTarget</LargeAddressAwareAfterTargets>
 </PropertyGroup>

I've alerted the contributers of PropertyChanged.Fody to this issue.

Sheldon Cooper
  • 577
  • 2
  • 14