IOException: 'Cannot locate resource' in Visual Studio











up vote
0
down vote

favorite












I have a WPF program, with a main window, which utilizes some resource dictionaries, located in a subfolder, as you can see here (we will soon get to, why I highlighted one of them):



File structure in my project



In the top of my MainWindow.xaml, I include some of these resource dictionaries, like this:



<ResourceDictionary>      
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/XamlResources/ControlTemplates.xaml" />
<ResourceDictionary Source="pack://application:,,,/XamlResources/TextBlockStyles.xaml" />
<ResourceDictionary Source="pack://application:,,,/XamlResources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>


So obviously everything is as it should be, and the program does compile and run just fine. No exceptions, no warnings, all is good. Except it's not. Because in the Visual Studio Editor, this is what the design window shows:



IOException in the Visual Studio editor.



Why do I get this error, when everything apparently is as it should be? I have event tried using the "Find" feature to search for other occurrences of controltemplate.xaml, but I only find valid references. Is this some sort of Visual Studio bug, and if so, how do I fix it?



UPDATE



Fiddling around with the XAML (for instance changing the way the source is formatted) sometimes causes the error to change to an SqlException, like this:



SqlException, which sometimes occur instead of the IOException.



I have no idea why this happens, or why the exception seems to change from time to time. I am using Entity Framework, if that could be the root cause, but I do not have a local SQL server installed. However, this hasn't been a problem in previous projects.










share|improve this question
























  • Did you try <ResourceDictionary Source="XamlResources/ControlTemplates.xaml" />?
    – Kaspar
    Nov 21 at 13:44










  • @Kaspar I have tried that. It doesn't change a whole lot. However, sometime the error changes to an XamlParseException instead. It still states though, that i cannot locate resource xamlresource/controltemplates.xaml.
    – Noceo
    Nov 21 at 13:53










  • Have you checked the encoding of the file? I've had in the past the encoding being changed from utf-8 to utf-8 with signature which Visual Studio dislikes.
    – Coops
    Nov 21 at 15:08










  • @Coops not sure how to check that. I haven't changed the encoding (at least not on purpose), also wouldn't that break the program entirely?
    – Noceo
    Nov 23 at 10:38










  • Open the file in Notepad++ and there's an encoding menu, just check that it's utf-8 and not utf-8 signed.
    – Coops
    Nov 23 at 10:40















up vote
0
down vote

favorite












I have a WPF program, with a main window, which utilizes some resource dictionaries, located in a subfolder, as you can see here (we will soon get to, why I highlighted one of them):



File structure in my project



In the top of my MainWindow.xaml, I include some of these resource dictionaries, like this:



<ResourceDictionary>      
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/XamlResources/ControlTemplates.xaml" />
<ResourceDictionary Source="pack://application:,,,/XamlResources/TextBlockStyles.xaml" />
<ResourceDictionary Source="pack://application:,,,/XamlResources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>


So obviously everything is as it should be, and the program does compile and run just fine. No exceptions, no warnings, all is good. Except it's not. Because in the Visual Studio Editor, this is what the design window shows:



IOException in the Visual Studio editor.



Why do I get this error, when everything apparently is as it should be? I have event tried using the "Find" feature to search for other occurrences of controltemplate.xaml, but I only find valid references. Is this some sort of Visual Studio bug, and if so, how do I fix it?



UPDATE



Fiddling around with the XAML (for instance changing the way the source is formatted) sometimes causes the error to change to an SqlException, like this:



SqlException, which sometimes occur instead of the IOException.



I have no idea why this happens, or why the exception seems to change from time to time. I am using Entity Framework, if that could be the root cause, but I do not have a local SQL server installed. However, this hasn't been a problem in previous projects.










