C# won't recognize getAttribute - c#

I transferred VB.Net app to C# and when I build it. This error showed up -
'mshtml.IHTMLImgElement' does not contain a definition for
'getattribute' and no extension method 'getattribute' accepting a
first argument of type 'mshtml.IHTMLImgElement' could be found (are
you missing a using directive or an assembly reference?)
So how can I replace this getattribute call?
This is the code
private void captcha()
{
mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2) WebBrowser1.Document.DomDocument;
mshtml.IHTMLControlRange imgrange = (mshtml.IHTMLControlRange) (((mshtml.HTMLBody) doc.body).createControlRange());
foreach (mshtml.IHTMLImgElement img in doc.images)
{
if (img.getattribute("src").ToString().Contains("urltoimg"))
{
imgrange.add((mshtml.IHTMLControlElement) img);
imgrange.execCommand("copy", false, null);
PictureBox1.Image = (System.Drawing.Image) (Clipboard.GetDataObject().GetData(DataFormats.Bitmap));
break;
}
}
}

Try "GetAttribute".
VB is case-insensitive, so "getattribute" would work in VB, however C# (and virtually every other language) is case-sensitive.

You need to cast the mshtml.IHTMLImgElement to an mshtml.IHTMLElement, which will then give you the getAttribute() method
You could replace this line as:
if (((mshtml.IHTMLElement)img.getAttribute("src")).ToString().Contains("urltoimg"))
Note the casing as 'getAttribute', not 'getattribute'.

Related

AWS cdk how to tag resources in c#?

I am trying to get Tags to work in a C# AWS CDK project but I can't seem to get anything to work except for the Depreciated syntax. For example in the following code:
using Amazon.CDK;
using Amazon.CDK.AWS.S3;
namespace HelloCdk
{
public class HelloCdkStack : Stack
{
internal HelloCdkStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
{
// The code that defines your stack goes here
var g_bucket = new Bucket(this, "GameContent", new BucketProps
{
Versioned = false,
PublicReadAccess = true,
AutoDeleteObjects = true, //delete and
RemovalPolicy = RemovalPolicy.DESTROY, //destroy bucket when CF Stack deleted.
WebsiteIndexDocument = "index.html",
WebsiteErrorDocument = "index.html"
});
Tag.Add(g_bucket, "key", "value");
}
}
}
The above code will succeed when I issue the cdk synth command. However, I get a warning message that says:
warning CS0618: 'Tag.Add(Construct, string, string, ITagProps?)' is obsolete: 'use "Tags.of(scope).add()"'
But, when I try to use "Tags.of...", the cdk synth command throws the following error:
error CS1061: 'TagManager' does not contain a definition for 'of' and no accessible extension method 'of'...
What do I need to change to get the recommended tagging approach to work?
Your source code with Tags.of should not compile as there is no such a method for .NET defined.
Documentation specifies Tags.Of - https://docs.aws.amazon.com/cdk/latest/guide/tagging.html
Tags.Of(myConstruct).Add("key", "value");
(!) Notice that the stack object has the Tags property, so make sure you do not access the Tags property of the stack, but Tags class.
Make sure you're using the correct Tags class in Amazon.CDK namespace, and not the Stack.Tags property. Here's how you can get to it directly:
Amazon.CDK.Tags.Of(CONSTRUCT).Add(KEY, VALUE);

Implement a simple IFindSaga

I have a simple IFindSaga implemented, I referred and followed the same steps that was provided in particular software document for SQL Persistence Saga Finding Logic. I'm getting an error at session.GetSagaData<SagaData> stating that: "SynchronizedStorageSession does not contain a definition for GetSagaData and no extension method GetSagaData accepting a first argument of type SynchronizedStorageSession could be found (are you missing a using directive or an assembly reference)." Please help me to solve this.
This is my code where I have implemented IFindSaga
public class TrackerFind : IFindSagas<SagaData>.Using<ITrackerData>
{
public Task<SagaData> FindBy(ITrackerData message, SynchronizedStorageSession session, ReadOnlyContextBag context)
{
return session.GetSagaData<SagaData>(
context: context,
whereClause: "JSON_VALUE(Data,'$.PaymentTransactionId') = #propertyValue",
appendParameters: (builder, append) =>
{
var parameter = builder();
parameter.ParameterName = "propertyValue";
parameter.Value = message.TrackerID;
append(parameter);
});
}
}
"GetSagaData" is an extension method which is part of "NserviceBus" namespace.
include following statement
using NServiceBus;
This worked for me. I am not getting that error now
use nuget
package NServiceBus.Persistence.Sql

System.Diagnostics.StackFrame.GetFrame(index) not found in mscorlib

I created two console applications, both targeting v4.5.2 of the .NET framework.
class MyDisposable : IDisposable
{
public void Dispose()
{
var callerName = new StackTrace().GetFrame(1)?.GetMethod()?.Name;
Console.WriteLine($"Dispose called by {callerName}.");
}
}
which run perfectly well.
In the other, I have the following, which are in effect the same.
return Disposable.Create(() =>
{
var stackFrame = new StackFrame();
var callingMethodBase = stackFrame.GetFrame(1)?.GetMethod();
...
});
But Visual Studio intellisense reports:
'StackFrame' does not contain a definition for
'GetFrame' and no extension method 'GetFrame'
accepting a first argument of type 'StackFrame'
could be found (are you missing a using
directive or an assembly reference?)
When I Go to Definition on the StackFramesclass, I see the method GetFrames is absent from the class declaration of the StackFrame class. Both the assembly versions for mscorlib are the same, i.e. v4.0.0.0.
Why is that?
In the first example you are using StackTrace, but in the second you are using StackFrame.
StackTrace has the method GetFrame(), but StackFrame doesn't.

How to read a onedrive folder using c# windows app

I am trying to follow a sample on MSDN to read the properties of a folder on onedrive, but I am running into some errors.
Here is the tutorial I am following: http://msdn.microsoft.com/en-us/library/live/hh826522.aspx#reading_albums
The error I get when I run the code says:
"Error 1 'testRun.MainPage' does not contain a definition for 'session' and no extension method 'session' accepting a first argument of type 'testRun.MainPage' could be found (are you missing a using directive or an assembly reference?) C:\Users\me\Desktop\project"
I have still looked into the issue, and haven't found out what I need to include for the LiveConnectClient parameter. It only gives that it needs "LiveConnectClient session", and I am not sure what to place in for that.
My Code:
private async void Button_logIn_Click(object sender, RoutedEventArgs e)
{
try
{
LiveConnectClient liveClient = new LiveConnectClient(this.session);
LiveOperationResult operationResult =
await liveClient.GetAsync("path/to/folder");
dynamic result = operationResult.Result;
this.Textblock_status.Text = string.Join(" ", "Album name:", result.name, "ID:", result.id);
}
catch (LiveConnectException exception)
{
this.Textblock_status.Text = "Error getting album info: " + exception.Message;
}
}
You need to make sure you're defining the session member, and populating it with a valid session prior to using it with LiveConnectClient. Check out the following documentation for a more complete example:
http://msdn.microsoft.com/en-US/library/dn631823.aspx

Loading Texture list with Texture2D dynamically from file at RunTime in Unity

I have strings for the path to the Texture2D element I want to load from the List string that is filled dynamically from an XML file into the List Texture.
public List commands;
public List icons = new List();
void Awake()
{
int i = 0;
foreach (string element in commands)
{
icons.Insert(i, icons[i].Resources.Load(element, Texture2D)); //error line
i++;
}
}
Here is what I have so far but I'm generating the following compiler errors in Unity:
error CS1061: Type UnityEngine.Texture' does not contain a definition
for Resources' and no extension method Resources of type
`UnityEngine.Texture could be found (are you missing a using
directive or an assembly reference?)
error CS1502: The best overloaded method match for
`System.Collections.Generic.List.Insert(int,
UnityEngine.Texture)' has some invalid arguments
error CS1503: Argument #2' cannot convert object' expression to type
`UnityEngine.Texture'
It seems I cannot use Resources.Load directly with the icons elements as I am attempting to do but I'm at a loss for how else to go about it.
foreach (string element in commands)
{
tex = (Texture2D) Resources.Load(element);
icons.Add(tex);
}
So I figured it out; above modifications are the changes.

Categories

Resources