Can't load model using ContentTypeReader - c#

I'm writing a game where I want to use ContentTypeReader. While loading my model like this:
terrain = Content.Load<Model>("Text/terrain");
I get following error:
Error loading "Text\terrain". Cannot find ContentTypeReader
AdventureGame.World.HeightMapInfoReader,AdventureGame,Version=1.0.0.0,Culture=neutral.
I've read that this kind of error can be caused by space's in assembly name so i've already removed them all but exception still occurs.
This is my content class:
[ContentTypeWriter]
public class HeightMapInfoWriter : ContentTypeWriter<HeightmapInfo>
{
protected override void Write(ContentWriter output, HeightmapInfo value)
{
output.Write(value.getTerrainScale);
output.Write(value.getHeight.GetLength(0));
output.Write(value.getHeight.GetLength(1));
foreach (float height in value.getHeight)
{
output.Write(height);
}
}
public override string GetRuntimeType(TargetPlatform targetPlatform)
{
return
"AdventureGame.World.Heightmap,AdventureGame,Version=1.0.0.0,Culture=neutral";
}
public override string GetRuntimeReader(TargetPlatform targetPlatform)
{
return
"AdventureGame.World.HeightMapInfoReader,AdventureGame,Version=1.0.0.0,Culture=neutral";
}
}
Does anyone meed that kind of error before?

I have been encountering the same problem for a week, and finally decided to do a quick check on the whole "assembly" part.
I found a fix!
Essentially, when you go into AssemblyInfo.cs, you will see all the properties(ie Title, Description, etc.)
The Title, sadly made by XNA, is NOT what your runtime reader refers to. Its actually getting the initial name of the project, which it uses to track back to your application (exe) file in your project. Try either re-making your project from scratch, making sure to keep your namespace the same as your project and never change it , or give a go at re-naming your exe file, found in the debug/obj folder in your project(i believe). hope I helped!
-Will

Related

VS 2015 C# AsyncExtension.cs not found

I haven't been able to find any information on this online. I'm debugging an console application, trying to step through some code. When I go to step over I get a source not found error. It says "AsyncExtension.cs not found" and then gives me some details. It says "You need to find AsyncExtension.cs to view the source for the current call stack frame". I'm working in VS2015. I'm assuming something async is happening behind the scenes, its erroring at some point but can't give me the specific details because it can't find the assembly containing AsyncExtension. But I don't know what this is, where to get it, etc. The code in particular I'm trying to step over is below. But I seem to get this at various points, and even when debugging other projects under the same solution.
Line of code:
var newObject = JsonConvert.DeserializeObject<HIDPMessage>(message.ToString());
HIDPMessage:
public class HIDPMessage
{
public string version { get; set; }
[Newtonsoft.Json.JsonProperty]
public string header { get; set; }
[Newtonsoft.Json.JsonProperty]
private Data Data { get; set; }
}
Not sure what you are trying to do but the code you have provided would not normally have any references to anything called AsyncExtension.cs. However your attempt to deserialize message could cause a JsonReaderException.
I'm guessing that "message" is some object that contains properties in common with HIDPMessage type and that you are trying to extract those into a new object, if so message.ToString(), unless overridden will just return the name of the type.
You need to serialize the object to a json string and use the json string instead of message.ToString();
Thanks for the input guys, you were right my code for deserializing was a little off. It turns out this app was built using VS2017 and some components from the Azure SDK were missing. I tried a manual install of the SDK but it wouldn't work - upgrading to 2017 fixed it, but I'm kinda surprised I had to upgrade just to get it to work.
I appreciate the feedback on the serialization stuff as well. This is a new-ish area for me and I'm still learning.

Invalid Resx file. Could not load type error why?

