silverlight-4 com-interop Cannot invoke a non-delegate type - silverlight-4.0

This silverlight code throws an error "Cannot invoke a non-delegate type"
var WshShell = AutomationFactory.CreateObject("WScript.Shell");
var WshSysEnv = WshShell.Environment("SYSTEM");
var foo = WshSysEnv("APPDATA");
How can I get the environment variable?
EDIT:
#paulsm4 - this works in silverlight...
var WshShell = AutomationFactory.CreateObject("WScript.Shell");
var appData = WshShell.ExpandEnvironmentStrings("%APPDATA%");
MessageBox.Show(appData);

Assuming WSH, How about something like this:
Set wshShell = CreateObject( "WScript.Shell" )
WScript.Echo wshShell.ExpandEnvironmentStrings( "%APPDATA%" )
wshShell = Nothing

Related

syntax error in New Form() With {} vb.net

Dim name As String = "hello"
If CType(My.Application.OpenForms(name), Faker) Is Nothing Then
New Faker() With {.Name = name, .Title = String.Format("{0} - ID:{1}", "hello", Me.ClassClient.ClientAddressID)}.Show()
End If
Syntax error in New , if i remove all code and write Dim F As New Faker() With {} and F.show() no error but not work and give me error while running the program object reference not set to an instance of an object
can any one here help me pls
There are two answers here Constructing an object and calling a method without assignment in VB.Net that should help.
Use With ... End With
Use Call
I think you're having an issue because you're trying to use the C# style of creating an instance of an object without assigning it before chaining a method call.
Your code becomes:
Dim name As String = "hello"
If CType(My.Application.OpenForms(name), Faker) Is Nothing Then
With New Faker() With {.Name = name, .Title = String.Format("{0} - ID:{1}", "hello", Me.ClassClient.ClientAddressID)}
.Show()
End If
Or
Dim name As String = "hello"
If CType(My.Application.OpenForms(name), Faker) Is Nothing Then
Call New Faker() With {.Name = name, .Title = String.Format("{0} - ID:{1}", "hello", Me.ClassClient.ClientAddressID)}.Show()
End If

Linq Exception: object reference not set to an instance of an object

When I run this LINQ query:
Dim CurrQ = From c In db.CurrentMonthTables Where c.MonthNumber = Val(CmbMonthNumber.Text) And c.Year = Val(CmbYear.Text) And c.Exist = True
I get:
...object reference not set to an instance of an object...

RS.exe subscribe report with parameters

I am trying to create dynamic report subscriptions through rs.exe. How ever I cannot get the parameters to work. The enddate value is data/time, so I think that might be causing it, but I do not know what to do about it. I have tried casting, but the error msg. stays the same.
rs.exe call:
C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn>rs.exe -i C:\Users\me\Desktop\rss_gen\subs.rss -s "localhost/ReportserverT"
subs.rss file:
Public Sub Main()
rs.Credentials = System.Net.CredentialCache.DefaultCredentials
Dim desc As String = "Report description"
Dim eventType As String = "TimedSubscription"
Dim scheduleXml As String = "<ScheduleDefinition><StartDateTime>2017-12-08T15:00:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Thursday>True</Thursday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>"
Dim parameters() As ParameterValue
' If you need setup parameters
Dim parameter As ParameterValue
parameter.Name = "enddate"
parameter.Value = "2017-12-30 10:03:01.250" 'this is date/time
parameters(0) = parameter
Dim matchData As String = scheduleXml
Dim returnValue As String
Dim reports() As String = { _
"/My Folder/report"}
For Each report As String In reports
returnValue = rs.CreateSubscription(report, parameters)
Console.WriteLine(returnValue)
Next
End Sub 'Main`enter code here`
Error msg:
C:\Users\mee\AppData\Local\Temp\11\dhexge0m.1.vb(43) : error BC30455:
Argument n ot specified for parameter 'Parameters' of 'Public Function
CreateSubscription(R eport As String, ExtensionSettings As
Microsoft.SqlServer.ReportingServices2005. ExtensionSettings,
Description As String, EventType As String, MatchData As Stri ng,
Parameters() As
Microsoft.SqlServer.ReportingServices2005.ParameterValue) As String'.
Let me teach you a trick to program in .Net and in general. It sounds simple, all you need to do is pass functions what they expect. Let me give you a simple example.
With this code I've got a similar error to you:
CS7036 There is no argument given that corresponds to the required formal parameter 'fileName' of 'FileInfo.FileInfo(string)'
The squiggle red line tells you where the problem is. If I type the opening bracket it will give me a tooltip with what it expects:
Ok it needs a string, so I declare a string and give it to the function as it expects:
So the problem you have is because you are not giving the CreateSubscription function the parameters it expects.
Argument not specified for parameter 'Parameters' of 'Public Function CreateSubscription
To fix it provide all the mandatory parameters to the ReportingService2005.CreateSubscription Method:
public static void Main()
{
ReportingService2005 rs = new ReportingService2005();
rs.Credentials = System.Net.CredentialCache.DefaultCredentials;
string report = "/SampleReports/Employee Sales Summary";
string desc = "Send email to anyone#microsoft.com";
string eventType = "TimedSubscription";
string scheduleXml = #"<ScheduleDefinition><StartDateTime>2003-02-24T09:00:00-08:00</StartDateTime><WeeklyRecurrence><WeeksInterval>1</WeeksInterval><DaysOfWeek><Monday>True</Monday></DaysOfWeek></WeeklyRecurrence></ScheduleDefinition>";
ParameterValue[] extensionParams = new ParameterValue[8];
extensionParams[0] = new ParameterValue();
extensionParams[0].Name = "TO";
extensionParams[0].Value = "dank#adventure-works.com";
extensionParams[1] = new ParameterValue();
extensionParams[1].Name = "ReplyTo";
extensionParams[1].Value = "reporting#adventure-works.com";
ParameterValue parameter = new ParameterValue();
parameter.Name = "EmpID";
parameter.Value = "38";
ParameterValue[] parameters = new ParameterValue[1];
parameters[0] = parameter;
string matchData = scheduleXml;
ExtensionSettings extSettings = new ExtensionSettings();
extSettings.ParameterValues = extensionParams;
extSettings.Extension = "Report Server Email";
try
{
rs.CreateSubscription(report, extSettings, desc, eventType, matchData, parameters);
}
catch (SoapException e)
{
Console.WriteLine(e.Detail.InnerXml.ToString());
}
}
As part of the 2005 report service for ms SQL, none of the parameters passed to CreateSubscription are optional. Please refer to the link and update the way you are calling the function. The error is clear, you are missing the parameters which is the last one. Look at the bottom of the page for an example.
https://technet.microsoft.com/en-us/library/microsoft.wssux.reportingserviceswebservice.rsmanagementservice2005.reportingservice2005.createsubscription(v=sql.90).aspx

