So I've written my own game class, which is initialized like so (BTW, this is F# not C#):
static member RunGame() =
use engine = new Root()
// For now, always use OpenGL
engine.RenderSystem <- engine.RenderSystems.["OpenGL"]
use renderWindow = engine.Initialize(true)
let game = new Game(engine, renderWindow)
game.Load()
engine.FrameStarted.Add(game.HandleInput)
engine.FrameRenderingQueued.Add(game.OnRenderFrame)
engine.StartRendering() // The error is thrown somewhere inside here
game.Unload()
and this is simply how I try to shut the system down:
static member this.HandleInput(e: FrameEventArgs) =
input.Capture()
if input.IsKeyPressed(KeyCodes.Escape) then
root.Shutdown
root is the first argument in the constructor, so it is the same object as engine in the first sample. Here's the full error:
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Axiom
StackTrace:
at Axiom.Graphics.RenderTarget.Update(Boolean swapBuffers)
at Axiom.Graphics.RenderSystem.UpdateAllRenderTargets(Boolean swapBuffers)
at Axiom.Core.Root.UpdateAllRenderTargets()
at Axiom.Core.Root.RenderOneFrame()
at Axiom.Core.Root.StartRendering()
at MiningGameTest.Game.RunGame() in H:\Projects\FSharp\MiningGameTest\MiningGameTest\Game.fs:line 22
at MiningGameTest.Host.Axiom.Program.Main(String[] args) in h:\Projects\FSharp\MiningGameTest\MiningGameTest.Host.Axiom\Program.cs:line 14
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
And one more thing: not sure if this has anything to do with it, but I've also been getting the following errors immediately when the project launches:
A first chance exception of type 'System.DllNotFoundException' occurred in FreeImageNET.dll
A first chance exception of type 'System.DllNotFoundException' occurred in OpenTK.dll
A first chance exception of type 'System.TypeInitializationException' occurred in OpenTK.dll
A first chance exception of type 'System.DllNotFoundException' occurred in OpenTK.dll
A first chance exception of type 'System.NullReferenceException' occurred in Axiom.dll
Am I doing something wrong or is this an Axiom bug?
PS: I'm running under Windows 8 and Visual Studio 2012 Professional using the OpenGL render system.
Related
I'm attempting to use CryptUnprotectData to read a password protected using CryptProtectData into a SecureString and use that to connect to a database. I can get the correct password out, but trying to create a new SqlConnection after that fails with the following:
System.TypeInitializationException was unhandled
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlConnection
StackTrace:
at System.Data.SqlClient.SqlConnection..ctor()
at System.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential)
at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
at ProtectedSqlTest.Program.Main() in C:\Git\ProtectedSqlTest\ProtectedSqlTest\Program.cs:line 16
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlConnectionFactory
StackTrace:
at System.Data.SqlClient.SqlConnection..cctor()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlPerformanceCounters
StackTrace:
at System.Data.SqlClient.SqlConnectionFactory..cctor()
InnerException:
HResult=-2147024809
Message=The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))
Source=mscorlib
StackTrace:
at System.Globalization.TextInfo.InternalChangeCaseString(IntPtr handle, IntPtr handleOrigin, String localeName, String str, Boolean isToUpper)
at System.Globalization.TextInfo.ToLower(String str)
at System.String.ToLower(CultureInfo culture)
at System.Diagnostics.PerformanceCounterLib.GetPerformanceCounterLib(String machineName, CultureInfo culture)
at System.Diagnostics.PerformanceCounterLib.IsCustomCategory(String machine, String category)
at System.Diagnostics.PerformanceCounter.InitializeImpl()
at System.Diagnostics.PerformanceCounter.set_RawValue(Int64 value)
at System.Data.ProviderBase.DbConnectionPoolCounters.Counter..ctor(String categoryName, String instanceName, String counterName, PerformanceCounterType counterType)
at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)
at System.Data.SqlClient.SqlPerformanceCounters..ctor()
at System.Data.SqlClient.SqlPerformanceCounters..cctor()
InnerException:
It's enough to simply call CryptUnprotectData for the SqlConnection to fail, the connection itself doesn't need to use the returned SecureString.
I'm using the extension methods from here as described in this post for my minimal repro:
class Program
{
const string ProtectedSecret = /* SNIP - base 64 encoded protected data here */;
static void Main()
{
// calling AppendProtectedData breaks the following SqlConnection
// without the following line the application works fine
new SecureString().AppendProtectedData(Convert.FromBase64String(ProtectedSecret));
using (var conn = new SqlConnection("Server=(localdb)\\MSSqlLocalDb;Trusted_Connection=true"))
using (var cmd = new SqlCommand("select 1", conn))
{
conn.Open();
cmd.ExecuteNonQuery();
}
}
}
If i create a new SqlConnection before I load the password, I can create new SqlConnections fine for the duration of the application as it seems to use the same SqlConnectionFactory, but that means as a workaround I have to do something like this at the start of the application:
new SqlConnection().Dispose();
... which I'd like to avoid.
The following do not help:
Debug vs Release build
Debugging in Visual Studio vs running through the command line
Changing the CryptProtectFlags that is passed to CryptUnprotectData.
Removing RuntimeHelpers.PrepareConstrainedRegions() from the protection method.
Windows 10, VS Enterprise 2015, Console Application (.NET 4.6.1)
UPDATE: Running the data protection code in another threads gives a similar exception with a different root cause:
System.TypeInitializationException was unhandled
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlConnection' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlConnection
StackTrace:
at System.Data.SqlClient.SqlConnection..ctor()
at System.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential)
at System.Data.SqlClient.SqlConnection..ctor(String connectionString)
at ProtectedSqlTest.Program.Main() in C:\Git\ProtectedSqlTest\ProtectedSqlTest\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlConnectionFactory' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlConnectionFactory
StackTrace:
at System.Data.SqlClient.SqlConnection..cctor()
InnerException:
HResult=-2146233036
Message=The type initializer for 'System.Data.SqlClient.SqlPerformanceCounters' threw an exception.
Source=System.Data
TypeName=System.Data.SqlClient.SqlPerformanceCounters
StackTrace:
at System.Data.SqlClient.SqlConnectionFactory..cctor()
InnerException:
BareMessage=Configuration system failed to initialize
HResult=-2146232062
Line=0
Message=Configuration system failed to initialize
Source=System.Configuration
StackTrace:
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
at System.Configuration.ConfigurationManager.GetSection(String sectionName)
at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
at System.Diagnostics.DiagnosticsConfiguration.Initialize()
at System.Diagnostics.DiagnosticsConfiguration.get_SwitchSettings()
at System.Diagnostics.Switch.InitializeConfigSettings()
at System.Diagnostics.Switch.InitializeWithStatus()
at System.Diagnostics.Switch.get_SwitchSetting()
at System.Data.ProviderBase.DbConnectionPoolCounters..ctor(String categoryName, String categoryHelp)
at System.Data.SqlClient.SqlPerformanceCounters..ctor()
at System.Data.SqlClient.SqlPerformanceCounters..cctor()
InnerException:
HResult=-2147024809
Message=Item has already been added. Key in dictionary: 'MACHINE' Key being added: 'MACHINE'
Source=mscorlib
StackTrace:
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Collections.Hashtable.Add(Object key, Object value)
at System.Configuration.Internal.InternalConfigRoot.GetConfigRecord(String configPath)
at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
InnerException:
Interestingly the faulting code is:
internal static PerformanceCounterLib GetPerformanceCounterLib(string machineName, CultureInfo culture) {
SharedUtils.CheckEnvironment();
string lcidString = culture.LCID.ToString("X3", CultureInfo.InvariantCulture);
if (machineName.CompareTo(".") == 0)
machineName = ComputerName.ToLower(CultureInfo.InvariantCulture);
else
machineName = machineName.ToLower(CultureInfo.InvariantCulture);
...
the line that calls ComputerName.ToLower(CultureInfo.InvariantCulture) causes the exception.
You can reproduce the same behavior just calling code
new SecureString().AppendProtectedData(Convert.FromBase64String(ProtectedSecret));
string lower = "Something".ToLower(CultureInfo.InvariantCulture);
Somehow in the constructor of the TextInfo class
this.m_dataHandle = CompareInfo.InternalInitSortHandle(m_textInfoName, out handleOrigin);
returns invalid data if this is not called before CryptUnprotectData function.
This seems like a bug in the framework. You can submit it to Microsoft. In the meantime you can call this line beforehand to prevent the error.
"".ToLower(CultureInfo.InvariantCulture);
I was recently experiencing similar symptoms, using the same code from http://www.griffinscs.com/?p=12: any call to CryptUnprotectData would lead to an exception in some unrelated code. Interestingly, the failure only occurred on a Windows 10 machine; the same code worked fine on a Windows 7 machine.
I fixed the problem by changing the declarations of the szDataDescr parameters in both CryptProtectData and CryptUnprotectData from string to IntPtr, and passing IntPtr.Zero instead of string.Empty in the two calls.
I have a solution that utilises Grapevine to start a server within the Program class.
For some reason though, as soon as I start the program, it crashes when server.Start() is called.
No other parts of the solution are running at this point, so I don't know how that could be happening?
Running in Visual Studio 15, as Administrator, on Windows 10.
Program.cs
using System;
using System.Threading;
using Grapevine.Server;
using QuantConnect.Logging;
namespace QuantConnect.Services
{
class Program
{
/// <summary>
/// QuantConnect C# Services Server:
/// </summary>
static void Main(string[] args)
{
var server = new RESTServer
{
//Host = Configuration.Config.Get("grapevine-host"),
//Port = Configuration.Config.Get("grapevine-port")
Host = Configuration.Config.Get("grapevine-host", "localhost"),
Port = Configuration.Config.Get("grapevine-port", "80")
};
Log.Trace(string.Format("Starting Server On {0}:{1}", server.Host, server.Port));
server.Start(); // Exception occurs here
while (server.IsListening)
{
Thread.Sleep(300);
}
Log.Trace("Server stopped. Press key to continue...");
Console.ReadLine();
}
}
}
Error and stacktrace:
An unhandled exception of type 'System.Net.HttpListenerException' occurred in Grapevine.dll
System.Net.HttpListenerException was unhandled
ErrorCode=32
HResult=-2147467259
Message=The process cannot access the file because it is being used by another process
NativeErrorCode=32
Source=System
StackTrace:
at System.Net.HttpListener.AddAllPrefixes()
at System.Net.HttpListener.Start()
at Grapevine.Server.RESTServer.Start()
at QuantConnect.Services.Program.Main(String[] args) in C:\Users\RichardsPC\Source\Repos\Lean\Services\Program.cs:line 29
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
So I figured out what the issue was.
I set Grapevine to use port 80.
Port = Configuration.Config.Get("grapevine-port", "80")
Issue was that there was another service on my machine using this port, I changed it to use 8080 and it works fine now.
Port = Configuration.Config.Get("grapevine-port", "8080")
I am trying to create a eventhandler for a msmq message router and I almost just copied a online example from msdn library
example 2.
But when I invoke messageQueue.BeginReceive() I get a IllegalFormatName exception.
I am using a private queue
Using VS 2015 on windows 10
Solution is using .Net 4.5.2
I got no problems sending messages to any of my private queues or reading from them if I use messageQueue.Receive()
Exception details below:
System.Messaging.MessageQueueException was unhandled
ErrorCode=-2147467259 HResult=-2147467259 Message=Formatnavnet er
ugyldigt. Source=System.Messaging StackTrace:
ved System.Messaging.MessageQueue.MQCacheableInfo.get_ReadHandle()
ved System.Messaging.MessageQueue.ReceiveAsync(TimeSpan timeout, CursorHandle cursorHandle, Int32 action, AsyncCallback
callback, Object stateObject)
ved System.Messaging.MessageQueue.BeginReceive()
ved MYFirstMSMQ.Program.Main(String[] args) in ......Visual Studio 2015\Projects\FirstQueue_bluff_city\ConsoleApplication1\Program.cs:linje
68
ved System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
ved System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
ved Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
ved System.Threading.ThreadHelper.ThreadStart_Context(Object state)
ved System.Threading.ExecutionContext.RunInternal(ExecutionContext
executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
ved System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean
preserveSyncCtx)
ved System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
ved System.Threading.ThreadHelper.ThreadStart() InnerException:
Sorry about the Message - windows returns some messages in my native language
I've been having problems with I code I wrote. What this code does is download a picture from my server and puts it inside a PDF document. I've narrowed it down to a problem with the image being downloaded.
At first, I thought it was a problem with my project so I've created a new Console Application with just that code to test it out - but that happens on it as well.
What I'm trying to do is simple - download a picture with WebClient and save it to the disk:
WebClient oWebClient = new WebClient();
byte[] oImageBytes = oWebClient.DownloadData("http://images1.ynet.co.il/PicServer3/2013/12/25/5058381/505838001000100396220.jpg");
ImageConverter oConverter = new ImageConverter();
Image oImg = (Image)oConverter.ConvertFrom(oImageBytes);
oImg.Save("d:\\temp\\1.jpg");
The image url in the example is taken from a local news site and fails as well.
The very strange thing is that on windows 7 and earlier it works. It fails on Windows8 and Windows Server 2012 with the following error:
An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in System.Drawing.dll
Additional information: A generic error occurred in GDI+.
This is the StackTrace:
at System.Drawing.Image.Save(String filename, ImageCodecInfo encoder, EncoderParameters encoderParams)
at System.Drawing.Image.Save(String filename, ImageFormat format)
at System.Drawing.Image.Save(String filename)
at ConsoleApplication1.Program.Main(String[] args) in c:\Users\Ophir\Documents\Visual Studio 2013\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs:line 23
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
I've tried searching the web, but all solutions I found didn't work in my case.
The directory that I'm trying to save to has sufficient permissions.
Anyone has any idea to why this is happening ?
Thanks
What about to save data as is?
byte[] oImageBytes = oWebClient.DownloadData("http://images1.ynet.co.il/PicServer3/2013/12/25/5058381/505838001000100396220.jpg");
File.WriteAllBytes("d:\\temp\\1.jpg", oImageBytes);
I downloaded Windows® API Code Pack for Microsoft® .NET Framework from
http://code.msdn.microsoft.com/WindowsAPICodePack/Release/ProjectReleases.aspx?ReleaseId=3077
ERROR
On testing the solution on VS 2008,I get error in line
IKnownFolderManager knownFolderManager = (IKnownFolderManager)new KnownFolderManagerClass();
knownFolderManager.GetFolderIds(out folders, out count);
DETAILS BELOW,
System.Runtime.InteropServices.COMException was unhandled
Message="Retrieving the COM class factory for component with CLSID {4DF0C730-DF9D-4AE3-9153-AA6B82E9795A} failed due to the following error: 80040154."
Source="Microsoft.WindowsAPICodePack.Shell"
ErrorCode=-2147221164
StackTrace:
at Microsoft.WindowsAPICodePack.Shell.KnownFolders.GetAllFolders() in D:\WindowsAPICodePack\WindowsAPICodePack\Shell\KnownFolders\KnownFolders.cs:line 43
at Microsoft.WindowsAPICodePack.Shell.KnownFolders.get_All() in D:\WindowsAPICodePack\WindowsAPICodePack\Shell\KnownFolders\KnownFolders.cs:line 29
at Microsoft.WindowsAPICodePack.Samples.ExplorerBrowserTestForm..ctor() in D:\WindowsAPICodePack\Samples\ExplorerBrowser\CS\WinForms\ExplorerBrowserTestForm.cs:line 27
at Microsoft.WindowsAPICodePack.Samples.Program.Main() in D:\WindowsAPICodePack\Samples\ExplorerBrowser\CS\WinForms\Program.cs:line 18
at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
QUESTION
Please help to resolve this error.
This error code means that the object you've requested is not registered on system. IKnownFolderManager appeared starting with Vista.