Amazon.S3.IO S3DirectoryInfo [duplicate] - c#

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.

Related

Python doesn't have access to internet but C# does

I'm working a project that needs to download a certain webpage content, my code in C# works perfectly, however, it seems that Python can't get connected to the internet throwing an exception.
Perhaps it's because I'm working in a Corporate network and that's why Python might be blocked by Firewall. But, how about a C# code, why it works?
I'd like to emulate the Python code as C# WebClient behavior.
Thanks.
C# Code
WebClient wc = new WebClient();
string str = wc.DownloadString("https://www.google.com");
Console.WriteLine(str);
Pythton Code
import urllib
link = "https://www.google.com"
f = urllib.urlopen(link)
myfile = f.read()
print myfile
Python Exception
[Errno socket error] [Errno 10060] A connection attempt failed because
the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to
respond
[Edit 01]
[Edit 02]
Tried WebClient.Proxy = null
WebClient wc = new WebClient();
wc.Proxy = null;
string str = wc.DownloadString("https://www.google.com");
Console.WriteLine(str);
Then I got this Exception. (I also got this exception in a Java Program)
{"The operation has timed out"}
at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
at System.Net.WebClient.DownloadString(Uri address)
at System.Net.WebClient.DownloadString(String address)
at WebClientTest.Program.Main(String[] args) in <ProjectPath>\WebClientTest\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()

Getting IllegalFormatName exception in messageQueue.BeginReceive

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

A generic error occurred in GDI+ when trying to save image downloaded with WebClient

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

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

MetadataException : connection string

I realise that this question has been asked and solved many times before here and that there are many helpful posts such as this one...http://blogs.teamb.com/craigstuntz/2010/08/13/38628/
But unfortunately none of the suggestions have worked for me, so I'm posting in the hope that someone might spot something I haven't seen.
I have a database project Sp_CodeGenerator - I've connected to the database. My connection string is
<add name="AdWorksLTEntities" connectionString="metadata=res://*/Sp_CodeGenerator.Model1.csdl|res://*/Sp_CodeGenerator.Model1.ssdl|res://*/Sp_CodeGenerator.Model1.msl;provider=System.Data.SqlClient;provider connection string="Data Source=EIRCOM;Initial Catalog=AdventureWorksLT2008R2;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework"" providerName="System.Data.EntityClient"/>
I have tried substituting //*/Sp_CodeGenerator.Model... with the name of the dll //Sp_CodeGenerator/Sp_CodeGenerator.Model.csdl etc But it doesn't work.
I have also removed all references in the .config file, removed the .edmx file and the template files generated by Entity Frameworks and started over many times, but it doesn't work.
I can see in my directory structure that the edmx files :Model1.csdl, Model1.msl, Model1.ssdl are housed in a folder called edmxResourcesToEmbed and they can be found in C:\Sp_CodeGenerator\Sp_CodeGenerator\obj\x86
So the full path is
C:\Sp_CodeGenerator\Sp_CodeGenerator\obj\x86\Debug\edmxResourcesToEmbed
I'm not sure if it is a coincidence, but once the problem appeared I also noticed that I have several messages once I open the .config file about missing schemas for element 'entityFramework' 'defaultconnectionFactory' 'type' etc etc.
Any suggestions of where to look next, greatly appreciated.
The full stack trace on the MetadataException is
at System.Data.Metadata.Edm.MetadataArtifactLoaderResource.LoadResource()
at System.Data.Metadata.Edm.MetadataArtifactLoaderResource.CreateReader()
at System.Data.Metadata.Edm.MetadataArtifactLoaderResource.CreateReaders(DataSpace spaceToGet)
at System.Data.Metadata.Edm.MetadataArtifactLoaderComposite.CreateReaders(DataSpace spaceToGet)
at System.Data.Metadata.Edm.MetadataCache.EdmMetadataEntry.LoadEdmItemCollection(MetadataArtifactLoader loader)
at System.Data.Metadata.Edm.MetadataCache.EdmItemCollectionLoader.LoadItemCollection(EdmMetadataEntry entry)
at System.Data.Metadata.Edm.MetadataCache.LoadItemCollection[T](IItemCollectionLoader`1 itemCollectionLoader, T entry)
at System.Data.Metadata.Edm.MetadataCache.GetOrCreateEdmItemCollection(String cacheKey, MetadataArtifactLoader loader, Object& entryToken)
at System.Data.EntityClient.EntityConnection.LoadEdmItemCollection(MetadataWorkspace workspace, MetadataArtifactLoader artifactLoader)
at System.Data.EntityClient.EntityConnection.GetMetadataWorkspace(Boolean initializeAllCollections)
at System.Data.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()
at System.Data.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor)
at System.Data.Objects.ObjectContext..ctor(EntityConnection connection)
at System.Data.Entity.Internal.InternalConnection.CreateObjectContextFromConnectionModel()
at System.Data.Entity.Internal.LazyInternalConnection.CreateObjectContextFromConnectionModel()
at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at System.Data.Entity.Internal.InternalContext.Initialize()
at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
at System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider()
at System.Linq.Queryable.OrderBy[TSource,TKey](IQueryable`1 source, Expression`1 keySelector)
at Sp_CodeGenerator.SelectAll.SelectAll_Method() in C:\Sp_CodeGenerator\Sp_CodeGenerator\Templates\dbo.SelectAll.StoredProcedure.sql.xml.cs:line 14
at Sp_CodeGenerator.Program.Main(String[] args) in C:\Sp_CodeGenerator\Sp_CodeGenerator\Program.cs:line 15
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 found the solution - I just needed to remove the Sp_CodeGenerator. from infront each Model1 in the connection string. Not really sure why the connection string was generated like that in the first place? Maybe something to do with my directory structure?

Categories

Resources