share|improve this question
























  • Did you try <ResourceDictionary Source="XamlResources/ControlTemplates.xaml" />?
    – Kaspar
    Nov 21 at 13:44










  • @Kaspar I have tried that. It doesn't change a whole lot. However, sometime the error changes to an XamlParseException instead. It still states though, that i cannot locate resource xamlresource/controltemplates.xaml.
    – Noceo
    Nov 21 at 13:53










  • Have you checked the encoding of the file? I've had in the past the encoding being changed from utf-8 to utf-8 with signature which Visual Studio dislikes.
    – Coops
    Nov 21 at 15:08










  • @Coops not sure how to check that. I haven't changed the encoding (at least not on purpose), also wouldn't that break the program entirely?
    – Noceo
    Nov 23 at 10:38










  • Open the file in Notepad++ and there's an encoding menu, just check that it's utf-8 and not utf-8 signed.
    – Coops
    Nov 23 at 10:40













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a WPF program, with a main window, which utilizes some resource dictionaries, located in a subfolder, as you can see here (we will soon get to, why I highlighted one of them):



File structure in my project



In the top of my MainWindow.xaml, I include some of these resource dictionaries, like this:



<ResourceDictionary>      
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/XamlResources/ControlTemplates.xaml" />
<ResourceDictionary Source="pack://application:,,,/XamlResources/TextBlockStyles.xaml" />
<ResourceDictionary Source="pack://application:,,,/XamlResources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>


So obviously everything is as it should be, and the program does compile and run just fine. No exceptions, no warnings, all is good. Except it's not. Because in the Visual Studio Editor, this is what the design window shows:



IOException in the Visual Studio editor.



Why do I get this error, when everything apparently is as it should be? I have event tried using the "Find" feature to search for other occurrences of controltemplate.xaml, but I only find valid references. Is this some sort of Visual Studio bug, and if so, how do I fix it?



UPDATE



Fiddling around with the XAML (for instance changing the way the source is formatted) sometimes causes the error to change to an SqlException, like this:



SqlException, which sometimes occur instead of the IOException.



I have no idea why this happens, or why the exception seems to change from time to time. I am using Entity Framework, if that could be the root cause, but I do not have a local SQL server installed. However, this hasn't been a problem in previous projects.










share|improve this question















I have a WPF program, with a main window, which utilizes some resource dictionaries, located in a subfolder, as you can see here (we will soon get to, why I highlighted one of them):



File structure in my project



In the top of my MainWindow.xaml, I include some of these resource dictionaries, like this:



<ResourceDictionary>      
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/XamlResources/ControlTemplates.xaml" />
<ResourceDictionary Source="pack://application:,,,/XamlResources/TextBlockStyles.xaml" />
<ResourceDictionary Source="pack://application:,,,/XamlResources/Styles.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>


So obviously everything is as it should be, and the program does compile and run just fine. No exceptions, no warnings, all is good. Except it's not. Because in the Visual Studio Editor, this is what the design window shows:



IOException in the Visual Studio editor.



Why do I get this error, when everything apparently is as it should be? I have event tried using the "Find" feature to search for other occurrences of controltemplate.xaml, but I only find valid references. Is this some sort of Visual Studio bug, and if so, how do I fix it?



UPDATE



Fiddling around with the XAML (for instance changing the way the source is formatted) sometimes causes the error to change to an SqlException, like this:



SqlException, which sometimes occur instead of the IOException.



I have no idea why this happens, or why the exception seems to change from time to time. I am using Entity Framework, if that could be the root cause, but I do not have a local SQL server installed. However, this hasn't been a problem in previous projects.







c# wpf visual-studio xaml visual-studio-2017






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 at 14:17

























asked Nov 21 at 13:29









Noceo

9751331




