Converting VB code from XNA 3.1 to MonoGame.
Any attempt to access class GraphicsAdapter throws the exception below. For example, trying to enumerate GraphicsAdapters. On this line:
For Each adapter As GraphicsAdapter In GraphicsAdapter.Adapters
Result is an exception:
System.TypeInitializationException occurred
HResult=-2146233036
Message=The type initializer for 'Microsoft.Xna.Framework.Graphics.GraphicsAdapter' threw an exception.
Source=MonoGame.Framework
TypeName=Microsoft.Xna.Framework.Graphics.GraphicsAdapter
StackTrace:
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter.get_Adapters()
at ...my code...
InnerException:
HResult=-2146233054
Message=Could not load type 'SharpDX.Rectangle' from assembly 'SharpDX, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1'.
Source=MonoGame.Framework
TypeName=SharpDX.Rectangle
StackTrace:
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter.CreateAdapter(Adapter1 device, Output monitor)
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter.PlatformInitializeAdapters(ReadOnlyCollection`1& adapters)
at Microsoft.Xna.Framework.Graphics.GraphicsAdapter..cctor()
Note the inner exception:
Could not load type 'SharpDX.Rectangle' from assembly 'SharpDX, Version=4.0.1.0, ...
The project references these assemblies (among others):
- MonoGame.Framework version=3.6.0.1625
from NuGet “MonoGame.Framework.WindowsDX”, file
packages\MonoGame.Framework.WindowsDX.3.6.0.1625\lib\net40\MonoGame.Framework.dll - SharpDX version=4.0.1.0
- SharpDX.Direct2D1 version=4.0.1.0
- SharpDX.Direct3D9 version=4.0.1.0
- SharpDX.DXGI version=4.0.1.0
- SharpDX.Mathematics version=4.0.1.0
So I don’t see why it would fail this way.
What could be wrong? Not compatible with this SharpDX version?
NOTE: These are all up-to-date packages from NuGet, in Visual Studio 2015. Targeting .Net 4.5.2.
UPDATE
To prove it isn’t a problem with SharpDX, I put this line before that GraphicsAdapter line:
Dim testRect As SharpDX.Rectangle = New Rectangle()
This successfully created testRect
. No Exception until attempt to access GraphicsAdapter
. Also tried all the other Shared (static) properties of GraphicsAdapter
, such as GraphicsAdapter.DefaultDevice
. Any one fails with same exception.
SOLVED
(from teamcity) MonoGameSetup.exe v.3.7.0.994
works with SharpDX 4.0.1
.
However, the list of SharpDX dlls in C:\Program Files (x86)\MonoGame\v3.0\Assemblies\Windows
is missing SharpDX.Mathematics.dll
; I used the NuGet version of SharpDX instead.