title: Attempted To Read Or Write Protected Memory. This Is Often An Indication That Other Memory Is Corrupt In Sharpdx
body: <p>I have a Sharpdx Program and I'm trying to initialize a RenderTarget to draw on a RenderForm
  Here is my Code</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using SharpDX;
  using SharpDX.Direct2D1;
  using SharpDX.Direct3D;
  using SharpDX.Direct3D11;
  using SharpDX.DXGI;
  using AlphaMode = SharpDX.Direct2D1.AlphaMode;
  using Factory = SharpDX.Direct2D1.Factory;
  using FeatureLevel = SharpDX.Direct2D1.FeatureLevel;
  
  namespace Proto_Engine
  {
      class D2DX11
      {
          SharpDX.Direct3D11.Device _device;
          SwapChain _swapChain;
          public Factory Factory2D { get; private set; }
          public SharpDX.DirectWrite.Factory FactoryDWrite { get; private set; }
          public RenderTarget RenderTarget2D { get; private set; }
          private Surface _surface;
          public D2DX11() { }
          public void Initialize(DSystemConfiguration configuration, IntPtr windowHandle)
          {
              var desc = new SwapChainDescription()
              {
                  BufferCount = 1,
                  ModeDescription =
                      new ModeDescription(configuration.Width,
                                          configuration.Height,
                                          new Rational(60, 1),
                                          Format.R8G8B8A8_UNorm),
                  IsWindowed = true,
                  OutputHandle = windowHandle,
                  SampleDescription = new SampleDescription(1, 0),
                  SwapEffect = SwapEffect.Discard,
                  Usage = Usage.RenderTargetOutput
              };
              SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, desc, out _device, out _swapChain);
  
              Factory factory = _swapChain.GetParent&lt;Factory&gt;();
  
              // New RenderTargetView from the backbuffer
  
              Factory2D = new Factory();
              _surface = Texture2D.FromSwapChain&lt;Texture2D&gt;(_swapChain, 0).QueryInterface&lt;Surface&gt;();
              RenderTarget2D = new RenderTarget(Factory2D,
                                                  _surface,
                                                  new RenderTargetProperties(new PixelFormat(Format.Unknown, AlphaMode.Premultiplied)));
  
              RenderTarget2D.AntialiasMode = AntialiasMode.PerPrimitive;
  
              FactoryDWrite = new SharpDX.DirectWrite.Factory();
  
              RenderTarget2D.DrawRectangle(new SharpDX.Mathematics.Interop.RawRectangleF(0, 1, 1, 0), new SolidColorBrush(RenderTarget2D, new SharpDX.Mathematics.Interop.RawColor4(1, 0, 0, 1)));
          }
      }
  }
  </code></pre>
  <p>This Is Causing the Issue</p>
  <pre><code>SharpDX.Direct3D11.Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.BgraSupport, new[] { SharpDX.Direct3D.FeatureLevel.Level_10_0 }, desc, out _device, out _swapChain);
  </code></pre>
  <p>I'm Getting This Error</p>
  <pre><code>Attempted To Read Or Write Protected Memory.  This Is Often An Indication That Other Memory Is Corrupt
  </code></pre>
  <p>I've been working on This for weeks but I Am mostly working On the 3d Aspect of it So I'm trying to implement 2D rendering to create UI. I'm getting the IntPtr windowhandle fro my Renderform and DSystemConfiguration is a custom class that I created</p>