The name does not exist in the namespace error in XAML - wpf

Using VS2012 working on a VB.NET WPF application. I have a simple MusicPlayer tutorial app I am using to learn WPF. I am converting a C# version of the tutorial to VB.NET step by step.
It has 2 classes in the app that are both under the same namespace. I am able to reference the namespace in the XAML but when I try to reference the class object in XAML I get an error and I am not able to compile.
Strange thing is that the IntelliSense works fine with both referencing the namespace via the xmlns:c= tag and also when typing the class object using <c:
But the object is underlined and errors are generated trying to build or work in the designer.
The .vb class files are in a folder called \Controls. The Main project Root Namespace is intentionaly left blank. The class is coded like this...
Namespace MusicPlayer.Controls
Public Class UpdatingMediaElement
.... code here
End Public
End Namespace
The xaml looks like this
(namespace defined in the <Window > tag
xmlns:c="clr-namespace:MusicPlayer.Controls"
(object defined in a <Grid> )
<c:UpdatingMediaElement Name="MyMediaElement" />
(error displayed)
The name "UpdatingMediaElement" does not exist in the namespace "clr-namespace:MusicPlayer.Controls".
Not sure what is wrong or how to fix it?

When you are writing your wpf code and VS tell that "The name ABCDE does not exist in the namespace clr-namespace:ABC". But you can totally build your project successfully, there is only a small inconvenience because you can not see the UI designing (or just want to clean the code).
Try to do these:
In VS, right click on your Solution -> Properties -> Configuration Properties
A new dialog is opened, try to change the project configurations from Debug to Release or vice versa.
After that, re-build your solution. It can solve your problem.

If the assembly is different from the namespace in which your class is contained, you have to specfiy it explicitly.
ex:-
xmlns:Local="clr-namespace:MusicPlayer.Controls;assembly=MusicPlayer"

In my case it was because of other compile errors. When other errors have been solved this seemingly related error was also removed from the list. Specially the errors at the bottom of the errors list and on pages you have recently changed.
So do not pay attention to this error directly and focus on other errors at first.

I've seen this issue go away by clearing the Xaml Design Shadow Cache. I had the issue with Visual Studio 2015 Update 1.
In Visual Studio 2015 the Cache is located here:
%localappdata%\Microsoft\VisualStudio\14.0\Designer\ShadowCache
Process:
Right-Click on the solution in the Solution Explorer and Choose "Clean Solution"
Shutdown Visual Studio
Delete the ShadowCache folder
Reopened the Visual Studio project
Rebuild the solution
And voila no more namespace errors.

Try changing the build target platform to x86 and building the project.
I noticed via Subversion that I apparently changed the project build Platform target to x64. This was the only change I had made. After making that change, the code was working for a short while before it started showing the same error you experienced. I changed the platform target to x86 to test and suddenly my designer was working again. Subsequently, I changed it back to x64, and the problem has disappeared completely. I suspect that the designer builds some kind of cached code in x32 and changing the x64 build platform breaks it when you make code changes.

Maybe another solution for when the project compiles but the XAML error is showing :
In solution explore, on the project node that contains the xaml
Right-click on the project and choose 'Unload Project'
Right-click on the project and choose 'Reload Project'
Make sure that your project is still choosen as "startup project". If not :
Right-click on the project and choose 'Set as startup project'
No need to rebuild, or close visual studio.

Jesus... This is still a problem five years later in Visual Studio 2017. Since I'm new to WPF, I was sure the problem was somehow me, but no, everything compiled and ran correctly.
I tried rebuilding, cleaning and rebuilding, switching between x86/x64 output, rebooting Windows, cleaning the ShadowCache folder, adding ";assembly={my main assembly name}" to the XML namespace declaration, nothing worked! The single thing that did:
Put my static class of Commands (in my case the deal was about making the design discover my WPF Commands) in its separate assembly and changing the assembly name to that one's instead.

Dunno if this will help anyone else
I'm new to WPF and still a novice with VB.net - so I was assuming that getting this error was being caused by me doing summit silly........ suppose I was really! I've managed to get rid of it by moving my project from a shared drive to one of my local drives.
Error's disappeared, project compiles perfectly no further issues - yet. Looks like VS2015 still has problems with projects held on a shared drive.

I had this problem recently using VS 2015 Update 3 for my WPF project in .NET 4.6.2. The copy of my project was in a network folder, I moved it locally and that solved the problem.
This may solve other sort of problems, as it looks like VS 2015 doesn't like network paths. Another issue that is a big problem for them is syncing git repositories if my project is in a network path, also solved by moving it locally.

I went through all the answers and none helped me. Finally was able to solve it by myself, so presenting the answer as it might help others.
In my case, the solution had two projects, one containing the models (say the project and assembly name was Models) and another containing the views and view models (as per our convention: project, assembly name and default namespace were Models.Monitor). The Models.Monitor referred Models project.
In the Models.Monitor project, in one of the xaml I included the following namespace:
xmlns:monitor="clr-namespace:Models.Monitor"
I suspect that MsBuild and Visual Studio then were erroring out as they were trying to find a 'Monitor' type in the assembly 'Models'. To resolve I tried the following:
xmlns:monitor="clr-namespace:Models.Monitor;assembly=" - which is valid if the namespace is in same assembly as per https://msdn.microsoft.com/en-us/library/ms747086(v=vs.110).aspx
also tried the explicit namespace declaration:
xmlns:monitor="clr-namespace:Models.Monitor;assembly=Models.Monitor"
Neither of the above worked.
Finally I gave up, and as a work around moved the UserControl I was trying to use to another namespace: 'ModelsMonitor'. I was able to compile fine after that.

I'm also having a lot of trouble with this one! Intellisense helps me complete the namespace and everything, but the compiler cries. I've tried everything I found in this and other threads. However in my case what helped in the end was writing something like this:
xmlns:util="clr-namespace:LiveSpielTool.Utils;assembly="
Leaving the assembly name empty. No idea why. But it was mentioned here. I must add I am developing an assembly, so the assembly attribute might make sense. But entering the assembly name did not work. So weird.

I had the same problem , and in my case the the Markup Design View asked me to rebuild the solution and did not show me the form layout with this message:
Design view is unavailable for x64 and ARM target platforms, or Build the Project to update Design view.
It does not get solved by rebuilding the solution (neither the design view nor the "The name does not exist in the namespace" error)
I think it was because I had played with the settings on Solution -> Properties > Configuration Properties
I finally resolved the problem with 2 jobs:
Checking all check boxes on Build Column of the page: Solution -> Properties -> Configuration Properties
Changing the solution configurations from Debug to Release or vice versa.
I think it's a bug in Visual Studio2012 Update 2.

The same problem plagues Visual Studios 2013, Service Pack 4.
I also tried it with Visual Studios 2015 Preview with the same results.
It's just a limitation of the WPF visualizer which the Visual Studios team hasn't fixed.
As proof, building in x86 mode enables the visualizer and building in x64 mode disables it.
Strangely enough intellisense works for Visual Studios 2013, Service Pack 4.

In my case the problem was due to some phantom files under the project's obj directory. The following fixed the issue for me:
Clean project
Exit VS
rm -rf /obj/*
Invoke VS and rebuild

In my case, it was just a weird bug.
I had the class I was trying to use in my namespace however Visual Studio kept throwing an error saying the class did not exist in the given namespace.
What I did to fix it was really silly but worked like a charm.
I commented out all the lines of code where I was trying to use the class, cleaned the build, rebuilt and the project was up and running.
Then I just uncommented the lines of code I had commented earlier and well, Visual Studio was no longer throwing me any errors.
Rebuild again and you are ready to go.

Looks like this problem may be solved through a variety of "tricks."
In my case, I had been building/rebuilding/cleaning the entire solution, instead of just the project that I was working on within the solution. Once I clicked "Build [my project]," the error message went away.

Try verifying your assembly references. If you have a yellow exclamation mark on the project references there's a problem there and you'll get all kinds of errors.
If you know the project reference is correct, check the Target framework. For instance, having a project using the 4.5 framework reference a project with 4.5.2 framework is not a good combination.

The solution for me was to unblock the assembly DLLs. The error messages you get don't indicate this, but the XAML designer refuses to load what it calls "sandboxed" assemblies. You can see this in the output window when you build. DLLs are blocked if they are downloaded from the internet. To unblock your 3rd-party assembly DLLs:
Right click on the DLL file in Windows Explorer and select Properties.
At the bottom of the General tab click the "Unblock" button or checkbox.
Note: Only unblock DLLs if you are sure they are safe.

In my case, the user control was added to the main project. I tried various solutions above to no avail. Either I would get Invalid Markup but the solution would compile and work, or I would add the
xmlns:c="clr-namespace:MyProject;assembly=MyProject" and then the markup would show, but I would get a compile error that the tag does not exist in the XML namespace.
Finally, I added a new WPF User Control Library project to the solution and moved my user control from the main project into that one. Added the reference and changed the assembly to point to the new library and finally the markup worked and the project compiled without error.

In my case I had a namespace and class spelled exactly the same, so for example, one of my namespaces was
firstDepth.secondDepth.Fubar
which contains its own classes (e.g. firstDepth.secondDepth.Fubar.someclass)
but I also had a 'Fubar' class in the namespace
firstDepth.secondDepth
which textually resolves to the same as the Fubar namespace above.
Don't do this

This problem can also be caused if the assembly that you're referencing isn't actually built. For example, if your xaml is in Assembly1 and you're referencing a class also in Assembly1, but that assembly has errors and isn't building, this error will be shown.
I feel silly about it, but in my case I was tearing asunder a user control and had all sorts of errors in the related classes as a result. As I was attempting to fix them all I started with the errors in question, not realising that xaml relies on built assemblies to find these references (unlike c#/vb code which can work it out even before you build).

I get this problem all the time. My views are in a WPF Custom Control Library project (a variant on Class Library). I can reference pre-built assemblies, but cannot reference any code in another project of the same solution. As soon as I move the code to the same project as the xaml it's recognized.

This happened to me already twice in a complex WPF app, in it there are 4 multi platform projects, 1 shared project, 2 support libraries, and 1 test project..
This very specific XAML namespace error happened twice on very recently modified files on the Shared project. In both of my cases, it was a new c# file added with a repeating namespace entry;
Like namespace MyProgram.MyFolder.MyProgram.MyFolder
I double pasted it once by mistake, and once it was due to JetBrains Rider double pasting the namespace. (If you ever rename a project in Rider, it time to time starts double pasting namespaces on new file creations, especially on Shared projects..). These c# files with repeating namespaces were then called in the ViewModels where XAML files were referencing to. Well you then get these unrelated and misleading errors, you can have a problem with one file, all your Xaml files will start erroring out eventually.
Anyways, if you get these kind of errors, it's most of the time an issue on a very newly added file or code change. My suggestions would be to look at your very recent changes.

If non of the answers worked
For me was .Net Framework version compatibility issue of the one i'm using was older then what is referencing
From properties => Application then target framework

VB.NET does not automatically add the Namespace information based on the folder structure as it does in C#. I think I am going through the same tutorial as you (Teach Yourself WPF in 24 Hours), and doing the same conversion to VB.
I found you have to manually add the Namespace information to Both the XAML Class and the XAML.VB code behind to be able to use the Namespaces as described in the book. Even then, VB doesn't automatically Assign the Namespace to the Assembly as it does in VB.
There is another article here that shows how to include this in your project templates so it does build the Namespace information automatically - Automatically add namespace when adding new item

In the solution property page, check the platform of the assembly that contains "UpdatingMediaElement" and the assmeblies that contain any of the superclasses and interfaces from which "UpdatingMediaElement" subclasses or implements. It appears that the platform of all these assemblies must be "AnyCPU".

Another possible cause: A post-build event is removing the project DLL from the build folder.
To clarify: WPF designer may report "The name XXX does not exist in the namespace...", even when the name does exist in the namespace and the project builds and runs just fine if a post-build event removes the project DLL from the build folder (bin\Debug, bin\Release, etc.). I have personal experience with this in Visual Studio 2015.

Ok, so none of these tips worked for me, unfortunately. I was able to eventually solve the issue. It seems that Visual Studio does not play nicely with network drives. I solved this issue by moving the project from the shared drive to my local and recompiled. No more errors.

Adding to the pile.
Mine was the assembly name of the WPF application was the same assembly name as a referenced dll. So make sure you don't have duplicate assembly names in any of your projects.

I had the solution stored on a network share and every time I opened it I would get the warning about untrusted sources. I moved it to a local drive and the "namespace does not exist" error went away as well.

Related

WPF Design Time Error w/ Local Namespace Reference

I'm having an issue with the WPF Designer. At some point I did something that broke all of my controls that reference the local assembly. The application builds and runs just fine, but the VS Designer throws errors every time that a local resource is referenced via a clr-namespace.
For instance, I have the following reference:
xmlns:Converters="clr-namespace:MyAssembly.Converters;assembly="
Note that I left off the assembly=MyAssembly because its the local/current.
Then when I reference it in a resources block:
<Converters:IsNotNullConverter x:Key="isNotNull"/>
This was all working up until today. At some point I did something which broke all of the references with the following error:
Undefined CLR Namespace. The 'clr-namespace' URI refers to a namespace 'MyAssembly.Converters' that is not included in the assembly.
I've tried cleaning, rebuilding, restarting VS, closing the designer panes, and all combinations of these 4. It's most likely some other minor issue that is causing the whole thing to blow up (as happens too often in WPF). My problem is that I have no idea how to begin to break this problem down.
Does anyone have any insights or techniques for finding the real issue with this design-time problem? Right now I'm basically going file by file and hoping I can find the needle in the haystack.
Thanks!
"I just solved this by changing the target from x64 to x86. Apparently Visual Studio is 32bit process and it's unable to load 64bit assemblies, and if your assembly is targeting x64 platform and you adding some custom control visual studio is unable to load it and throws this message. "
From: The 'clr-namespace' URI refers to a namespace that is not included in the assembly
I had it set to x64 because of a 3rd party DLL requirement...gonna be tricky. Oh well. Thanks!

Visual Studio 2010 UnresolvedAssemblyException: Type universe cannot resolve assembly: log4net

Recently, I've started to encounter exceptions in the Visual Studio 2010 WPF designer seemingly due to log4net. If I freshly build my project, the XAML file will appear correctly in the designer. Then, once I start to click on controls to jump within the XAML, this exception quickly gets thrown:
System.Reflection.Adds.UnresolvedAssemblyException
Type universe cannot resolve assembly: log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821.
at System.Reflection.Adds.AssemblyProxy.GetResolvedAssembly()
at System.Reflection.Adds.AssemblyProxy.GetHashCode()
continues...
The problem only goes away when I remove the log4net reference. This is now the second project to exhibit this behavior. Has anyone else seen this and/or found a fix?
Note: I'm using .NET 4 Full (not Client Profile) and I've toggled Specific Version on the log4net reference T/F to no avail.
I managed to resolve the issue after:
Finding this blog where the author resolved a similar situation by placing the unresolved assembly in the Public Assemblies folder (found using k3b's fuslogvw tool)
Encountering a FileLoadException which led me to this SO post.
Downloading a fresh copy of log4net, unblocking the zip file, and replacing the reference in VS and the Public Assemblies folder.
But, I'm still not sure why I had to place this particular assembly in the Public Assemblies folder. All the other assemblies I reference don't require this step.
You can use the "Assembly Binding Log Viewer" (Fuslogvw.exe) that belongs to the dotnet sdk to find out which dll is loaded when and why . If logging is enabled it can show you wich assemblies are loaded and which assembly caused it to load.
For details see http://msdn.microsoft.com/en-us/library/e74a18c4(v=vs.80).aspx
Sometimes the dll is there but in the wrong version.
if you include universe.dll into your project you must also include log4net.dll with local copy=true
Add the path to your assembly "log4net" in the Project Properties/Reference Paths.
http://msdn.microsoft.com/en-us/library/6taasyc6(v=VS.100).aspx
Turns out when we had this problem, it was due to the paths we used to add the references.
We are using some custom ".targets" files which define the references. There are lots of mixed dependencies with the projects, and using the .targets files helps to keep the references defined in one place.
Well, the references HintPath ended up something like...
<HintPath>C:\Program Files (x86)\\Custom\CustomControlsWPF2.2011\Source\\..\Binaries\WPF\Custom.Windows.Controls.dll</HintPath>
When we removed the double blackslash, replacing with single "\", the "Visual Studio 2010 UnresolvedAssemblyException: Type universe cannot resolve assembly" error went away.
This is how is should have been.
<HintPath>C:\Program Files (x86)\Custom\CustomControlsWPF2.2011\Source\..\Binaries\WPF\Custom.Windows.Controls.dll</HintPath>
Ensure that your code runs at design time, as well as run time. If your code runs at design time, do not assume that Application.Current is your application. For example, when you are using Expression Blend, Current is Expression Blend. Typical operations that cause a custom control to fail at design time include the following.
-Casting Current to your custom subclass of Application.
-Using the FindName method on Current.
-Not checking whether Application.Current has returned a value that is null. If Visual Studio does not create an application object, then Application.Current may return null.
http://msdn.microsoft.com/en-us/library/ff356886%28v=vs.95%29.aspx
give a try to this. add it at the beginig of your functions:
// Check for design mode.
if ((bool)(System.ComponentModel.DesignerProperties.IsInDesignModeProperty.GetMetadata(typeof(DependencyObject)).DefaultValue))
{
return;
}

wpf xaml designer bug

every time we open a *.xaml file in our project - we see not working designer and a lot of messages 'type not found' 'assembly not found' etc.
After a couple of experiments, i found out a root of a problem :
create new WPF application, create a folder in project root, add some value converter to folder, try to use it on your 'MainWindow.xaml'
you will probably write something like this :
xmlns:Folder="clr-namespace:WpfApp.Folder"
and then
<Window.Resources>
<Folder:SomeValueConverter x:Key="someKey"/>
</Window.Resources>
You know...
And, now the most interesting thing!
when you build your project for x86 or 'any CPU' - everything will be just fine, designer will be available, all namespaces will be imported perfectly!BUT, just change you project configuration to x64...Rebuild solution and open design view... You'll be amazed...errors, types not found, etc...
How the hell to use VS xaml designer in x64 applications?
Windows 7 enterprise x64, Visual Studio 2010 Ultimate
Others have reported the same problem. One of the workarounds suggested was to do the design work with a 32-bit target, and then switch to 64-bit only when you're ready to compile and deploy.
In my case, I was using an obfuscator (ConfuserEx to be exact) as a post-build step in Release configuration that was causing this behavior. Switching back to Debug configuration fixed the problem. Alternately, removing the post-build step will also fix the problem.

How do I compile C++/CLI code for Silverlight?

I have a C++/CLI library that I would like to use in a Silverlight application. It is supposed to be possible to write code for Silverlight in any .NET language, but so far I've only worked out how to compile C#. Silverlight does not seem to be able to use DLLs compiled for .NET.
I'm using Visual Studio 2010 and Silverlight 4. The only new projects available for Silverlight are C# projects. Porting the code to C# is not a practical option.
How do I compile C++/CLI code for Silverlight?
I think I may have gotten a VS2010 C++/CLI class library project to build with references to (only) Silverlight assemblies.
Update
Ok, it is possible. But it is not nice.
First, you must convince the C++ compiler to NOT load the .NET Framework, using an undocumented compiler switch. But that's not the worst part.
Set your C++/CLI project "Common Language Runtime Support" to /clr:safe
Next, under References, remove all references.
Next, in the C++/CLI project properties, under C++ > Command Line, enter /d1clr:nomscorlib /FU"C:\Program Files (x86)\Microsoft Silverlight\4.0.50917.0\mscorlib.dll"
Now, save the project and exit Visual Studio. Open the .vcxproj in a text editor, and change the framework version setting. You want it to be the same as a C# Silverlight project:
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
Now, reopen Visual Studio, and build the project. You'll get an error because the compiler auto-generated a file with #using<mscorlib> and the search path finds the .NET Framework version first.
Silverlight,Version=v4.0.AssemblyAttributes.cpp(1): fatal error C1197: cannot reference 'c:\windows\microsoft.net\framework\v4.0.30319\mscorlib.dll' as the program has already referenced 'c:\program files (x86)\microsoft silverlight\4.0.50917.0\mscorlib.dll'
Double-click the error to open the auto-generated file. Replace the path-less reference with e.g. (here's where you put your references, not in the project properties)
#using <c:\program files (x86)\microsoft silverlight\4.0.50917.0\mscorlib.dll>
#using <c:\program files (x86)\microsoft silverlight\4.0.50917.0\System.dll>
#using <c:\program files (x86)\microsoft silverlight\4.0.50917.0\System.Core.dll>
Luckily, the compiler leaves your changes in-place. So you should be good as long as no one cleans your temp directory.
Building should now succeed.
Then, you need to go add the DLL created by the C++/CLI project to your Silverlight application. Note that you can't set up a project reference, because VS2010 still isn't convinced that the C++/CLI is a Silverlight project. So you'll have to browse and add the reference as an assembly file. (And it won't automatically switch between Debug and Release to match the Silverlight application).
Final Notes
I got it to run an empty Silverlight application in Debug mode and stop at a breakpoint in the middle of C++/CLI code. Also the C++/CLI code successfully returned a value to C# and the local variable in C# received the correct value. So I guess it's working.
I went through a bunch more steps trying to make this work, but I don't think they affected the outcome. If you run into errors, though, let me know and I'll try to figure out what I omitted from this answer.
Ben Voigt, thanks for this, it worked for me too.
Also, if your C++ code does anything that is specific to the C++ language (i.e. not entirely IL portable) like using stack semantics for an array, you'll get the following error:
could not find assembly 'Microsoft.VisualC.dll' etc.
If you recompile with the full .NET Framework and then dump the IL code, you'll find references to "''.$ArrayType$$$BY06$$CB_W modopt" or something similar. This tells you where to change the code.
I found that after I installed the Silverlight SDK and it got added to "\Program Files(x86)\Reference Assemblies" I did not have to go through all of Ben Voigt's steps, just changing the project file was enough.
Another note, you can also use:
<TargetFrameworkProfile>WindowsPhone71</TargetFrameworkProfile>
if you want to target Windows Phone (install the SDK first).
Silverlight does not support native C++ libraries, nor any P/Invoke scenarios due to security concerns. If your library is pure .Net you might be able to decompile it with ILDASM and recompile for Silverlight with ILASM.
Silverlight is not a powerful development platform like .NET which is tightly integrated with operating system. First of all silverlight is supposed to run on any operating system, so there is no choice of Native API anywhere in silverlight.
Silverlight also does not support MSIL completely, so there is lot of problem in compiling and recomiping it at IL level.
Can you say more about what kind of C++/CLI code you have? Most Rich internet applications (Silverlight's target) do not include any of high powerful computation, instead they are plain simple HTML+JS alternatives. For powerful graphics, you can use Silverlight's PixelShadder support.
Reflector
What you can do alternatively is,
Compile your C++/CLI to regular .NET DLL, use Reflector to disassemble and generate C# source code from your dll, it may not be perfect, but you will have most of your logic converted back in C#.
I was able Ben Voigt's solution to work with some minor changes in Visual Studio 2013
Here is what I did different.
Unload the silverlight project that you want to reference it in. Right click and choose edit project.csproj
Copy the Target Framework Settings. For me this was
<TargetFrameworkIdentifier>Silverlight</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
<SilverlightVersion>$(TargetFrameworkVersion)</SilverlightVersion>
For the compiler switch /d1clr:nomscorlib This was not working for me. Also a reference to mscorlib for silverlight was automatically added to the complied output without specifying it on the command line options. This is how I got around it.
Open the project in Just Deompile
Load the Assembly Editor Plugin
Navigate the tree to the references
Delete the reference to the non silverlight mscorlib from the reflexil menu.
Right click on the top level of the tree for the assembly, and save as under the reflexil menu.
I haven't tested all of the functions, but the ones I have tested so far worked as expected.
Thank you Ben, your post has saved me a lot of time. I was thinking I was going to have to port my library:)

Strange Error - CS0012: The type x is defined in an assembly that is not referenced

The type 'x' is defined in an assembly that is not referenced. You must add a reference to assembly 'abc123'.
I have a .NET 2.0 web application that references my assembly 'abc123'. The assembly exists in the GAC and I've verified that it is the correct(same) version. The rest of application has no issues except for one .aspx page. The page in question has a repeater that displays a user control as one of its "fields". Upon binding a list of type y to the repeater I pass the user control a list of type x (a property of y) as shown here:
<uc1:usercontrol id="ucusercontrol " runat="server" myPublicUserControlProperty='<%#Eval("CollectionOfX") %>'/>
On the user control's property set, I bind the list of type x to a gridview in the user control.
One strange thing to note is that this report works fine on my development pc but not on any servers once I deploy. My pc is Windows XP, IIS6, VS2005. The servers are Windows Server 2003, IIS6.
I hope I explained that well enough. Thanks in advance for any insight you can provide.
I'm Mike's coworker, and we worked out a solution.
The type X is defined in his assembly, that is only in the GAC. Even though his ASP.NET web appplication did have a reference, it was failing to load from the GAC only for this UserControl. The rest of the application worked as expected. We confirmed the failed loading by placing a copy of the assembly in the bin directory, and everything worked. We removed the assembly, and the problem came back.
Our solution was to manually add an entry to the web.config in the assemblies section to point ASP.NET to the GAC.
It looks like any time you reference a type in the page (not the code-behind), you need the assembly information defined in the web.config file or in a page directive.
<assemblies>
<add assembly="MyAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=[MyPublicKeyToken]"/>
</assemblies>
When troubleshooting these types of problems, the Fusion Log Viewer has always been a great help.
There's also a bug that can manifest itself with similar symptoms, described here.
The workaround is to delete everything in the C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\ directory, and it only seems to manifest itself in debug mode.
I found that if type x is actually a class in your App_Code, dirtying it and re-saving often forces the web app to recompile and solves the problem.
More often than not, it is because of the cached assemblies. One way resolve this issue is by making the "strong reference" in the proj or config file. Refer this blog post
I had the exact same error, but I had a public constructor in my class that used as a parameter, an object from another project.
I resolved the problem by making that constructor internal.
For me it was a version control pull problem.
In Visual studio, open "References" in your Solution explorer, and scroll through it.
If anything has a yellow warning triangle on it, remember the name, remove it, and add it back again (or have ReSharper do it for you).
Happened to me several times after pulling a project when a co-worker added a new package and references.

Resources