9751331












  • Did you try <ResourceDictionary Source="XamlResources/ControlTemplates.xaml" />?
    – Kaspar
    Nov 21 at 13:44










  • @Kaspar I have tried that. It doesn't change a whole lot. However, sometime the error changes to an XamlParseException instead. It still states though, that i cannot locate resource xamlresource/controltemplates.xaml.
    – Noceo
    Nov 21 at 13:53










  • Have you checked the encoding of the file? I've had in the past the encoding being changed from utf-8 to utf-8 with signature which Visual Studio dislikes.
    – Coops
    Nov 21 at 15:08










  • @Coops not sure how to check that. I haven't changed the encoding (at least not on purpose), also wouldn't that break the program entirely?
    – Noceo
    Nov 23 at 10:38










  • Open the file in Notepad++ and there's an encoding menu, just check that it's utf-8 and not utf-8 signed.
    – Coops
    Nov 23 at 10:40


















  • Did you try <ResourceDictionary Source="XamlResources/ControlTemplates.xaml" />?
    – Kaspar
    Nov 21 at 13:44










  • @Kaspar I have tried that. It doesn't change a whole lot. However, sometime the error changes to an XamlParseException instead. It still states though, that i cannot locate resource xamlresource/controltemplates.xaml.
    – Noceo
    Nov 21 at 13:53










  • Have you checked the encoding of the file? I've had in the past the encoding being changed from utf-8 to utf-8 with signature which Visual Studio dislikes.
    – Coops
    Nov 21 at 15:08










  • @Coops not sure how to check that. I haven't changed the encoding (at least not on purpose), also wouldn't that break the program entirely?
    – Noceo
    Nov 23 at 10:38










  • Open the file in Notepad++ and there's an encoding menu, just check that it's utf-8 and not utf-8 signed.
    – Coops
    Nov 23 at 10:40
















Did you try <ResourceDictionary Source="XamlResources/ControlTemplates.xaml" />?
– Kaspar
Nov 21 at 13:44




Did you try <ResourceDictionary Source="XamlResources/ControlTemplates.xaml" />?
– Kaspar
Nov 21 at 13:44












@Kaspar I have tried that. It doesn't change a whole lot. However, sometime the error changes to an XamlParseException instead. It still states though, that i cannot locate resource xamlresource/controltemplates.xaml.
– Noceo
Nov 21 at 13:53




@Kaspar I have tried that. It doesn't change a whole lot. However, sometime the error changes to an XamlParseException instead. It still states though, that i cannot locate resource xamlresource/controltemplates.xaml.
– Noceo
Nov 21 at 13:53












Have you checked the encoding of the file? I've had in the past the encoding being changed from utf-8 to utf-8 with signature which Visual Studio dislikes.
– Coops
Nov 21 at 15:08




Have you checked the encoding of the file? I've had in the past the encoding being changed from utf-8 to utf-8 with signature which Visual Studio dislikes.
– Coops
Nov 21 at 15:08












@Coops not sure how to check that. I haven't changed the encoding (at least not on purpose), also wouldn't that break the program entirely?
– Noceo
Nov 23 at 10:38




@Coops not sure how to check that. I haven't changed the encoding (at least not on purpose), also wouldn't that break the program entirely?
– Noceo
Nov 23 at 10:38












Open the file in Notepad++ and there's an encoding menu, just check that it's utf-8 and not utf-8 signed.
– Coops
Nov 23 at 10:40




Open the file in Notepad++ and there's an encoding menu, just check that it's utf-8 and not utf-8 signed.
– Coops
Nov 23 at 10:40












1 Answer
1






active

oldest

votes

















up vote
0
down vote













We have a similar setup in our application and use this:



<ResourceDictionary>      
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Your.Assembly.Name;component/XamlResources/TextBlockStyles.xaml" />
<!-- ... -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>





share|improve this answer





















  • Fun stuff. If I make this changes, the designer displays the actual window (and content) for like a second, before then throwing a new exception, this time an SqlException (still at design time, no compiling or running the program).
    – Noceo
    Nov 21 at 14:13










  • @Noceo I wouldn't worry about on the designer preview too much, it's pretty finicky and often doesn't work although a control or window works when actually run. However the SqlException hints that loading of the styles now works and it has run in new issues in displaying data from your controls.
    – Lennart
    Nov 21 at 14:18











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413142%2fioexception-cannot-locate-resource-in-visual-studio%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













