I have the following code:
XAML code for Window1.xaml and the VB.Net code for Window1.xaml.vb.
The error I get is the following:
"Cannot create instance of 'Window1' defined in assembly 'ServiceControl, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Exception has been thrown by the target of an invocation. Error in markup file 'ServiceControl;component/Window1.xaml' Line 2 Position 2."
I can't see any problem in the code and what it should do is trigger an animation depending on the status of a service (spooler service in this case). It may be because I am manually referencing to the System.ServiceProcess namespace, which is not available in WPF framework by default, but I'm not sure. Anybody can help?
Thanks.
You're only looking at the top level exception message. Drill in and look at the inner exception.
Related
I have a Class Library project with default controls and styles in. I created a Nuget package from this project. I then tried to use the Package Manager in Visual Studio to add a reference to another project, but this is where I have the problem.
The reference gets added successfully, but then I cannot access the App.xaml file from the packaged project in a ResourceDictionary within the MergedDictionaries property of the consumer project's App.xaml file:
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/DefaultStyles;component/App.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
I get an inline error on this line (not shown in the Error List) stating:
Assembly 'DefaultStyles' is not referenced by this project
But it is referenced by the project. I can see the reference in the Project References and I have Intellisense for the controls that are in the referenced project.
Also, the project builds successfully, but I have two similar errors displayed in the Error List:
The name "ImageWithSingleTextLine" does not exist in the namespace "clr-namespace:DefaultStyles.ItemTemplates;assembly=DefaultStyles".
But it does exist in there and I get Intellisense for it, so that if I try to write the line again, it auto completes for me... and then gives me the error again. No amount of cleaning, building and rebuilding will fix the issue.
It's not until I try to run the application that I get a further clue. A XamlParseException is thrown from the App.xaml.cs constructor, stating:
The invocation of the constructor on type 'DefaultStyles.App' that matches the specified binding constraints threw an exception.
It also has an inner Exception of type InvalidOperationException:
Cannot create more than one System.Windows.Application instance in the same AppDomain.
So, it seems like that is the root cause of the problem. In the default styles project, I have extensively used the App.xaml file, and added an event handler into the App.xaml.cs code behind file.
My question is how can I make this all work?
As you correctly discovered, you cannot have more than a single instance of the Application class in one AppDomain. The solution is to move the contents of your App.xaml file into a ResourceDictionary and use that instead. You can still use a code behind file for a standard ResourceDictionary, if you need to.
I have a very simple project where are all files are within the same solution. Getting this weird issue when trying to reference resources in a user control specifically. The same pack uri syntax works perfectly well in MainWindow.xaml but when used in user control is giving an error.
Here is my files folder structure:
Here is my Mainwindow.xaml screenshot:
SummaryView.xaml (UserControl) screenshot:
Try writing out the name of the assembly explicitly:
"pack://application:,,,/FIBRE_Reporting;component/Resources/Brushes.xaml"
I'm attempting to follow the instructions to create a reusable modal window in LightSwitch from Jan Van der Haegen's blog. However after I click to add a new Silverlight User Control to the Client, and input the xaml I'm met with errors. I reduced the code to the shortest section that gives me an error:
HRESULT E_FAIL has been returned from a call to a COM component.
From the following xaml:
<shellUtils:ScreenChildWindow
xmlns:shellUtils="clr-namespace:Microsoft.LightSwitch.Runtime.Shell.Framework;assembly=Microsoft.LightSwitch.Client">
</shellUtils:ScreenChildWindow>
I just installed Visual Studio 2012 in a virtual machine, created a new project, new Client Silverlight User Control, and tried the same code and received the same error.
I also receive it with this code and others referencing Microsoft.LightSwitch.Client:
<Framework:GroupBox
xmlns:Framework="clr-namespace:Microsoft.LightSwitch.Presentation.Framework;assembly=Microsoft.LightSwitch.Client">
</Framework:GroupBox>
Comments on the blog seem to indicate others have this error but I haven't found a solution anywhere yet. I also see the same/similar on Stackoverflow here, but unanswered.
Yes that's correct, just close the preview window. The XAML designer has a hard time rendering the control when referencing the LS assemblies. You can ignore these errors.
If you're seeing these errors elsewhwere please let me know and we can investigate.
After scouring the internet for the slightest related issue, I discovered at least in my case the design view errors can be entirely ignored.
Even with the other errors I didn't mention:
Undefined CLR namespace. The 'clr-namespace' URI refers to a namespace
Microsoft.LightSwitch.Cosmopolitan.Presentation.Controls' that could
not be found.
The type 'ctls:OverflowControl' was not found. Verify that you are not
missing an assembly reference and that all referenced assemblies have
been built.
An error occurred while finding the resource dictionary
/Microsoft.LightSwitch.Cosmopolitan.Client;component/Presentation/Shells/BasicStyles.xaml"
The control works perfectly. All the assembly preferences are present, so I'm not sure why the designer claims otherwise.
I'm having trouble using the Ribbon control from the Office 2007 RibbonControlsLibrary.dll.
It works for most people but not for me. The fault I get is:
Cannot create instance of 'Ribbon' defined in assembly 'RibbonControlsLibrary, Version=3.5.31016.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. Exception has been thrown by the target of an invocation
The problem is probably not with the code since it works for other people.
Its the Ribbon class thats causing the problem. If I remove any references to the Ribbon class but keep the references to RibbonWindow I don't get any exceptions.
Any help appreciated
I fixed it...
My problem was that RibbonControlsLibrary.dll was in the GAC... as soon as I removed it from the GAC it worked like a charm...
I have a custom WPF UserControl in a DLL file. I access the UserControl from PowerBuilder via OleObject (COM). I'm trying to create an instance of the UserControl (code in .NET dll).
Everything works fine when I'm using it via COM from C++, but in PowerBuilder, I'm getting this error message:
Error Message
Can you help me to figure out, what the problem is?
Tell me, if you need some more information.
Thank you so much!!
Found the solution. :)
Had to load the assembly WPFToolkit.dll and System.Windows.Controls.DataVisualization.Toolkit.dll manually via Assembly.LoadFrom("...");
Now it works!
I think you will have to load all assemblies which contain custom classes which are used in the xaml this way.