Getting IllegalFormatName exception in messageQueue.BeginReceive - c#

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

Related

Grapevine 3.1 - 'The process cannot access the file'

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")

BIDSHelper2014 1.7.0.0 (BimlEngine) throws <>z__Aspects

I have a code which works fine with 1.6.6 version. For example this line:
var root = new AstRootNode(null);
I decided to update the library to 1.7.0.0 and now I get "The type initializer for '<>z__Aspects' threw an exception.". If someone else faced this problem, please help solve it.
Inner Exception:
{"Could not load file or assembly 'Utility, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.":"Utility, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null"}
Stack Trace:
at Varigence.Utility.ComponentModel.VulcanNotifyPropertyChanged..ctor()
at Varigence.Languages.Biml.AstNode..ctor(IFrameworkItem parentItem)
at Varigence.Languages.Biml.AstRootNode..ctor(IFrameworkItem parentItem)
at ConsoleApplication1.Program.Main(String[] args) in c:\Users\Nikolai\Documents\Visual Studio 2012\Projects\ConsoleApplication1\ConsoleApplication1\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()

dll Matlab instance throw an exception while running release in c#

My c# program uses Matlab dll and it works find as long as I run it in Debug mode.
but as I trying to run it in Release mode it crashes immediately when creating it's instance.
It trows TypeInitializationException.
Thanks for your help
StackTrace:
"at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at Turbo_Neuron.ANNController..ctor()
in C:\\Users\\Eli\\Desktop\\....\\MyProject\\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
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()"
And it sais:
The type initializer for 'MatlabANNComp.MatlabANN' threw an exception.
StachTrace 2:
at MatlabANNComp.MatlabANN..ctor()
at Turbo_Neuron.ANNController..ctor() in C:\Users\Eli\Desktop\Work_ANN\ANN\working\Current\Turbo_Neuron_Pro_Filxed_10.09.13_N\Turbo_Neuron\Matlab_Layer\ANNController.cs:line 49
at Turbo_Neuron.TNController..ctor(pnl_main form) in C:\Users\Eli\Desktop\Work_ANN\ANN\working\Current\Turbo_Neuron_Pro_Filxed_10.09.13_N\Turbo_Neuron\Logic_Layer\TNController.cs:line 49
at Turbo_Neuron.pnl_main..ctor() in C:\Users\Eli\Desktop\Work_ANN\ANN\working\Current\Turbo_Neuron_Pro_Filxed_10.09.13_N\Turbo_Neuron\View_Layer\Turbo_Form.cs:line 29
at Turbo_Neuron.Program.Main() in C:\Users\Eli\Desktop\Work_ANN\ANN\working\Current\Turbo_Neuron_Pro_Filxed_10.09.13_N\Turbo_Neuron\Program.cs:line 17
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
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()
Exception messages:
Exception.Message =
"The type initializer for 'MatlabANNComp.MatlabANN' threw an exception."
InnerException.Message =
{"Could not load file or assembly 'MWArray, Version=2.10.1.0,
Culture=neutral, PublicKeyToken=e1d84a0da19db86f'
or one of its dependencies. An attempt was made
to load a program with an incorrect format."}
InnerException.InnerException = null
An attempt was made to load a program with an incorrect format
this is the key, and it means you are mixing platforms somwhow. A 32bit process cannot load 64bit dlls and vice-versa. If a process tries to do so anyway, it throws the above exception.
You say you only changed from Debug->Release, so it's likely something that has to do with platform changed as well. Compare settings for all projects in the Configuration Manager. They all should be x86 or x64 (not AnyCPU). Which one depends on your matlab dll's platform (set when building it).

await with httpClient.GetAsync(url) and getting error System.NullReferenceException was unhandled

I am using VS 2012 and set the target framework 4.0.
public async Task<HttpResponseMessage> GetResponse(Uri url)
{
this.httpClient.DefaultRequestHeaders.Accept.Clear();
HttpResponseMessage response = await this.httpClient.GetAsync(url);
response.EnsureSuccessStatusCode();
}
Error:
System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Microsoft.CompilerServices.AsyncTargetingPack.Net4
StackTrace:
Server stack trace: at System.Web.ThreadContext.AssociateWithCurrentThread(Boolean setImpersonationContext) at System.Web.HttpApplication.OnThreadEnterPrivate(Boolean setImpersonationContext) at System.Web.LegacyAspNetSynchronizationContext.CallCallbackPossiblyUnderLock(SendOrPostCallback callback, Object state) at System.Web.LegacyAspNetSynchronizationContext.CallCallback(SendOrPostCallback callback, Object state) at System.Web.LegacyAspNetSynchronizationContext.Post(SendOrPostCallback callback, Object state) at System.Runtime.CompilerServices.TaskAwaiter.<>c__DisplayClassa.<OnCompletedInternal>b__0(Task param0)
Exception rethrown at [0]: at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_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.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
InnerException:
-------------------------------------------------
I have installed "Microsoft.CompilerServices.AsyncTargetingPack" from NuGet, but still getting this error. Any suggestion.

Amazon.S3.IO S3DirectoryInfo [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to upload files to Amazon S3 (official SDK) that are larger than 5 MB (approx)?
I try to use the Amazon.S3.IO API. If i write 10mb there is no problem. If i write 21mb i get an exception:
The request was aborted: The request was canceled.
StackTRace:
at System.Net.ConnectStream.CloseInternal(Boolean internalCall, Boolean aborting)
at System.Net.ConnectStream.System.Net.ICloseEx.CloseEx(CloseExState closeState)
at System.Net.ConnectStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.Stream.Dispose()
at Amazon.S3.AmazonS3Client.getRequestStreamCallback[T](IAsyncResult result)
at Amazon.S3.AmazonS3Client.endOperation[T](IAsyncResult result)
at Amazon.S3.AmazonS3Client.EndPutObject(IAsyncResult asyncResult)
at Amazon.S3.AmazonS3Client.PutObject(PutObjectRequest request)
at Amazon.S3.IO.S3FileStream.Flush(Boolean flushToS3)
at Amazon.S3.IO.S3FileStream.Dispose(Boolean disposing)
at System.IO.Stream.Close()
at System.IO.StreamWriter.Dispose(Boolean disposing)
at System.IO.TextWriter.Dispose()
at S3FileSystem_Sample.Program.createFile(S3DirectoryInfo rootDirectory, String filename) in c:\Program Files (x86)\AWS SDK for .NET\Samples\S3FileSystem_Sample \S3FileSystem_Sample\Program.cs:line 106
at S3FileSystem_Sample.Program.Main(String[] args) in c:\Program Files (x86)\AWS SDK for .NET\Samples\S3FileSystem_Sample\S3FileSystem_Sample\Program.cs:line 59
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()
static void createFile(S3DirectoryInfo rootDirectory, string filename)
{
// Creates a file at the root of the bucket.
S3FileInfo readme = rootDirectory.GetFile(filename);
char[] buffer = new char[buffersize];
fillBuffer(buffer);
using (StreamWriter writer = new StreamWriter(readme.OpenWrite()))
{
writer.Write(buffer);
}
}
Any idea i could set the timeout?
Click here and here for more related questions.
Unfortunately the Amazon.S3.IO API does not support setting a timeout but as a Developer on the SDK I will add that feature request to our backlog.
Keep in mind the Amazon.S3.IO API is a really easy interface to work with S3 but it is not well suited for large files because it buffers them into memory until you have passed the entire contents of the file to the API and then it writes it to S3. For large files you should use the TransferUtility found in the the Amazon.S3.Transfer namespace.

Categories

Resources