WPF Add-In: UriFormatException when trying to use SiteOfOrigin

W

Wonko the Sane

Hi Gurus,

We have an WPF Add-In that we use to interact with our main WPF application.
In order to localize it, I am trying to use a pack command to build a Uri as
follows:

string resourcesFileName = @"pack://SiteOfOrigin:,,,/MyPath/MyFile_us.xaml";
Uri uriResources = new Uri(resourcesFileName, UriKind.Absolute);

When the call to create the Uri gets run, it gives the following
UriFormatException:

Invalid URI: A port was expected because of there is a colon (":") present
but the port could not be parsed.

Any ideas on how I can get a reference to this relative path where the
Add-In resides, so I can (eventually) load the ResourceDictionary XAML file?

Thanks,
WtS
 
L

Linda Liu[MSFT]

Hi WtS,

Based on my understanding, you have a WPF Add-in and a WPF application.
What you'd like to do is to access a resource from the WPF application. If
I'm off base, please feel free to let me know.

Is the "MyFile_us.xaml" file you mentioned a separate file or built into
the add-in assembly? If it is the former, please make sure that this XAML
file exists under the "MyPath" subfolder of the WPF application executable
directory.

I find two MSDN documents which introduce WPF add-ins and pack URI in WPF
and may be helpful to you:
'Windows Presentation Foundation Add-Ins Overview'
http://msdn.microsoft.com/en-us/library/bb909794.aspx

'Pack URIs in Windows Presentation Foundation'
http://msdn.microsoft.com/en-gb/library/aa970069.aspx

Hope this helps.

Sincerely,
Linda Liu
Microsoft Online Community Support


==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.asp...
ications.


Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
W

Wonko the Sane

Hi Linda,

Actually, the issue was that I wanted to use a resource within the Add-In
itself (i.e. the resource is defined in the Add-In, so we don't need to
recompile the entire application to update the Add-In.

In my case, I found that jsut using a relative Uri instead of the absolute
Uri.
string resourcesFileName = "/MyPath/MyFile_us.xaml";
Uri uriResources = new Uri(resourcesFileName, UriKind.Relative);

Thanks for the help and the links!

WtS
 
W

Wonko the Sane

I do have a follow-up question.

If the ResourceDictionary has a blank string value:
<s:String x:Key="String1"></s:String>

I get a XamlParseException because String does not have a default (blank
parameter) constructor. Is there any way to avoid that, without actually
specifying a value for that element?

Thanks,
WtS
 
L

Linda Liu[MSFT]

Hi WtS,

Thank you for your reply and I'm glad to hear that your original problem is
fixed.
I get a XamlParseException because String does not have a default (blank
parameter) constructor. Is there any way to avoid that, without actually
specifying a value for that element?

The Application.LoadComponent method parse the compiled XAML and generate a
tree of objects described by the XAML. We can see that WPF calls the
constructor of the type specified in the XAML element to create an object
internally.

In your case, the String element has no value specified, so WPF tries to
call the constructor of type String with no parameter, which results the
exception.
I'm afraid we have no method to change this behavior. That's to say, you
may need to specify a value for the String element to fix the problem.

If you have any concern, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support
 
W

Wonko the Sane

Hi Linda,

Thanks for the information. I wish that there was a either a default String
constructor (defaulting to null, most likely) or a property that could be set
for LoadComponent, but we'll have to kludge something in for now.

Thanks again (as always),
WtS
 
L

Linda Liu[MSFT]

Hi WtS,

Thank you for your response and you're welcome!

If you have any other questions in the future, please don't hesitate to
contact us. It's always our pleasure to be of assistance.

Have a nice day!

Sincerely,
Linda Liu
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top