Xna: problem loading effect, "Attempt to read or write protected memory. Often this condition indicates that other parts of the memory are damaged"

Hi guys, I’m having a problem assigning a file to the effect variable, when I try to assign a value to the effect variable it gives me the error(“Attempt to read or write protected memory. Often this condition indicates that other parts of the memory are damaged”), in the second photo you can see in the commented part another way to assign it indirectly from the file but the error is always in the assignment to the variable, I just took a cue from this site: http://gmjosack.github.io/posts/my-first-2d-pixel-shaders-part-1/; I leave you some photos to be able to see the code well:

Kind of a parallel question, but are you using FNA or Monogame?

The problem I think is that I first installed fna and I started my project, then I thought of installing monogame but since I had already created the project I think I have not installed it well, you know a guide on how to install it on a project already created ?

Okay I had monogame to my project, it give me same error in both ways: using load.content and using the other method in the photo:

When using the content manager to load the effect, I see you include the extension “.fx” in the name. That isn’t needed, and wont’ load the effect. Do you get a different error if you change that?

Adding monogame now gives me the same error adding or not the extension, before adding it it gave me the same error but without adding it it told me that it could not find the file

I’m pretty sure the issue is that you’re not building the effect correctly through the Content Pipeline. Once you build the .fx file, it will spit out an .xnb of the shader. Then you simply use a line like this to load:

        Effect effect = content.Load<Effect>("Effect1");

You should not use File.ReadAllLines, or load the .fx file directly (which seems to be what you’re doing based on the screenshots).

Yhea I know but even doing so in my project gives the same error, in fact I tried to make a new project where I immediately installed monogame and it works perfectly there, for example in the tutorial series you have not used or added to the monogame project, therefore like the did you add light? (sorry for my english, it’s google translator xD)

LOL no worries. In the tutorial series I’m using FNA, but I’ve used Effect files in FNA and MonoGame and it works the same in both cases. The code from the video series should directly translate to MonoGame, so if you want to make the switch to utilize the Content Pipeline it shouldn’t be much effort.

I will let you know as soon as I find, if I find it, the origin of the error, thank you so much for your time

Thanks to all the guys for the help, I recreated the project with monogame installed as a template and I “implemented” all my code and now it goes perfectly!

Thanks to all the guys for the help, I recreated the project with monogame installed as a template and I “implemented” all my code and now it goes perfectly!!!