I'm tring to create a generic collection of dynamic type at runtime of Silverlight application. My code:
Type listType =
Type.GetType("System.Collections.ObjectModel.ObservableCollection`1[["
+ type.AssemblyQualifiedName
+ "]], System.Windows, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e",
true);
type is a variable of Type type. That Type is creating at runtime. At that code line I've got error:
Could not load file or assembly ', Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
How can I resolve that error?
Use MakeGenericType instead:
Activator.CreateInstance(typeof(ObservableCollection<>).MakeGenericType(type));
Related
warning C4945: 'IContainerRegistryExtensions':
cannot import symbol from 'd:\repos\bitbucket\runtempl-dataaccess-branch\core\bin\prism.dll':
as 'Prism::Ioc::IContainerRegistryExtensions' has already been imported from another assembly 'Prism.Wpf':
message: first seen type is used; re-order imported assemblies to use the current type
message: This diagnostic occurred while importing type 'Prism.Ioc.IContainerRegistryExtensions' from assembly 'Prism, Version=7.2.0.1422, Culture=neutral, PublicKeyToken=40ee6c3a2184dc59'.
This occurs when a single compilation unit attempts to use both assemblies... The interface is declared in both Prism assemblies (and they are different).
I'm getting a dozen "Invalid Resx file. ResX input is not valid. Cannot find valid "resheader" tags for the ResX reader and writer type names." err msgs on trying to compile.
I had this problem before, as can be seen here.
This time, though, it manifests itself a little differently.
First, here is what I did: I selected the context menu item "Undo Pending Changes" on several files in a project. For each of them, their related *.resx file apparently got corrupted.
2-clicking the first err msg in the Error List takes me here in the .resx file:
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
2-clicking the next err takes me here in the .resx file:
<resheader name="resmimetype">text/microsoft-resx</resheader>
This is a commented out explanatory section; in a little bit of context:
<!--
Microsoft ResX Schema
Version 1.3
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">1.3</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1">this is my long string</data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
[base64 mime encoded serialized .NET Framework object]
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
[base64 mime encoded string representing a byte array form of the .NET Framework object]
</data>
. . .
All 10 other 2-clickings takes me right to the first line in the .resx file, namely:
<?xml version="1.0" encoding="utf-8"?>
Hans Passant's answer to the same question by a different cat here indicates superfluous white space needs to be removed; I see no such extra white space in my .resx files, though...
What need I do to fix these mangled .resx files?
UPDATE
It may be that those first two locations where the err msg seems to point are bogus/misleading; they may be simply places in the files where I had previously put my cursor (odd that the err msg would go there instead of to the supposed location of the problem, though...)
UPDATE 2
According to the err msg, the failing *.resx files are missing valid resheader reader/writer tags. Yet those tags/declarations do exist there in the failing *.resx files. These look like this:
<resheader name="reader">
<value>System.Windows.Forms.Design.CFResXResourceReader, System.CF.Design,
Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</resheader>
<resheader name="writer">
<value>System.Windows.Forms.Design.CFResXResourceWriter, System.CF.Design,
Version=7.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</resheader>
....but, interestingly enough (if you're an uebergeek, anyway) those do differ from the RESX readers and writer declarations in other (compiling) forms, which look like this:
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0,
Culture=neutral,PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0,
Culture=neutral,PublicKeyToken=b77a5c561934e089</value>
</resheader>
If I replace the RESX reader/writer declarations in the non-compiling forms with the other format (IOW I replace "System.Windows.Forms.Design.CFResXResourceReader, System.CF.Design, Version=7.0.5000.0" with "System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0" (and use the differing public key tokens), it compiles!
BUT (and this is a big but[t] (think Bertha)), the machine on which this project is being compiled is a PC (of course), but the target machine on which the .exe will run is a Compact Framework (handheld) device. So, will replacing the "CF" with the more generic RESX verbiage prove problematic once the .exe is moved from point PC to point Handheld Windows CE device?
In XAML-file of the SquadView page (VfmElitaSilverlightClientView.Pages.SquadView) I am using custom value converter. XAML-file is in "VfmElitaSilverlightClientView" namespace. Separate folder was created for converter and it is in "VfmElitaSilverlightClientView.Converter" namespace (in the same assembly). To use converter following code is used in XAML:
xmlns:Converter="clr-namespace:VfmElitaSilverlightClientView.Converter"
...
<NavigationControls:Page.Resources>
<Converter:BooleanToVisibilityConverter x:Key="resourceBooleanToVisibilityConverter" />
</NavigationControls:Page.Resources>
All works fine. Here I want to move converter class into a custom separate assembly "SilverlightCommonView" and class himself will be in "SilverlightCommonView.Converter" namespace. The XAML code is changed to the following:
xmlns:Converter="clr-namespace:SilverlightCommonView.Converter;assembly=SilverlightCommonView"
...
<NavigationControls:Page.Resources>
<Converter:BooleanToVisibilityConverter x:Key="resourceBooleanToVisibilityConverter" />
</NavigationControls:Page.Resources>
In this case when application throws following exception:
An unhandled exception ('Unhandled
Error in Silverlight Application...
Code: 4004 Category:
ManagedRuntimeError Message:
Microsoft.Practices.Unity.ResolutionFailedException:
Resolution of dependency failed, type="VfmElitaSilverlightClientView.Pages.SquadView",
name="(none)".
Exception occurred while: Calling constructor
VfmElitaSilverlightClientView.Pages.SquadView(). Exception is: XamlParseException -
The type 'BooleanToVisibilityConverter' was not found because
'cl...:SilverlightCommonView.Converter;assembly=SilverlightCommonView'
is an unknown namespace.
It's unclear why specified namespace is unknown (those assembly is referenced by the current one).
Please advise.
Any thoughts are welcome.
I'd bet you do not have an assembly reference to your shared/common project from your application project.
I want to run my wpf application "A" from another assembly "B".
I use the following code:
static void main()
{
var app = new A.App();
app.InitializeComponent();
app.Run();
}
when i run my app I got the following error:
Cannot convert string '/Resources/icon.gif' in attribute 'Icon' to object of type 'System.Windows.Media.ImageSource'. Cannot locate resource 'resources/icon.gif'. Error at object 'MainWindow' in markup file 'A;component/shell/shellview.xaml'.
How can I transfer from B images and resources info to A?
Thanks!
Are you using the Pack URI?
You can use the pack URI syntax to access resources embedded in other assemblies. The following example demonstrates the basic pack URI syntax for accessing embedded resources in other assemblies:
pack://application:,,,/;component//
Thus, if you wanted to locate a file named myPic.bmp in the folder myFolder in another assembly named myAssembly, you would use the following pack URI:
Pack://application:,,,/myAssembly;component/myFolder/myPic.bmp
As with other pack URIs, if the embedded file does not exist within a folder, the folder is omitted in the URI.
TRy using something like this:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary
Source="CustomControls.Controls;component\Themes/...."
/>
</ResourceDictionary.MergedDictionaries>
Today I had the same problem, and I solved it by putting just:
Source="../../Resources/name.jpg"
I have this wpf form; the call to InitializeComponent() brings up this message:
Binding Failure was detected.
The assembly with display name
'Csla.Luna' failed to load in the
'Load' binding context of the
AppDomain with ID 1. The cause of the
failure was:
System.IO.FileNotFoundException: Could
not load file or assembly 'Csla.Luna,
Version=3.6.1.0, Culture=neutral,
PublicKeyToken=93be5fdc093e4c30' or
one of its dependencies. The system
cannot find the file specified.
File name: 'Csla.Luna, Version=3.6.1.0, Culture=neutral,
PublicKeyToken=93be5fdc093e4c30'
=== Pre-bind state information ===
LOG: User = DOMAIN\blah.blah
LOG: DisplayName = Csla.Luna, Version=3.6.1.0, Culture=neutral,
PublicKeyToken=93be5fdc093e4c30
(Fully-specified)
LOG: Appbase = file:///D:/MyPath/bin/Debug/
LOG: Initial PrivatePath = NULL
Calling assembly : PresentationFramework,
Version=3.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35.
===
LOG: This bind starts in default load context.
LOG: Using application configuration file:
D:\MyPath\bin\Debug\Myapplication.vshost.exe.Config
LOG: Using machine configuration file from
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\config\machine.config.
LOG: Post-policy reference: Csla.Luna, Version=3.6.1.0,
Culture=neutral,
PublicKeyToken=93be5fdc093e4c30
LOG: Attempting download of new URL
file:///D:/MyPath/bin/Debug/Csla.Luna.DLL.
LOG: Attempting download of new URL
file:///D:/MyPath/bin/Debug/Csla.Luna/Csla.Luna.DLL.
LOG: Attempting download of new URL
file:///D:/MyPath/bin/Debug/Csla.Luna.EXE.
LOG: Attempting download of new URL
file:///D:/MyPath/bin/Debug/Csla.Luna/Csla.Luna.EXE.
We use Csla but in a data access component that is not developed by me;
I don't know what Csla.Luna is, and I couldn't find anything about it online. Any help?...
The only "out of the ordinary" thing that I am doing on that form is that I am binding to some ObjectDataProviders that call static methods accessing the database, but It worked so far, and I can't tell whether this is the problem or not.
Any help would be appreciated. Can't believe that Google has no clue about this Csla.Luna thing.
I don't believe Csla.Luna is part of the original framework. You should try and contact the person in charge of developing the data acces component to find out more about it.
In any case, it seem that you are missing this file (Csla.Luna.dll).
You could also use Reflector to pinpoint the location of the call to this Csla.Luna assembly...