So I followed this link http://www.c-sharpcorner.com/UploadFile/b696c4/how-to-upload-and-display-image-in-mvc/ given by #Div and it just gave me errors at ContentRepository service = new ContentRepository();. How am I suppose to replace that with something else that contain UploadImageInDataBase like int i = service.UploadImageInDataBase(file, model); ?
Private readonly DBContext db = new DBContext();
Gives me error "is inaccessible due to its protection level." And it wont be usable since it gives error "Cannot resolve", but I replaced it with private TestEntities db = new TestEntities(); and it works then. Hopefully it will cover everything?
I cant add anything inside var Content = new Content { as I getting "Cant resolve symbol X" inside it.
Then at
List<ImageVm> contentModel = content.Select(item => new ImageVm()) {
I'm getting following error:
Cannot implicitly convert type 'System.Linq.IQueryable'
to 'System.Collections.Generic.List'. An explicit
conversion exists (are you missing a cast?)
I followed every step carefully and I can't get any further.
The author basically just said "add this code" without explanation and I've no idea how to solve it.
Any idea how to solve it or have any better guides?
Related
I am new to C# and to IOptionsMonitor concept
MyOptionsClass myOptionObject = new MyOptionClass ();
IOptions<MyOptionsClass> instaceOfIOptions =
new OptionsWrapper<MyOptionsClass>(myOptionObject );
Similar to the approach they have used to get an instance of "IOptions"
I wanted to get of IOptionsMonitor So I tried in similar way but it gives me an compiler error.
IOptionsMonitor<CosmosDBOptions> instaceOfIOptionsMonitor =
new OptionsMonitor<CosmosDBOptions>(myOptionObject);
But it asks for 3 arguments (factory, source and cache) in place of myOptionObject
what do I need to pass for the arguments here?
How to achieve this?
So far, I've been unsuccessful at finding anything on this that has worked. I'm trying to change the current view from a class in the .droid namespace to another in the same namespace.
Intent intent = new Intent(this, typeof(viewclass));
Is what seems to be half correct. The biggest problem is this as I cannot do that from the droid, I get the following error:
Cannot convert from App.Droid.CustomMapRenderer to Android.Context.Context
Solution:
var intent= new Intent(Android.App.Application.Context, typeof(ViewClass));
Android.App.Application.Context.StartActivity(intent);
The biggest problem is this as I cannot do that from the droid, I get the following error:
From the error message. You are creating an Intent inside a renderer(CustomMapRenderer). Thus this refers to an instance of CustomMapRenderer, but to create an intent the first argument should be a Context.
So to fix the problem, you need to retrieve the current context in certain way,
For example, you can try Intent intent = new Intent(Application.Context, typeof(viewclass));
Update: I downloaded Ramone project, added it to my project and then ran the application again with debugger. The error is shown below:
public MediaTypeWriterRegistration GetWriter(Type t, MediaType mediaType)
{
...
CodecEntry entry = SelectWriters(t, mediaType).FirstOrDefault(); => this line throws error
...
}
Error occurs in CodecManager.cs. I am trying to figure out why it does not recognize json-patch media type. Could it be because writer is not being registered correctly? I am looking into it. If you figure out the problem, please let me know. Since you are the author of the library, it will be easier for you to figure out the issue. I will have to go through all the code files and methods to find the issue. Thanks!
I was excited to know that Ramone library supports json-patch operations but when I tried it, I got following error:
415- Unsupported Media Type
This is the same error that I get when I use RestSharp. I thought may be RestSharp does not support json-patch and errors out so I decided to try Ramone lib but I still get same error. Endpoint has no issues because when I try same command using Postman, it works but when I try it programmatically in C#, it throws unsupported media type error. Here is my code:
var authenticator = new TokenProvider("gfdsfdsfdsafdsafsadfsdrj5o97jgvegh", "sadfdsafdsafdsfgfdhgfhehrerhgJ");
JsonPatchDocument patch = new JsonPatchDocument<MetaData>();
patch.Add("/Resident2", "Boyle");
//patch.Replace("/Resident", "Boyle");
RSession = RamoneConfiguration.NewSession(new Uri("https://api.box.com"));
RSession.DefaultRequestMediaType = MediaType.ApplicationJson;
RSession.DefaultResponseMediaType = MediaType.ApplicationJson;
Ramone.Request ramonerequest = RSession.Bind("/2.0/files/323433290812/metadata");
ramonerequest.Header("Authorization", "Bearer " + authenticator.GetAccessToken(code).AccessToken);
//var ramoneresponse = ramonerequest.Patch(patch); //results in error: 405 - Method Not Allowed
var ramoneresponse = ramonerequest.Put(patch); //results in error: 415 - Unsupported Media Type
var responsebody = ramoneresponse.Body
Endpoint information is available here: http://developers.box.com/metadata-api
I used json-patch section in the following article as a reference:
http://elfisk.dk/Ramone/Documentation/Ramone.pdf
By the way I tried Patch() method (as shown in above ref. article) but that resulted in "Method not allowed" so I used Put() method which seems to work but then errors out because of json-patch operation.
Any help, guidance, tips in resolving this problem will be highly appreciated. Thanks much in advance.
-Sham
The Box documentation says you should use PUT (which is quite a bit funny). The server even tells you that it doesn't support the HTTP PATCH method (405 Method Not Allowed) - so PUT it must be.
Now, you tell Ramone to use JSON all the time (RSession.DefaultRequestMediaType = MediaType.ApplicationJson), so you end up PUT'ing a JSON document to Box - where you should be PUT'ing a JSON-Patch document.
Drop the "RSession.DefaultRequestMediaType = MediaType.ApplicationJson" statement and send the patch document as JSON-Patch with the use of: ramonerequest.ContentType("application/json-patch+json").Put(...).
I am in the final stages of porting some code into my framework.
The latest problem is very similar to this one I posted recently ( Strange "The type arguments for method cannot be inferred from the usage." ), whereby text enclosed in '<' and '>' in the listing I am porting code is missing.
The latest offending line is:
using (var resource = SlimDX.Direct3D11.Resource.FromSwapChain(swapChain, 0))
renderTarget = new SlimDX.Direct3D11.RenderTargetView(graphics, resource);
I get the following error from the compiler:
The type arguments for method 'SlimDX.Direct3D10.Device.OpenSharedResource(System.IntPtr)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
I tried to fix this myself by changing my code to:
using (var resource = SlimDX.Direct3D11.Resource.FromSwapChain<SlimDX.Direct3D11.Resource>(swapChain, 0))
renderTarget = new SlimDX.Direct3D11.RenderTargetView(graphics, resource);
... but now I get an even stranger run-time error:
"Error: Method 'SlimDX.Direct3D11.Resource.FromPointerReflectionThunk' not found."
Initial research indicates I might have stumbled into something which is way above my head: http://www.gamedev.net/topic/542095-slimdx-need-help-from-nativemanaged-interop-expert/
All I am trying to do is port this code into my framework: http://www.aaronblog.us/?p=36 ... which is all about drawing text in SlimDX with DX11.
At some point I hope to have figured out how to genericise this code into my framework. It is heavy going though.
I'm using SlimDX SDK (January 2012).
Look at the last post in the gamedev.net thread you referenced -- it says that you can fix the problem by specifying the type argument as Texture2D.
So you might try:
using (var resource = SlimDX.Direct3D11.Resource.FromSwapChain<Texture2D>(swapChain, 0))
renderTarget = new SlimDX.Direct3D11.RenderTargetView(graphics, resource);
I trying to use the MimeMapClass from IISOle.
I am getting the following error
The type 'IISOle.MimeMapClass' has no constructors defined
It happens when I try to instantiate the object
vRoot.Properties["MimeMap"].Add(new MimeMapClass { Extension = ext, MimeType = mime });
I get additional errors:
Interop type 'IISOle.MimeMapClass' cannot be embedded. Use the applicable interface instead.
'IISOle.MimeMapClass' does not contain a definition for 'Extension'
I have no idea why this is happening.
Any ideas?
I am not sure if this is your issue as I don't know if you are using VS2010 or not. But if you are, try not embedding the interop types (see the properties of the reference you have added). According to this article it can cause you these type of troubles
Have you tried the following? (Not production code - No error handling, disposing, or check for existing items provided.)
DirectoryEntry mimeMap = new DirectoryEntry("IIS://localhost/MimeMap")
PropertyValueCollection collection = mimeMap.Properties["MimeMap"];
MimeMapClass newMimeType = new MimeMapClass();
newMimeType.Extension = ext;
newMimeType.MimeType = mime;
collection.Add(newMimeType);
mimeMap.CommitChanges();