IISOle.MimeMapClass has no constructors - c#

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

Related

WF4.5- Expression Activity type 'CSharpValue`1' requires compilation in order to run

Background
What I'm trying to do is to have a scoped variable of one of my models in the xaml.
In my workflow project "MyProject.Workflows" I have created model classes, code activities and Xaml files. They are all under same namespace. In another project ("Engine"), I load and execute these workflows.
To load the workflows in the "Engine", I use ActivityXamlServices with ActivityXamlServicesSettings including CompileExpressions = true.
When loading the ActivityXamlServices, I use a XamlXmlReader with XamlXmlReaderSettings where I actually point to the "MyProject.Workflows" dll.
Since Both these projects are in the same solution I actually referred MyProject.Workflows in the "Engine".
Because Earlier, they were in different solutions, So when I tried to do this It gave me It cant find the "MyProject.Workflows" dll even though I point it in the XamlXmlReaderSettings.
Then I tried to load the dll to the app domain and then it worked.But I did not want to deal with App Domains so I decided to get both projects under one solution so I can refer the "MyProject.Workflows" in the "Engine".
Issue:
If I use one of those models inside of the Xaml as an expression like "Assign Activity" the Workflow isn't getting compiled when I try to execute this.
For example if I use this in an "Assign" activity having a scoped variable of type MyObject
Newtonsoft.Json.JsonConvert.DeserializeObject<MyProject.Workflows.Models.MyObject>(inputString);
I will get the below error message when I run the workflow.
NotSupportedException:'Expression Activity type 'CSharpValue`1' requires compilation in order to run. Please ensure that the workflow has been compiled.
If I remove these objects and just deal with strings or ints, it works fine.
Things I found in my research:
I found this was a bug in .Net Framework 4.5. But Im using 4.6
Even though I used CompileExpressions = true , I tried this compile method I found. But did not change a thing.
private static void Compile(DynamicActivity dynamicActivity)
{
TextExpressionCompilerSettings settings = new TextExpressionCompilerSettings
{
Activity = dynamicActivity,
Language = "C#",
ActivityName = dynamicActivity.Name.Split('.').Last() + "_CompiledExpressionRoot",
ActivityNamespace = string.Join(".", dynamicActivity.Name.Split('.').Reverse().Skip(1).Reverse()),
RootNamespace = null,
GenerateAsPartialClass = false,
AlwaysGenerateSource = true,
};
TextExpressionCompilerResults results =
new TextExpressionCompiler(settings).Compile();
if (results.HasErrors)
{
throw new Exception("Compilation failed.");
}
ICompiledExpressionRoot compiledExpressionRoot =
Activator.CreateInstance(results.ResultType,
new object[] { dynamicActivity }) as ICompiledExpressionRoot;
CompiledExpressionInvoker.SetCompiledExpressionRootForImplementation(
dynamicActivity, compiledExpressionRoot);
}
I read that some people faced this problem and they had to actually move the models to a diffrent namespace. I did that too. Didn't fix the problem.
My Xaml file has this entry added at the top.
xmlns:local="clr-namespace:MyProject.Workflows.Models"
Can someone please help me to get through this?

Getting MissingMethodException when using Manatee.trello to get list of users

I have the following code which is intended to fetch a list of all the user of an organisation.
public static IEnumerable<Member> ListTrelloUsers()
{
var serializer = new ManateeSerializer();
TrelloConfiguration.Serializer = serializer;
TrelloConfiguration.Deserializer = serializer;
TrelloConfiguration.JsonFactory = new ManateeFactory();
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
TrelloAuthorization.Default.AppKey = ApplicationKey;
TrelloAuthorization.Default.UserToken = GrandToken;
var myOrganization = Member.Me.Organizations.FirstOrDefault().Id; //Exception thrown here.
var orgToAddTo = new Organization(myOrganization);
return orgToAddTo.Members.AsEnumerable();
}
But I'm getting a
System.MissingMethodException
thrown on
RestSharp.IRestRequest RestSharp.RestRequest.AddFile(System.String, Byte[], System.String)
So why is this exception thrown and what should the correctly working code look like?
Clarifications
I will also accept working C#/ASP.Net MVC code that isn't based on Manatee.Trello as an answer. (Including pure API-calls.)
I have tried using the Organisation ID directly as
var orgToAddTo = new Organization(OrganisationId);
but that just caused the same exception to be thrown later when I make a call to the method's returned object (e.g. using Count()).
UPDATE: I tried setting the build to Release instead of Debug and now the (same) exception is instead thrown at
TrelloConfiguration.RestClientProvider = new RestSharpClientProvider();
This is an issue with RestSharp that I reported quite some time ago, though they deny that it's a problem. If you're using .Net 4.5+, you can try the Manatee.Trello.WebApi package instead of Manatee.Trello.RestSharp.
TrelloConfiguration.RestProvider = new WebApiClientProvider();
Here's my Trello card for tracking the issue. This and this are the RestSharp issues I created.
I have been able to recreate this as well, but have received no help from them to resolve it.
Apperently, the class with missing method is located in an assembly, which differ from the one, which you used while compiling the project. Double check and make sure both at compiling and at execution you use the same assembly with the aforementioned class.
That is my best clue based on the info you've provided.
basically, check project references and make sure, you use correct ones for the class-holding assembly.

How can I pass ARM template parameters through the API instead of a parameter file?

I'm attempting to automate the creation of some resources in Azure using Azure Resource Manager .NET libraries. I am able to create the Resource Group and have placed my ARM template in an accessible location on blob storage; however, I would like to be able to pass in the parameters to the request in code instead of staging a JSON file somewhere in storage.
It seems like this should be possible. For example, on the Deployment.Properties object, it has both Parameters and ParametersLink, but I cannot find any documentation on its usage and the following is throwing an exception saying that no value was specified for the parameters in the template:
deployment.Properties = new DeploymentProperties
{
Mode = DeploymentMode.Incremental,
TemplateLink = new TemplateLink("link-to-my-template-json-in-storage"),
Parameters = new
{
diskStorageAccountName = "value",
imageVhdPath = "value",
virtualNetworkName = "value",
virtualNetworkSubnetName = "value",
vmName = value,
vmAdminUserName = "value",
vmAdminPassword = "value"
}
};
This yields the following error:
An unhandled exception of type 'Microsoft.Rest.Azure.CloudException' occurred in mscorlib.dll
Additional information: Deployment template validation failed: 'The value for the template parameter 'diskStorageAccountName' at line '5' and column '32' is not provided. Please see http://aka.ms/arm-deploy/#parameter-file for usage details.'.
Am I doing something wrong? DeploymentProperties.Parameters is just an Object so I had assumed that it would be serialized and passed on correctly -- is this assumption incorrect?
Edit: The MSDN article is not very helpful either.
Edit 2: I wonder if this is a bug in the autogenerated code. See line 700 here:
https://github.com/Azure/azure-sdk-for-net/blob/master/src/ResourceManagement/Resource/ResourceManagement/Generated/DeploymentOperations.cs
Looks like it is trying to JObject.Parse
Edit 3: Opened an issue on GitHub.
For the Deployment Properties Parameters, you should use the JObject type from the Newtonsoft.Json.Linq namespace.
E.g.
using Newtonsoft.Json.Linq;
// paramJsonString is a string type object
Parameters = JObject.Parse(paramJsonString);
Note: The Microsoft.Azure.Management.Resources nuget package will be deprecated.
Strongly recommend to use Microsoft.Azure.ResourceManager
1.0.0-preview Microsoft.Azure.ResourceManager for your development related to Azure Resource Manager.
Hope this helps!
According to the source code testing, it has something of an odd layout...
#"{ 'siteName': {'value': 'mctest0101'},'hostingPlanName': {'value': 'mctest0101'},'siteMode': {'value': 'Limited'},'computeMode': {'value': 'Shared'},'siteLocation': {'value': 'North Europe'},'sku': {'value': 'Free'},'workerSize': {'value': '0'}}",
There is also an issue raised with similar problems
I've not currently got time to test this! so if it doesn't work let me know and I'll delete this answer.

Error CS1540/CS0122: Getting keyboard size doesn't work after switching to Unified API

Today I updated to Xamarin.iOS 8.6.0.51 and switched to the new Unified API.
Now I want to get the keyboard size (this code worked before):
var val = new NSValue (notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey).Handle);
RectangleF keyboardSize = val.RectangleFValue;
With the help of the migration tool the RectangleF is converted to CGRect, but the errors I'm getting here are
Error CS1540: Cannot access protected member
Foundation.NSValue.NSValue(System.IntPtr)' via a qualifier of type
Foundation.NSValue'. The qualifier must be of type
`MyApp.SomeViewController' or derived from it (CS1540)
and
Error CS0122: `Foundation.NSValue.NSValue(System.IntPtr)' is
inaccessible due to its protection level (CS0122)
How can I solve this? I can delete new NSValue(...), but RectangleFValue still doesn't work and I would need a replacement/another way.
Edit:
According to jonathanpeppers I modified my code to:
NSValue keyboardFrameBegin = (NSValue)notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey);
CGRect keyboardSize = keyboardFrameBegin.CGRectValue;
This doesn't throw an error anymore, but I can't test it further because I'm in the process of migrating to the Unified API and there are still some errors to correct.
Can you just use a cast:
var val = (NSValue)notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey);
RectangleF keyboardSize = val.RectangleFValue;
Only rarely should you have to mess with handles in Xamarin.iOS.
To be absolutely sure what to cast to, debug and see what the underlying type is first:
NSObject val = notification.UserInfo.ValueForKey (UIKeyboard.FrameBeginUserInfoKey);
Console.WriteLine("Type: " + val.GetType());
The .ctor(IntPtr) constructors in NSObject could be misused and causes issue later. Also, like #jonathanpeppers mentioned, they were not required for many scenarios (like this one).
Another way to do this (e.g. if you have nothing else but an handle), as documented here, is to use the ObjCRuntime.Runtime.GetNSObject<T> (IntPtr) method. That will ensure the NSObject-subclass is created correctly.

Unsupported Media Type error when using json-patch in Ramone

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

Categories

Resources