Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using COM with Silverlight 4
Message
De
23/08/2010 21:44:41
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Silverlight
Titre:
Using COM with Silverlight 4
Versions des environnements
Environment:
C# 4.0
OS:
Windows XP
Divers
Thread ID:
01478069
Message ID:
01478069
Vues:
715
Hi

I am posting this here because there is no other appropriate category here.

I was testing out Silverlight Capability with COM , specifically the examples shown here:
http://justinangel.net/CuttingEdgeSilverlight4ComFeatures

Although these samples are nor fully correct because of the changes to SL4, I have corrected them (COMAutomatoionFactory is now
AutomationFactory) and in my installation of VS2010 Express the first sample for writing a text file using the FSO works in the IDE in
Debug mode.

This is the code for the MainPage.xaml
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Runtime.InteropServices.Automation;

namespace SL4Com
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
        }

        private void btnInstall_Click(object sender, RoutedEventArgs e)
        {
            if (Application.Current.InstallState == InstallState.NotInstalled)
                Application.Current.Install();
        }

        private void btnWriteFile_Click(object sender, RoutedEventArgs e)
        {
            using (dynamic fsoCom = AutomationFactory.CreateObject("Scripting.FileSystemObject"))
            {
                dynamic file = fsoCom.CreateTextFile(@"c:\test.txt", true);
                file.WriteLine("Bloody Hell");
                file.WriteLine("Silverlight 4");
                file.Close();

            }
        }
    }
}
This sample is a simple Out-of-Browser example and in the VS2010 Express IDE it works , a OOB window appears and the file is generated when the button is clicked.

However I am unable to get this to run in any way outside the VS2010 IDE. There are a number of files generated on build:
AppMainfest.xaml
Microsoft.CSharp.dll
Microsoft.CSharp.xml
SL4COM.dll
SL4Com.pdb
SL4Com.xap
SL4ComTestPage.html.

and some other language folders(de, es, fr etc.)

Dbl. Clicking on the last 2 files (.xap and .html) opens a browser with the button displayed. No OOB here, but a button in the browser.

Q1 Why no OOB and how do I get it to display an OOB Window?

Clicking the button gives this error:
Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; .NET4.0E)
Timestamp: Tue, 24 Aug 2010 01:37:42 UTC

Message: Unhandled Error in Silverlight Application This operation is not supported in the current context.   at MS.Internal.Error.MarshalXresultAsException(UInt32 hr, COMExceptionBehavior comExceptionBehavior)
   at MS.Internal.XcpImports.CheckHResult(UInt32 hr)
   at MS.Internal.ComAutomation.ComAutomationNative.CreateObject(String progID, IntPtr& nativeObject)
   at MS.Internal.ComAutomation.ComAutomationServices.CreateObject(String progID, ComAutomationParamWrapService paramWrapService)
   at System.Runtime.InteropServices.Automation.AutomationFactory.CreateObject(String progID)
   at SL4Com.MainPage.btnWriteFile_Click(Object sender, RoutedEventArgs e)
   at System.Windows.Controls.Primitives.ButtonBase.OnClick()
   at System.Windows.Controls.Button.OnClick()
   at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
   at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
   at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
Line: 1
Char: 1
Code: 0
URI: file:///C:/VS2010/Silverlight/SL4Com/SL4Com/Bin/Debug/SL4ComTestPage.html
Same things happen when I open the files from IIS.
Q2 So can anyone shed some light on this? How do you actually get an OOB to work as an OOB and why is this error appearing?

Thanks

Bernard

Update:Above problem is solved. Found this solution here:

http://geekswithblogs.net/BelugaNeil/archive/2010/01/05/silverlight-4-oob-out-of-browser-application.aspx

But this now leads to another problem - the text file is not created on the computer c:\text.txt like it was in the VS2010 IDE. and there is absolutely no feedback as to why this is.

Now if I can only find an example of using XML data from a web service in a silverlight grid....
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform