Old forum URL:

tesicg posted on Wednesday, May 11, 2011


I'm new user of CSLA and don't have enough experience. I use VS 2010 and Silverlight 4.

I've created new Silverlight library (DLL) and added a class that deals with deserializing and decompressing (SharpZipLib library). The project compiles successfully.

There's a method in my class:

    private static string Deserialize(byte[] bin)
      string res = null;

      if (bin == null)
        return null;

      object o = Csla.Serialization.Mobile.MobileFormatter.Deserialize(bin);

      XmlSerializer s = new XmlSerializer(o.GetType());
      StringBuilder a = new StringBuilder();
      TextWriter writer = new StringWriter(a);
      s.Serialize(writer, o);
      res = a.ToString();

      return res;

The exception: System.IO.FileNotFoundException was thrown on calling this method:

object o = Csla.Serialization.Mobile.MobileFormatter.Deserialize(bin);

Detailed message is:

System.IO.FileNotFoundException was unhandled
  Message=Could not load file or assembly 'System.Xml, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' or one of its dependencies. The system cannot find the file specified.
  FileName=System.Xml, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
  FusionLog==== Pre-bind state information ===
LOG: User = TESIC-8CC108F46\Goran
LOG: DisplayName = System.Xml, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
LOG: Appbase = file:///D:/Programiranje/Amphora/C1/ConsoleApplication1/ConsoleApplication1/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : Csla, Version=, Culture=neutral, PublicKeyToken=93be5fdc093e4c30.
LOG: This bind starts in default load context.
LOG: No application configuration file found.
LOG: Using host configuration file:
LOG: Using machine configuration file from c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: System.Xml, Version=, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
LOG: Attempting download of new URL file:///D:/Programiranje/Amphora/C1/ConsoleApplication1/ConsoleApplication1/bin/Debug/System.Xml.DLL.
LOG: Attempting download of new URL file:///D:/Programiranje/Amphora/C1/ConsoleApplication1/ConsoleApplication1/bin/Debug/System.Xml/System.Xml.DLL.
LOG: Attempting download of new URL file:///D:/Programiranje/Amphora/C1/ConsoleApplication1/ConsoleApplication1/bin/Debug/System.Xml.EXE.
LOG: Attempting download of new URL file:///D:/Programiranje/Amphora/C1/ConsoleApplication1/ConsoleApplication1/bin/Debug/System.Xml/System.Xml.EXE.

       at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Stream serializationStream)
       at Csla.Serialization.Mobile.MobileFormatter.Deserialize(Byte[] data)
       at SL1.Transformer.Deserialize(Byte[] bin) in D:\Programiranje\Amphora\C1\ConsoleApplication1\SL1\Transformer.cs:line 98
       at SL1.Transformer.DecodeToXml(String encodedText) in D:\Programiranje\Amphora\C1\ConsoleApplication1\SL1\Transformer.cs:line 136
       at ConsoleApplication1.Program.Main(String[] args) in D:\Programiranje\Amphora\C1\ConsoleApplication1\ConsoleApplication1\Program.cs:line 26
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()

How to overcome this?

Thank you in advance.



ajj3085 replied on Wednesday, May 11, 2011

Your project compiles, but are there any warnings about missing reference exceptions? 

It looks like you have a console application referencing a Silverlight library, which won't work (they are different runtimes).

tesicg replied on Wednesday, May 11, 2011

You're right. I have a console applications that referencing Silverlight library. In that case I would please you for advise what to do.

Let me explain in short our situation. We need to create DLL or something else (but, what?) that should be imported in HP LoadRunner application. HP LoadRunner is application that uses for testing automation purposes. We need to automatically test our Silverlight application. After we import such Silverlight library into HP LoadRunner we should call functions from that library.

But, according to what you wrote - "which won't work (they are different runtimes)", it seems to me it won't work as well because HP LoadRunner is not Silverlight based application. Does it mean Silverlight libraries works only with Silverlight based applications and DLLs?

Or I'm wrong? Is it possible to import such Silverlight DLL into non Silverlight based application and use it?

What to do in case we can't use Silverlight DLL? Once again we need to test Silverlight application.

Thank you in advanced.

JonnyBee replied on Thursday, May 12, 2011

In a .NET 4 application you can load a Silverlight assembly and call methods on it but there are some restrictions:

"Portability Explained

We named this new feature “assembly portability”, given that the feature allows your code to be “ported” between both Silverlight and .NET. Portability provides the ability to compile your source with the Silverlight tools, and run your built assemblies on both the Silverlight and .NET runtimes. This feature doesn’t change the underlying implementation of either the Silverlight or .NET runtimes; instead, if you write code that only uses APIs that have the same behavior across Silverlight and .NET, it allows you to use one set of binaries to target both. But how do you know if the APIs you are using are compatible? We have identified five key assemblies that are compatible between Silverlight and .NET. (The Silverlight UI layer is of course not one of these – there are some important differences between Silverlight UI and WPF.)"

Read more about "assembly portability" here:

RockfordLhotka replied on Thursday, May 12, 2011

Given that Csla.dll isn't a portable assembly, I doubt that you can use this technique to create business libraries.

Making Csla.dll be a portable assembly is on my future to-do list, but it requires some non-trivial effort. Jonny actually did some of the required prep work to do the Mono port, but there's more to be done.

To head of the next question: No, I don't have a prediction on when this change will occur, because it is a lot of work.

tesicg replied on Friday, May 13, 2011

Thank you Rockford.

ajj3085 replied on Friday, May 13, 2011

To answer your other question, you create two projects; one for silverlight, one for .net.  You add files to the .net library, and in the SL library you can add files from the .Net library using "Add as Link."  Compiler directives can be used to remove .net code which doesnt' belong in silverlight.

Copyright (c) Marimer LLC