VB.net: Object not set to an instance of object

I am getting a Object not set to an instance of object error. I have put a list view where all messages should be shown. I am using lumisoft sample code which I ported to vb.net
Private Sub FillMessagesList()
Me.Cursor = Cursors.WaitCursor
Try
Dim m_pPop3 As POP3_Client = Nothing
For Each message As POP3_ClientMessage In m_pPop3.Messages
Dim mime As Mail_Message = Mail_Message.ParseFromByte(message.HeaderToByte())
Dim item As New ListViewItem()
If mime.From IsNot Nothing Then
item.Text = mime.From.ToString()
Else
item.Text = "<none>"
End If
If String.IsNullOrEmpty(mime.Subject) Then
item.SubItems.Add("<none>")
Else
item.SubItems.Add(mime.Subject)
End If
item.SubItems.Add(mime.[Date].ToString())
item.SubItems.Add(CDec(message.Size / CDec(1000)).ToString("f2") & " kb")
item.Tag = message
ListView1.Items.Add(item)
Next
Catch x As Exception
MessageBox.Show(Me, "Errorssssss: " + x.Message)
End Try
Me.Cursor = Cursors.[Default]
End Sub
The problem is here:
Dim m_pPop3 As POP3_Client = Nothing
For Each message As POP3_ClientMessage In m_pPop3.Messages
You set m_pPop3 to Nothing and then try to access one of its members.
You say that you ported the code - perhaps you need to look back at the original code and port it correctly:
private POP3_Client m_pPop3 = null;
/// <summary>
/// Default constructor.
/// </summary>
public wfrm_Main()
{
InitUI();
this.Visible = true;
wfrm_Connect frm = new wfrm_Connect(
new EventHandler<WriteLogEventArgs>(Pop3_WriteLog));
if(frm.ShowDialog(this) == DialogResult.OK){
m_pPop3 = frm.POP3;
// etc...
}
private void FillMessagesList()
{
this.Cursor = Cursors.WaitCursor;
try{
foreach(POP3_ClientMessage message in m_pPop3.Messages){
// etc...
}
}
Notice that m_pPop3.Messages is a private member here, not a local variable as you have implemented it.
To correct your code I would suggest changing it to be more similar to the original. Change the local variable to a private member and set it in the constructor, just as the original C# code does.
The culprit is possibly from the code in the 2 lines:
Dim m_pPop3 As POP3_Client = Nothing
For Each message As POP3_ClientMessage In m_pPop3.Messages
You're trying to loop through the messages in "m_pPop3" but you've explicitly set it to nothing on the line directly above.
I'm guessing it's here since you're setting m_pPop3 to Nothing. If you'd stepped through the code it would show you that.
Dim m_pPop3 As POP3_Client = Nothing
For Each message As POP3_ClientMessage In m_pPop3.Messages

RavenDB - Need a simple example using EmbeddableDocumentStore?

I am experimenting with RavenDB embedded in my application. I am receiving a "Type 'EmbeddableDocumentStore' is not defined" error. I do, however, have a reference to Raven.Client.Embedded in my project.
Here's my VB.Net code:
Imports Raven.Client.Client
Imports Raven.Client
Sub Main()
Dim documentStore As EmbeddableDocumentStore = New EmbeddableDocumentStore()
documentStore.DataDirectory = "c:\dbdata"
documentStore.Initialize()
Dim session As Document.DocumentSession = documentStore.OpenSession()
session.Store(New LineItem With {
.draftpostingdate = Nothing,
.forumdate = "#12/1/2010#",
.pfvolume = Nothing,
.pfissue = Nothing,
.change = "change",
.sectiontext = "Revision",
.rs = Nothing,
.revisionid = 51438,
.mononum = "100249",
.webtype = "PCA"
})
session.SaveChanges()
Dim lineItems = session.Query(Of LineItem)()
For Each li As LineItem In lineItems
Console.WriteLine(li.mononum)
Next
End Sub
I have had similar problems before when I targeted the wrong framework. Have you checked that you're not targeting the "Client Profile" in your project? If I remember correctly you have to target the full framework when using Embedded client.