We have a similar setup in our application and use this:



<ResourceDictionary>      
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Your.Assembly.Name;component/XamlResources/TextBlockStyles.xaml" />
<!-- ... -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>





share|improve this answer





















  • Fun stuff. If I make this changes, the designer displays the actual window (and content) for like a second, before then throwing a new exception, this time an SqlException (still at design time, no compiling or running the program).
    – Noceo
    Nov 21 at 14:13










  • @Noceo I wouldn't worry about on the designer preview too much, it's pretty finicky and often doesn't work although a control or window works when actually run. However the SqlException hints that loading of the styles now works and it has run in new issues in displaying data from your controls.
    – Lennart
    Nov 21 at 14:18















up vote
0
down vote













We have a similar setup in our application and use this:



<ResourceDictionary>      
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Your.Assembly.Name;component/XamlResources/TextBlockStyles.xaml" />
<!-- ... -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>





share|improve this answer





















  • Fun stuff. If I make this changes, the designer displays the actual window (and content) for like a second, before then throwing a new exception, this time an SqlException (still at design time, no compiling or running the program).
    – Noceo
    Nov 21 at 14:13










  • @Noceo I wouldn't worry about on the designer preview too much, it's pretty finicky and often doesn't work although a control or window works when actually run. However the SqlException hints that loading of the styles now works and it has run in new issues in displaying data from your controls.
    – Lennart
    Nov 21 at 14:18













up vote
0
down vote










up vote
0
down vote









We have a similar setup in our application and use this:



<ResourceDictionary>      
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Your.Assembly.Name;component/XamlResources/TextBlockStyles.xaml" />
<!-- ... -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>





share|improve this answer












We have a similar setup in our application and use this:



<ResourceDictionary>      
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Your.Assembly.Name;component/XamlResources/TextBlockStyles.xaml" />
<!-- ... -->
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 14:01









Lennart

5,935124965




5,935124965












  • Fun stuff. If I make this changes, the designer displays the actual window (and content) for like a second, before then throwing a new exception, this time an SqlException (still at design time, no compiling or running the program).
    – Noceo
    Nov 21 at 14:13










  • @Noceo I wouldn't worry about on the designer preview too much, it's pretty finicky and often doesn't work although a control or window works when actually run. However the SqlException hints that loading of the styles now works and it has run in new issues in displaying data from your controls.
    – Lennart
    Nov 21 at 14:18


















  • Fun stuff. If I make this changes, the designer displays the actual window (and content) for like a second, before then throwing a new exception, this time an SqlException (still at design time, no compiling or running the program).
    – Noceo
    Nov 21 at 14:13










  • @Noceo I wouldn't worry about on the designer preview too much, it's pretty finicky and often doesn't work although a control or window works when actually run. However the SqlException hints that loading of the styles now works and it has run in new issues in displaying data from your controls.
    – Lennart
    Nov 21 at 14:18
















Fun stuff. If I make this changes, the designer displays the actual window (and content) for like a second, before then throwing a new exception, this time an SqlException (still at design time, no compiling or running the program).
– Noceo
Nov 21 at 14:13




Fun stuff. If I make this changes, the designer displays the actual window (and content) for like a second, before then throwing a new exception, this time an SqlException (still at design time, no compiling or running the program).
– Noceo
Nov 21 at 14:13












@Noceo I wouldn't worry about on the designer preview too much, it's pretty finicky and often doesn't work although a control or window works when actually run. However the SqlException hints that loading of the styles now works and it has run in new issues in displaying data from your controls.
– Lennart
Nov 21 at 14:18




@Noceo I wouldn't worry about on the designer preview too much, it's pretty finicky and often doesn't work although a control or window works when actually run. However the SqlException hints that loading of the styles now works and it has run in new issues in displaying data from your controls.
– Lennart
Nov 21 at 14:18


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53413142%2fioexception-cannot-locate-resource-in-visual-studio%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks