Best practice to resolve the URI error - wpf

I have a main project (ProjectA) that contain a base class (xaml + code-behind).
Also, I have another project (ProjectB) in reference with ProjectA. In that last
project I have inherits some user-control created in ProjectA.
When launching the main application, I receive the follow error:
The component 'XXX' does not have a resource identified by the URI
'/My.Assembly;component/.../simplegridview.xaml'
Is there a best way to resolve that problem?

I know it is not really a solution to the problem. But I have found that Clean and Build makes the error go away...

I encounter the same problem with VS 2013 sometimes, without any immediate cause e.g. after a reboot and rebuild from scratch. In such cases the solution build succeeds, it also runs but still the error list displays e.g. 5 URI errors. While sometimes clean and build suffies, other times you have to close VS, delete bin/obj folders of the project with the errors, reopen VS and then the errors have gone.

Related

Using log4net on nmodbus from not-main-project in a WPF project

So, i'm taking over a old project that uses nmodbus (and old version at that, 2.0_1.11.0.0, we decided it was best to not update). Nmodbus uses log4net for logging messages. I need to be able to view the logged messages, but it seems like log4net doesnt like WPF, or being in not-main-project.
Adding
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config")]
To the Nmodbus project AssemplyInfo.cs file gives me this error:
Severity Code Description Project File Line Suppression State
Error Unknown build error, 'Cannot resolve dependency to assembly 'log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821' because it has not been preloaded. When using the ReflectionOnly APIs, dependent assemblies must be pre-loaded or loaded on demand through the ReflectionOnlyAssemblyResolve event.' OptimalProdTest
Adding log4net, with NuGet Package Manager, to the main (WPF) project causes Nmodbus to stop working. (maybe has something to do with log4net being an older version in the old nmodbus project, and adding with NuGet will download the newest? Can i somehow add log4net from the other project into the main project without NuGet?)
I found other people with similiar problem who said i should add:
FileInfo configFileInfo = new FileInfo("log4net.config");
log4net.Config.XmlConfigurator.ConfigureAndWatch(configFileInfo);
to "the entry point of your library setup your logger", one guy said, another said "in the constructor of the wrapper class". However, i do not know what files these guys are talking about, nor do i know which project they meant (add to main project or nmodbus?).
( https://social.msdn.microsoft.com/Forums/vstudio/en-US/0c5d7fbb-94a3-4221-ab91-9732c5acee58/cannot-resolve-dependency-to-assembly-because-it-has-not-been-preloaded )
I'm lost and i can't find much help when googling. Anyone has any idea what i should do to be able to view the logs from log4net in nmodbus?

Permission denied error from loader on Windows

I have been getting this error for the past few weeks while programming in C. I'm confused on how to fix this since the error doesn't tell me where the error is coming from. Why can the compiler not open the output file?
Your bonus.exe file is busy due to some reason. Create a new project and try. Seems like you are working on Visual Studio. Close the application and reload also can fix your issue. This is not compilation issue rather build and link issue while it try to create bonux.exe second time it failed because your previous bonus.exe file is still busy. Also go to task manager and try to kill bonus.exe. That will also fix your issue.

Why do I get a "Metafile not found" error when trying to compile a WPF application?

I had to rebuild a project in my application.
I created a new project, created each file, and copied the contents of each file into the new project one at a time making all the necessary changes.
Now when I try to compile the project, it gives me three errors:
The metafile c:\projects\project1\CustomerModule\bin\Debug\CustomerModule.dll could not be found.
Application Definition Element could not be given by the library project file.
The project file has invalid properties.
Clicking any of these does nothing.
What are these errors telling me? What do I need to change to get my application running again?
New info: If I do a "rebuild" on just the project, I only get the second two errors, so these seem to be the original issue, but what is the library project file and what properties are invalid?
I found the answer on this forum question.
Basically the thing I did wrong was copy images from a directory in one module to a directory in another module within the Solution Explorer. Don't do this. Instead, copy them from the Windows Explorer into the Solution Explorer, then everything works fine.
Click add a reference and browse for the dll file you want to use.
You may have to rebuild the dll for it to work.

WPF App crashes outside of Visual Studio

I've got a WPF app that runs perfectly fine inside VS.NET, but if I try to run it outside of VS.NET, I get a "... has encountered a problem and needs to close.." dialog. This happens in Debug and Release modes. Why is this happening?
Most likely this is an uncaught exception. You might want to try using the Application.DispatcherUnhandledException Event to display a message box with the exception to narrow down the problem:
Add this to your App.xaml as an attribute to the <Application> tag:
DispatcherUnhandledException="Application_DispatcherUnhandledException"
while the implementation of that handler might look like the following:
private void Application_DispatcherUnhandledException(object sender, System.Windows.Threading.DispatcherUnhandledExceptionEventArgs e)
{
System.Windows.MessageBox.Show(e.Exception.ToString());
}
But without much context this could be anything that is causing it and you probably have a better understanding where it comes from when looking at the exception.
Make sure that you have all libraries that your executable requires to run in the same folder as the executable, as well as any necessary configuration files or manifest files.
Have you already attempted to run the application straight from the debug/release folders? Are all of your references marked as "Copy to output directory"?
Another thing to check is that your project file is not configured to add a parameter to your application.

g.i.cs file not found with WPF and code contracts

I have a WPF project which compiles just fine. However, when I enable code contracts, I get a lot of errors like the following:
file 'C:\MyProject\obj\Debug\MyFile.g.i.cs' could not be found
Is there workaround?
Just FYI... This bug has been fixed in the latest version of Code Contracts (v1.2.21023.14, released Oct. 22nd).
Can you be a bit more specific about your repro steps? The significance of the files ending in .g.i.cs is they are files generated specifically to enable intellisense in running projects. They are not truly part of the build process and likely should not be consumed by code contracts. I'm not a code contracts expert by any means though so I could be wrong on this point.
I posted a repro and workaround to this problem on the Code Contracts forum. Here's the URL:
http://social.msdn.microsoft.com/Forums/en-US/codecontracts/thread/4f2af748-1db1-4175-abf0-fbcc82f177ee
The short answer is that the error occurs whenever you have multiple projects that reference each other in a Solution, and one of the child projects is a WPF control library. To get around the problem, you can either disable contract verification for the parent project(s) (the ones that reference the other projects), or you can add a post-build event to the offending child project(s) to create the *.g.i.cs files that the Code Contracts rewriter is looking for.
For example, create a blank text file in the root directory of your child project and name it "Blank.txt". Then add the following command as a post-build event in that project:
copy "$(ProjectDir)Blank.txt" "$(ProjectDir)obj\$(Configuration)\GeneratedInternalTypeHelper.g.i.cs"
Copy this line as many times as needed, one for each missing file.

Resources