I'm getting designer error on code:
The Component i'm willing to define a List of properties for:
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace TestProjectForProperty.Test
{
public class MyTreeView : TreeView
{
private List<TypeDescriptorBase> _descriptorsAvailable = new List<TypeDescriptorBase>();
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
public List<TypeDescriptorBase> DescriptorsAvailable
{
get { return _descriptorsAvailable; }
set { _descriptorsAvailable = value; }
}
}
}
The Descriptor itself:
using System;
namespace TestProjectForProperty.Test
{
[Serializable]
public class TypeDescriptorBase
{
public string Name { get; set; }
public override string ToString()
{
return Name;
}
}
}
I am getting the following error if i try to use the component for example on a form and add any items on the property sheet or in the component's constructor to the DescriptorsAvailable property
Error 1 Invalid Resx file. Could not load type
System.Collections.Generic.List`1[[TestProjectForProperty.Test.TypeDescriptorBase,
TestProjectForProperty, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null]], mscorlib, Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089 which is used in the .RESX file.
Ensure that the necessary references have been added to your project.
Line 134, position 5. ...\visual studio
2010\Projects\TestProjectForProperty\TestProjectForProperty\Form1.resx 134 5 TestProjectForProperty
In the Resx file there is data field with base64 encoded stuff inside when this error is present.
I have been searching for an answer, but the best i got is to restart everything, it didn't help me, do you guys have any suggestions? I'm using .net 4 client and visual studio 2010
In my experience, this is due to a change of version of a referenced library, or a change of the lib itself, which contains the backing type of a property you have defined in your user control. The solution is to "force" the visual studio designer to re-initialize it's designer code for that type, and not expect to retrieve a "canned" version of it from the .resx file of the control.
1) Delete the offending data section in the .resx file of your control. This will be a section in the xml of the .resx file associated with your user control, which has a node: <data></data> - the name attribute will be set to whatever you've named that object in the properties of whatever you added this type to. The <data>/data> section contains a base64 encoded string that is the encoded form of the name and version of the library the type comes from. This is where the problem ism, because it now contains an encoded version of the library and/or version number you are no longer referencing in order to include the type. Delete the entire <data>/data> section, from opening to closing tag, save the change and close the file. Now the "artifact" is gone.
2) Now find the place in the designer file for your control, where the type is instantiated; this is initialization code generated for you by visual studio, and it is the place that is expecting to load a "canned" definition of the type from the base64 encoded string contained within the .resx file. The line will look something like this:
this.myCtrlFoo.MyPropertyFroo = ((MyNamespaceFoo.MyTypeFoo)(resources.GetObject("myCtrlFoo.MyPropertyFroo")));
...now just replace the resources.GetObjec call with the instantiation of a new instance of the appropriate type like so:
this.myCtrlFoo.MyPropertyFroo = ((MyNamespaceFoo.MyTypeFoo)(new MyNamespaceFoo.MyTypeFoo()));
...now save the change to the file, close it, rebuild, and everything should now build & run OK.
Put the MyTreeView and TypeDescriptorBase classes into another project and reference it from your GUI project will resolve the issues.
I'm not sure why exactly the problem occurs - I guess it has something to do with the way the serializing process is generating the base64 string for the DescriptorsAvailable Property. Maybe somebody else can give us some insight.
I've struggled quite a bit with this; I have three user controls that all expose the same non-designer property, but for some reason, any change to two of the three would instantly cause the next build to fail with this same issue. This is in VS 2015.
I wound up having to add the following two attributes to the property that kept expanding in the resx file, and it hasn't occurred since. It works for me because they're not available in the designer anyway.
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
For me, this error occured when I used a custom class as a property for the user control. When I switched from property to traditional get- and set- methods, the error disappeared. I guess this is because properties are already compiled at design-time, so when you build the whole project, a new version of the custom class is compiled which is separate from the one of the control, and the reference is broken.
For me, with the custom class Inventory, all I had to do was to switch from this property-based approach:
public Inventory Resources {get;set;}
to this method-based approach:
private Inventory resources;
public Inventory getResources() { return resources; }
public void setResources(Inventory newResources) { resources = newResources; }
I hope this helps someone, as I've been spending some hours on figuring it out.
In my case I've got the error : "error MSB3103: Invalid Resx file. The specified module could not be found" executed in a light windows container based on mcr.microsoft.com/powershell instead of mcr.microsoft.com/windows:1909 (was working fine on 1909).
The error was on a ressource icon that was compressed with PNG inside.
It can be checked by opening the ressource on visual studio : Project > Properties > Ressources.resx, select icons, double click on the icon, check the end of the title that is either "..,BMP]" or "...,PNG]").
Updating the icon with an uncompressed format solve the "Invalid Resx file" issue.
I stumbled across this question today whilst looking for the solution to a similar issue.
Unfortunately none of the above worked for me, however my issue turned out to be that I had different versions of the .NET Framework for different projects. For example;
Project A - .NET Framework 4.7.2
Project B - .NET Framework 4
Where Project B was referencing Project A. Solution was simply to change the .NET Framework version of Project B to 4.7.2 (in my case) and hey presto the issue was resolved.
A shame Visual Studio doesn't provide a more helpful error message in this case, but something to look out for!

sharing a static class with a DLL in C# without passing a reference

VS2012 for desktop .net framework 4.5 normal windows forms applications, not WPF
Hello, I tried to search for an answer, but I'm not sure of the correct terminology. I've managed to break my code, and can't understand what I've done wrong. (i didn't think i had changed anything, but ...)
I have a solution which contains 2 projects. The first project is an executable program, and the second is a DLL, which is loaded at run time and used by the first project.
the first project contains a form, and a static class with public static strings in the same namespace. (and some other unconnected classes). specifically:
namespace project1_namespace
{
static class settings
{
public static string some_words = "some words in a string";
}
class dll_callback{
//.. some public methods here
}
dll_callback dllcallback; // instance is initialised in the code (not shown)
Form form;
public partial class frm_splash : Form
{
private void frm_splash_FormClosing(object sender, FormClosingEventArgs e)
{
// this function actually loads the DLL, ensuring its the last step
//... some error checking code removed for brevity
Assembly assembly = Assembly.LoadFrom("c:\dllpath\project2.dll");
Type type_init = assembly.GetType("project2_class");
object init = Activator.CreateInstance(type_init, form, dllcallback);
//... some error checking code removed for brevity
}// end method
}// end form class
}// end namespace
when the form is closing, the method shown above is called which calls the second projects class project2_class constructor.
in project 2, the DLL, there is:
namespace project2_namespace
{
// how did i get this working to reference "settings" class from project 1??
public class project2_class
{
public project2_class(project2_namespace.Form1 form_ref, object callback)
{
settings.some_words = "the words have changed";
//... some more stuff
}
}
}
Now, i was experimenting with some code in an entirely different part of project2, and VS2012 suddenly started refusing to compile stating:
error CS0103: The name 'settings' does not exist in the current context
the standard solution to this appears to be to add a reference to project2, but that would create circular dependencies because project 1 calls 2 as a DLL.
I really honestly don't think i had changed anything relevant to this, but also clearly I have.
looking at it, i cant see how project 2 would have access to a class in project 1 without a reference, but the list of arguments to the project2_class constructor doesn't include one, and I am absolutely positive that it hasn't changed (and I cant change it for backwards compatibility reasons).
would really appreciate help with this, as its been a lot of work to get this working.
as a side note, I've definitely learned my lesson about not using source control. and not making "how this works" comments instead of "what this does" comments.
may dynamic help you? You can not get the setting string at complie time.

One web application, two namespaces

I have one web application with two projects:
Project "Website"
Using CMS;
namespace Web
{
}
Project "CMS"
namespace CMS
{
public class Functions
{
}
}
Then I want to be able to use CMS.Functions.MyMethod() inside Website.Web.
Im having some problem with this.. Inside the "Website" project I have added "CMS" as a reference and I have also added Using CMS; and even tho the intellisense picks up CMS.Functions I get an error! The word CMS gets underlined blue and I get the message:
The name 'CMS' does not exist in the current context
What am I missing out? Its so weird becuase I can write CMS.Functions and the "Functions" part comes up in the intellisense but when I finish the line the word CMS gets underlined blue and I get the error even tho I got a reference and a Using statement.
From the sound of it, you want to make your Functions class methods to be static
namespace CMS
{
public class Functions
{
public static void MyMethod(){
//do stuff
}
}
}
The most likely cause is that you have not added a reference to the CMS project to your main project. That is the only time that I get the exception about the name not existing in the current context.

Getting CS1061 error on compile even though the property exists

I have come across the most curious problem ever as .Net dev. I am compiling a library which has a newly added property DeviceID in the class of UserInfo. The library internally uses the type and it's new property just fine, but when I try and reference it from another library, the compiler kicks back a compiler error stating
'library.UserInfo' does not contain a definition for 'DeviceID' and no extension
method 'DeviceID' accepting a first argument of type 'library.UserInfo' could
be found
Even though my class definition looks like:
public class UserInfo
{
public static UserInfo Current
{
get
{
if (UserInfoPrincipal.Current != null)
{
return UserInfoPrincipal.Current.UserData;
}
else
{
return null;
}
}
}
public string UserID { get; set; }
public string DeviceID { get; set; }
public string MikeLiUserID { get; set; }
public string TransactionServer { get; set; }
public string ApplicationKey { get; set; }
public string IpAddress { get; set; }
}
The offending code reads as such:
internal LogDetail BuildLogDetail(LogType entryType, string message)
{
return new LogDetail
{
ActingUserID = UserInfo.Current.UserID,
ActingDeviceID = UserInfo.Current.DeviceID,
ApplicationKey = UserInfo.Current.ApplicationKey,
IpAddress = UserInfo.Current.IpAddress,
EntryType = entryType,
OwnerID = UserInfo.Current.UserID,
LogData = message
};
}
I'd like to note that all of the other members of the UserInfo class go through the compiler correctly and it is just the DeviceID, which was added today, is causing the issue. I've tried Clean All, I've tried refreshing everything from TFS, manually deleting the obj and bin directories of both projects... nothing yet has worked.
UPDATE: This code, which is part of the library, works correctly:
public class UserInfoPrincipal : IPrincipal
{
public static UserInfoPrincipal Current
{
get
{
if (Thread.CurrentPrincipal is UserInfoPrincipal)
return (UserInfoPrincipal)Thread.CurrentPrincipal;
else
return null;
}
}
...
internal UserInfo UserData
{
get { return _userInfo; }
}
public string DeviceID
{
get { return _userInfo.DeviceID; }
}
...
}
So my hail mary pass was to remove the project reference and then add it again. Then it compiled. Have no clue why that worked, but figured I'd post it here for other who might run into the same problem.
Is the other library using a project reference or a binary reference? If its a binary reference, are you sure its using the latest build?
Check the reference path of the project that's generating the error; make sure you're either referencing the library project (if it's part of your solution) or the most recent build of the library (if it's not.)
I've gotten stuck in a few situations like this before. Here's what worked for me:
Are those two samples of code in separate projects? If so, I would say to try rebuilding the first project (containing the UserInfo class), then take out the line that fails the compilation out and try rebuilding the second project. Then do a rebuild all. Then add the offending line back in and do a rebuild all.
May not work for you, but worth a shot. I know that situation is frustrating.
for me -- try to recreate the line that shows an issue. Write the name of the object period (.) and wait for VS to show you the list of available properi
I encountered a very similar problem.
In my case I have a piece of code that I only need to run a couple times a year. When I attempted to use it there was an error accessing a Member. Nothing should have changed since the last time I used the code. Intellisense was detecting the member when using the '.' in Visual Studio. I restarted Visual Studio and the computer but the problem stayed.
In the end to fix my problem, I created a new file, copied the code from the original to the new file, and that was it. No code modifications. I used Ctrl-C, Ctrl-V so the content wasn't corrected by a manual touch. This isn't the first time copy and paste has fixed a bug so it's worth keeping the idea in the tool chest. Sometimes a mysterious problem demands an equally mysterious solution.
In my case, it was a problem with the web application's project properties. To fix it, I did the following:
Right-click the project > click Properties.
On the Build tab, change the Output path value for all configurations to: bin\
Previously, my output path had been bin\Debug or bin\Release depending on which configuration I was looking at. I don't know why this screwed with my markup page's ability to see methods in my codebehind, but it did. Once I changed this, the error disappeared.
This was in VS2012 w/ update 2.
My solution: I was create another name method what set property. My problem was on VS2015 + Silverlight 5

Categories

Resources