I used the shader templates given through Greg Schechter's blog: http://blogs.msdn.com/greg_schechter/archive/2008/08/11/a-visualstudio-buildtask-and-project-and-item-templates-for-writing-shadereffects.aspx
It was all simple to add the wpf shader templates and create the project. I'm also able to see that the shader is working through the visual studio 2008 designer when editing my xaml. But I get this error when I run my program:
Cannot find type 'ShaderEffectLibrary1.Effect1'. The assembly used when compiling might be different than that used when loading and the type is missing.
Make sure your top level project (for the GUI) also has a reference to the ShaderEffectLibrary. I ran across a similar problem today where I was referencing a third-party library from within my WPF user control library. It built fine, but then I would receive a similar exception at execution time. It turned out that adding a reference to the third-party library from the top level project resolved the exception.
Related
I am trying to use Nish Nishant's classes to extend the system menu of a WPF window. Nish's project is in Code Project as An MVVM friendly approach to adding system menu entries in a WPF application
I have included Nish's source files in my project and defined some menu commands for the system menu.
This was easy and as far as I can tell it is working correctly. I am not getting a runtime error.
However, the XAML designer is showing me the error
'System.Windows.FreezableCollection`1[NS.MVVM.SystemMenuItem]' is not a valid value for property 'MenuItems'.
This error only appears after compiling the project. I do not get the error in Nish's sample project. I am using Visual Studio 2019 version 16.8.3. What might be causing this error message?
EDIT
I now know what is causing the error message, in the sense that I know what the difference is between my project and Nish's sample project.
Nish's project targets the x86 platform, whereas my project targeted Any CPU.
This is understandable, because the code uses Win32 API functions. I have changed the target platform for my project to x86 and the error has gone.
However, I still don't really understand why the error occurs and how it relates to the underlying issue of target platform.
I have a winform usercontrol than I want to add to wpf project.
I added the relevant references (WindowsFormsIntegration, SystemWindowsForms and my user control dll) and added this row in my XAML:
xmlns:MyControl="clr-namespace:xx.xx.xx;assembly=xx.xx"
And then this:
<WindowsFormsHost><MyControl:control></MyControl:control></WindowsFormsHost>
When I write "MyControl:" the "control" is automated show up that mean VS recognize the control and all references added ok... but when I compile the project this give me the error in the title.
Edit
Its very strange when I'm compile the all project i've got error "The type or namespace name "xx' could not be found..."
but I added all the refernces and the VS recognize the namespace so why the compiler don't found them? If this problem will be solved I beleive the other problem also will disappear.
The solution is: Go to your project properties and change the Target Framework from Client Profile to the full version of the .Net you are using, see the image below. This problem happens if your DLL targets the full .NET Framework, and your WPF Application (main project) targets .Net Client Profile.
This happened to me when I included the assembly name in the namespace definition, but both controls were in the same assembly. Just removing the assembly part of the namespace declaration solved it.
Visual Studio will load the reference only for reflection so it will show correct intellisense correctly. But in order to compile, compiler will need all the dlls that your referenced dll is dependent on. So visual studio will show intellisense for mycontrol as it can find it in reference. But your myontrol may reference other dlls which you may not have added. You will have to add dependent references of mycontrol in your project too.
It could also be that the target framework is different between your projects. We host a class library dll with the WPF pages, and it was targeted to 'Any CPU', but the host application was targeted to 'x86'. Once they matched, the problem went away.
I ran into the same "The type or namespace name 'xx' could not be found..." issue.
It disappears when I moved my Visual Studio files on a local drive. They were stored on a shared network directory before. I dont know the root cause of this, but at least I can have my designer running now.
I've encountered this problem before and replacing <MyControl:control></MyControl:control> with just <MyControl:control/> fixed it for me.
No idea why though. It seems like the first form is only for controls which can contain other controls.
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
i have a project that i am doing and i need to share the code between silverlight and WPF Assembly problem is that even though the wpf assembly is the owner of that file
and the silverlight assembly only has a link to the file, all of the build actions are page everything is correct. if i make the silverlight assembly the owner then silverlight works and wpf doesnt, and currently with wpf being the owner i dont get any errors at all it just never styles the control like it cannot find it..
Note: both projects exists in the same solution.
this scenario builds and runs fine
wpf project
|__Themes
|__Generic.xaml
|__SomeControl.cs
this scenario builds and runs but will not display the control
if i change them from linked to normal it will work fine.
i just want to share this source code and not have multiple versions of the same file floating around.
SilverlightProject
|__Themes
|__"Linked"Generic.xaml
|__"Linked"SomeControl.cs
sorry for my corny Tree view representation
+++++++ UPDATE +++++++++
i have noticed when using any linked file regardless of if it is silverlight or WPF
the link file will not build into the Themes folder in the resource only the root.
i used reflector to see where my resources ended up after compilation of the assembly including the linked file and they ended up in the root , so with that being said. is there a way to prevent this or a fix for this if this is indeed non intended behavior .
i would really love to get this figured out as it has been driving me insane for a while now.
Silverlight XAML and WPF XAML do not have the same namespace - so they aren't directly reusable.
My mistake - you're right - now with Silverlight 3 the namespaces are the same:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml
What is the Build Action in the Property Pane for the XAML?
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?