We have an old legacy application that is running with MS Access. We are in the process of migrating it to WPF. For that we created a WinForms control, that is showing our new WPF stuff in an ElementHost. This WinForms control is then somehow used in a COM ocx which then is placed on a MS Access form. This works so far, and for the time being this is like it is and I can't change it.
Until now we used the built-in WebBrowser control from .NET to show web sites, but since this control is based on IE 11, we are looking for a replacement. WebView2 is not working in an ElementHost, so now we are investigating and testing CefSharp for WPF.
In all of my stand-alone tests it worked so far, but when I tried to integrate it into our software today I stumbled upon a problem and I'm not sure how to fix that.
When I put the ChromiumWebBrowser control from CefSharp onto our WPF window and ran our software I got an IO.FileLoadException for the file CefSharp.Wpf. Checking that with fuslogvw.exe I've seen, that .NET looked for that file in the directory where the MSAccess.exe is situated, probably because this in fact is the executing assembly.
So I registered an AppDomain.CurrentDomain.AssemblyResolve event to manually load the necessary files from where they are situated. This worked for
CefSharp.Wpf
CefSharp
CefSharp.Core
But then it tried to load CefSharp.Core.Runtime and although this assembly is present I get an IO.FileLoadException (this file or one of its dependencies can't be found) when loading this assembly. I assume that it tries to find one of its own dependencies (non .NET) and looks for it in the wrong place (maybe the MS Access directory again?).
Do you have any suggestions how I can tell CefSharp and all of its dependencies (direct or indirect) where they can be found and where they should be loaded from?
Related
We are developing plugins to be added to a giant & awesome software. We often reuse the same WPF controls so we packaged them and created separate assemblies for each of them.
Sometimes, we need to load 2 different plugins within the same instance of the software. At that point, if the 2 plugins use the same reusable control but with different DLL versions, WPF doesn't seem to be able to choose the correct one. Both DLLs are correctly loaded (seen using Process Explorer).
What we already tried :
Binding redirects
Assembly redirects
Overridden assembly resolving
Is there any solution to indicate to WPF which version of the same DLL it needs to select for requested namespace in XAML ? Could we force the use of the latest in some way (this would work for us) ?
Look at my commit o SharpDevelop: https://github.com/icsharpcode/SharpDevelop/commit/b3ea4a0efb7e3b8e083f8be40ea6f7e03ff44604
I fixed this, by using a custom "InitializComponent" Call! ("SpecialInitializeComponent") and using special merged ResourceDictionarys: VersionedAssemblyResourceDictionary! Hope that helps you!
I am working on an application that started out as a WinForm but it is now utilizing WPF windows with UI. The interaction is all working beautifully but when the WPF windows are first shown it takes quite a long time (around 1-3 seconds) for them to show. So long that some wonder if the app has crashed (until the content shows). The second time the same windows are invoked they come up quickly. I need them to come up quickly the first time around.
I am making use of styles and control templates that are located as XAML in the resource folder. In the XAML for the WPF windows I then merge them into the windows resource dictionary. The Build Action for those (in VS 2010) needs to be set to "Resource".
Preferably I want to keep them in separate files for easy maintenance.
As far as I understand if the build action was "Page" the XAML would be precompiled and should load faster but if I set it to Page I cannot merge them into the resource dictionary. Is there a way around that?
I am fairly new to this part of WPF and so far my internet search hasn't been successful.
To be clear: I am not talking about WPF controls being embedded in WinForms. I am talking about entirely separate WPF windows that are spawned from the WinForm context.
Is there a way to precompile the entire app or at least all XAML (it's all static, no dynamic XAML)?
Thanks in advance!
Edit: The UIs are not heavy by any means. The ones in question have between 5 and 20 buttons and the usual containers (basically a grid with 1 or 2 stack panels).
Update:
I tried precompilation with "NGEN install appname" - no effect on WPF window load.
I included all resources and templates into the window.xaml - no effect.
(window.xaml is pre-compiled)
I found this really interesting article about pre-jitting upon app load here:
http://www.codeproject.com/KB/dotnet/pre_JIT.aspx
(I used the improvement suggested by 'ittay ophir')
again: no effect on WPF window load...
The load times simply won't change on first load but they are significantly reduced on all consecutive loads (loads in 20ms or less).
What the heck is going on here?
How about loading the XAML asynchronously using XamlReader.LoadAsync Method ?
Microsoft has a handy reference of the various controls in the System.Windows.Controls namespace and which controls are included in the runtime.
For any controls listed here that aren't included in the runtime, you have to include the reference to the System.Windows.Controls assembly and select "copy local" in Visual Studio. So that's what I'm currently doing and it works.
However, by including this DLL I'm adding almost 80 KB to my XAP file (and my XAP file is only 110 KB). The only control I'm using that requires it is the GridSplitter. Is there a way to rebuild a condensed version of this assembly that includes the GridSplitter only?
It looks like I just found the answer for Silverlight 2...
Source Code for Silverlight 2 Runtime and SDK Controls
And I think that'll work for me for now. I should be able to go through the project and exclude all the unnecessary bits from the project and do a rebuild.
I'm still using Silverlight 2 but I will be switching to 3 in a couple months. And I can't seem to find the same thing for Silverlight 3. Maybe the source is not available yet for Silverlight 3?
UPDATE:
So I got this working after jumping through some hoops. At first I downloaded the source project from Microsoft and then just started removing stuff. But then I noticed that I couldn't build the solution. In fact I couldn't build an unmodified version of the solution either. I was getting errors about strong name verification. I tried unchecking strong name signing from the "Signing" section of the project properties but I got the same error. I even added the assembly to the strong name verification skip list and finally got past the error. But when I tried to include the new assembly in my Silverlight project and run it in a browser, I'd get a blank screen (the Silverlight control never loaded). I'm still not sure why but I'm sure I was missing something.
Finally I just created a fresh project. It seems I should've done this from the beginning. I just needed to create an empty C# Silverlight Class Library for the GridSplitter. Then I started adding the source files necessary for the GridSplitter to this project and then I set the namespace and assembly name to System.Windows.Controls. After building this project, and referencing it in my Silverlight app it finally worked. The result: a 60 KB savings.
I wrote a little more about this here:
http://regexhero.net/blog/2009/09/optimizing-silverlight-xap-file.html
In case anyone wants them, I've got 4 of the controls from the SDK right here...
http://www.silverlightxap.com/controls/tagged/silverlight-sdk
The new Silverlight 3 beta includes the ability to run Out-of-Browser applications. The demos so far show this only inside a special frame. Does anyone know how I can run Siverlight 3 controls inside a (WPF) application?
No, you can not embed out-of-browser silverlight into WPF. The sllauncher.exe standalone frame has a special handler for the offline://(hostname).(revision)/ url given to it to allow the app to have all the features of out-of-browser mode (like extra keyboard access). Unless you can find a way to embed this app into your app, you won't be able to get out-of-browser; if you know some way to do this the address for this app is:
C:\Program Files\Microsoft Silverlight\3.0.40307.0\sllauncher.exe
As others have said, however, you can embed a silverlight control inside of an html page and that inside a WebBrowser element. Be cautious with this method, however, since there is currently no x64 support for Silverlight and if you absolutely must do this make sure to compile specifically for x86.
I'm guessing (yes, shame on me!) but you can probably put a WPF web browser on your window and navigate to the Silverlight app inside it.
This is a supported scenario; a recent MSDN article stated this scenario was supported, and scenarios like this forced the CLR team to allow multiple CLRs loaded into a single process.
It seems that SLOOB apps run inside a host process (C:\Program Files\Microsoft Silverlight\3.0.40307.0\sllauncher.exe). This hosts and sandboxes the app.
I suspect that it will not be possible to host it yourself - sorry if that's a little close to guessing, but short of running a hosting web browser in your WPF app I can't think of a way around the sandboxing requirement.
HTH
You can host a browser control inside a windows app, and load silverlight inside the browser control. This is how live mesh is going to do it.
Quick intro: I have some Silverlight 1 content that people have been editing and putting into HTML pages. Unfortunately, this means a lot of repetative creation of Storyboards, etc. We can use Silverlight 2, but not everyone here is familiar with C#/has Visual Studio. What I would like to do is create some custom controls in C#, output to a DLL, then reference the DLL in the XAML file (just as if it was part of a Silverlight project in VS).
I've tried adding this:
xmlns:mycontrol="clr-namespace:MyControl;assembly=../../content_GLOBAL/controls/MyControl/MyControl"
in the Grid tag that is my root. I know the path to MyControl.dll is correct. When I actually try and use it, though (I add <mycontrol:MyControl></mycontrol:MyControl> to the grid) and I get a parser error. It all seems OK if I don't add the control, even if I leave in the xmlns.
I suppose on some level, this makes sense--looking for an assembly is useful if you are going to build something, and since this XAML isn't in VS, it isn't actually building anything. Is there another way that I can reference, and use a custom control in SL2 in a stand-alone XAML file?
Let me first make sure that I understand you correctly: You have a Silverlight app that doesn't use any managed code and is not packaged in a .xap file. The <object> tag refers to a loose xaml file.
This is the Silverlight 1 app model and can still be used in SL 2, and such apps are referred to as "v1-style apps" (even though they target SL 2 and may use features not present in v1). When an application in this form is used, the Silverlight plugin does not load any of the managed components of the runtime (e.g. the CLR, etc.), so referencing a dll from a v1 style app is not going to work.
However, there might be work-arounds to the challenge you are facing here. One solution might be to use a v2 style app that is packed into a .xap and uses managed assemblies. One of the reasons you gave for not doing this is that other developers one the team are not familiar with C#. This should not be an issue as C# is not a requirement for building apps in SL, you can continue to program against it in JavaScript. And if you are just writing JavaScript code, Visual Studio is not a requirement, since there is nothing to compile. They can just edit the .html/.js files and use the .xap/.dll files that were already compiled. Does this make sense?